[Search] Comments

This commit is contained in:
shale 2015-07-15 12:37:12 -07:00
parent eee9309650
commit 759eaa3b35

View File

@ -48,7 +48,7 @@ define(
/////////////// The following is for non-Elastic Search ///////////////// /////////////// The following is for non-Elastic Search /////////////////
// Recursive helper function for getItems // Recursive helper function for getItems()
function itemsHelper(children, i) { function itemsHelper(children, i) {
if (i >= children.length) { if (i >= children.length) {
// Done! // Done!
@ -67,7 +67,7 @@ define(
} }
// Converts the filetree into a list // Converts the filetree into a list
// Used for queryManual // Used for queryManual()
function getItems() { function getItems() {
// Aquire My Items (root folder) // Aquire My Items (root folder)
return objectService.getObjects(['mine']).then(function (objects) { return objectService.getObjects(['mine']).then(function (objects) {
@ -85,8 +85,8 @@ define(
* Notes: * Notes:
* * The order of the results is not guarenteed. * * The order of the results is not guarenteed.
* * A domain object qualifies as a match for a search term if * * A domain object qualifies as a match for a search term if
* the object's name property contains the search term as a * the object's name property contains the exact search term
* substring. * as a substring.
* * Folders are not included in the results. * * Folders are not included in the results.
* * Wildcards are not supported. * * Wildcards are not supported.
* *
@ -146,6 +146,7 @@ define(
/////////////// The following is for Elastic Search ///////////////// /////////////// The following is for Elastic Search /////////////////
// Check to see if the input has any special options // Check to see if the input has any special options
// Used by queryElasticsearch()
function isDefaultInput(searchTerm) { function isDefaultInput(searchTerm) {
// If the input has quotes, not default // If the input has quotes, not default
if ((searchTerm.substr(0, 1) === '"' && searchTerm.substr(searchTerm.length - 1, 1) === '"') || if ((searchTerm.substr(0, 1) === '"' && searchTerm.substr(searchTerm.length - 1, 1) === '"') ||
@ -162,6 +163,7 @@ define(
} }
// Add wildcards to the font and end of each subterm // Add wildcards to the font and end of each subterm
// Used by queryElasticsearch()
function addWildcards(searchTerm) { function addWildcards(searchTerm) {
return searchTerm.split(' ').map(function (s) { return searchTerm.split(' ').map(function (s) {
return '*' + s + '*'; return '*' + s + '*';
@ -169,6 +171,7 @@ define(
} }
// Add the fuzziness operator to the search term // Add the fuzziness operator to the search term
// Used by queryElasticsearch()
function addFuzziness(searchTerm, editDistance) { function addFuzziness(searchTerm, editDistance) {
if (!editDistance) { if (!editDistance) {
editDistance = ''; editDistance = '';
@ -178,10 +181,10 @@ define(
return s + '~' + editDistance; return s + '~' + editDistance;
}).join(' '); }).join(' ');
//searchTerm + '~' + editDistance; //searchTerm + '~' + editDistance;
} }
// Currently specific to elasticsearch // Currently specific to elasticsearch
// Used by queryElasticsearch()
function processSearchTerm(searchTerm) { function processSearchTerm(searchTerm) {
// Shave any spaces off of the ends of the input // Shave any spaces off of the ends of the input
while (searchTerm.substr(0, 1) === ' ') { while (searchTerm.substr(0, 1) === ' ') {
@ -193,23 +196,23 @@ define(
if (isDefaultInput(searchTerm)) { if (isDefaultInput(searchTerm)) {
// Add fuzziness for completeness // Add fuzziness for completeness
searchTerm = addFuzziness(searchTerm); searchTerm = addFuzziness(searchTerm, 1);
// Searching 'name' by default // Searching 'name' by default
searchTerm = 'name:' + searchTerm; searchTerm = 'name:' + searchTerm;
} }
console.log('processed search term ', searchTerm); //console.log('processed search term ', searchTerm);
return searchTerm; return searchTerm;
} }
// Processes results from the format that elasticsearch returns to // Processes results from the format that elasticsearch returns to
// a list of objects in the format that mct-representation can use. // a list of objects in the format that mct-representation can use.
// Used by queryElasticsearch()
function processResults(rawResults) { function processResults(rawResults) {
var results = rawResults.data.hits.hits, var results = rawResults.data.hits.hits,
resultsLength = results.length, resultsLength = results.length,
ids = [], ids = [],
//scores = [],
i; i;
if (rawResults.data.hits.total > resultsLength) { if (rawResults.data.hits.total > resultsLength) {
@ -222,14 +225,6 @@ define(
ids.push(results[i][ID]); ids.push(results[i][ID]);
} }
/*
// Get the result objects' scores
for (i = 0; i < resultsLength; i += 1) {
scores.push(results[i][SCORE]);
}
console.log('scores', scores);
*/
// Get the domain objects from their IDs // Get the domain objects from their IDs
return objectService.getObjects(ids).then(function (objects) { return objectService.getObjects(ids).then(function (objects) {
var output = [], var output = [],
@ -256,11 +251,13 @@ define(
* term. This is done through querying elasticsearch. * term. This is done through querying elasticsearch.
* Notes: * Notes:
* * The order of the results is from highest to lowest score, * * The order of the results is from highest to lowest score,
* as elsaticsearch determines them to be. * as elsaticsearch determines them to be.
* * Folders are not included in the results. * * Folders are not included in the results.
* * Wildcards are supported. * * Wildcards are supported.
* * More search details at * * More search details at
* https://www.elastic.co/guide/en/elasticsearch/reference/current/search-uri-request.html * https://www.elastic.co/guide/en/elasticsearch/reference/current/search-uri-request.html
* * Fuzziness is used to produce more results that are still
* relevant. (All results within a certain edit distance.)
* *
* @param inputID the name of the ID property of the html text * @param inputID the name of the ID property of the html text
* input where this funcion should find the search term * input where this funcion should find the search term