[Search] More search options

If the user searches with quotes (" or ') around
the search term, then the term processor will
not put wildcards around the search term.
This commit is contained in:
shale 2015-07-14 12:32:52 -07:00
parent bf0e6692f5
commit 7c627fae8f

View File

@ -139,16 +139,26 @@ define(
// TODO: May be unnecsisary // TODO: May be unnecsisary
searchTerm = document.getElementById("searchinput").value; searchTerm = document.getElementById("searchinput").value;
} }
// Process search term. // Process search term.
// Put wildcards on front and end to allow substring behavior. // Allow exact searches by checking to see if the first and last
// This works when options like AND and OR are not used, which is // chars are quotes.
// the case most of the time. if ((searchTerm.substr(0, 1) === '"' && searchTerm.substr(searchTerm.length - 1, 1) === '"') ||
// e.g. The input 'sine' become '*sine*', but the input (searchTerm.substr(0, 1) === "'" && searchTerm.substr(searchTerm.length - 1, 1) === "'")) {
// 'sine OR telemetry' becomes '*sine OR telemetry*' instead of // Remove the quotes, because of how elasticsearch processses.
// '*sine* OR *telemetry*' // This will mean that elasticsearch will return any object that has
searchTerm = '*' + searchTerm + '*'; // that searchTerm as a part of the name _separated by spaces_.
searchTerm = searchTerm.substring(1, searchTerm.length - 1);
} else {
// Put wildcards on front and end to allow substring behavior.
// This works when options like AND and OR are not used, which is
// the case most of the time.
// e.g. The input 'sine' become '*sine*', but the input
// 'sine OR telemetry' becomes '*sine OR telemetry*' instead of
// '*sine* OR *telemetry*'
searchTerm = '*' + searchTerm + '*';
}
// Get the data... // Get the data...
return $http({ return $http({
method: "GET", method: "GET",