[Search] Search term processing

The search term processor for ElasticSearch now
removes extra spaces from inside of the search
term (to avoid some ES errors).
This commit is contained in:
slhale 2015-07-28 17:04:29 -07:00
parent 32b58715c6
commit 495d8c9830
2 changed files with 13 additions and 4 deletions

View File

@ -77,13 +77,20 @@ define(
// Currently specific to elasticsearch
function processSearchTerm(searchTerm) {
// Shave any spaces off of the ends of the input
var spaceIndex;
// Cut out any extra spaces
while (searchTerm.substr(0, 1) === ' ') {
searchTerm = searchTerm.substring(1, searchTerm.length);
}
while (searchTerm.substr(searchTerm.length - 1, 1) === ' ') {
searchTerm = searchTerm.substring(0, searchTerm.length - 1);
}
spaceIndex = searchTerm.indexOf(' ');
while (spaceIndex !== -1) {
searchTerm = searchTerm.substring(0, spaceIndex) + searchTerm.substring(spaceIndex + 1, searchTerm.length);
spaceIndex = searchTerm.indexOf(' ');
}
if (isDefaultFormat(searchTerm)) {
// Add fuzziness for completeness
@ -100,7 +107,7 @@ define(
// Processes results from the format that elasticsearch returns to
// a list of objects in the format that mct-representation can use
function processResults(rawResults, timestamp) {
var results = rawResults.data.hits.hits,
var results = rawResults.hits.hits,
resultsLength = results.length,
ids = [],
scores = {},
@ -177,9 +184,9 @@ define(
return $http({
method: "GET",
url: esQuery
}).then(function (rawResults) {
}).success(function (data, status) {
// ...then process the data
return processResults(rawResults, timestamp);
return processResults(data, timestamp);
});
} else {
latestResults = [];

View File

@ -63,10 +63,12 @@
});
}
/*
message = {
request: 'index'
};
return message;
*/
}
// Helper function for serach()