[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 // Currently specific to elasticsearch
function processSearchTerm(searchTerm) { 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) === ' ') { while (searchTerm.substr(0, 1) === ' ') {
searchTerm = searchTerm.substring(1, searchTerm.length); searchTerm = searchTerm.substring(1, searchTerm.length);
} }
while (searchTerm.substr(searchTerm.length - 1, 1) === ' ') { while (searchTerm.substr(searchTerm.length - 1, 1) === ' ') {
searchTerm = searchTerm.substring(0, searchTerm.length - 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)) { if (isDefaultFormat(searchTerm)) {
// Add fuzziness for completeness // Add fuzziness for completeness
@ -100,7 +107,7 @@ define(
// 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
function processResults(rawResults, timestamp) { function processResults(rawResults, timestamp) {
var results = rawResults.data.hits.hits, var results = rawResults.hits.hits,
resultsLength = results.length, resultsLength = results.length,
ids = [], ids = [],
scores = {}, scores = {},
@ -177,9 +184,9 @@ define(
return $http({ return $http({
method: "GET", method: "GET",
url: esQuery url: esQuery
}).then(function (rawResults) { }).success(function (data, status) {
// ...then process the data // ...then process the data
return processResults(rawResults, timestamp); return processResults(data, timestamp);
}); });
} else { } else {
latestResults = []; latestResults = [];

View File

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