mirror of
https://github.com/nasa/openmct.git
synced 2025-05-31 22:50:49 +00:00
[Search] Processing as separate function
Moved the search term processing to be its own separate function.
This commit is contained in:
parent
27c7410318
commit
35d038e826
@ -120,6 +120,39 @@ define(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Currently specific to elasticsearch
|
||||||
|
function processSearchTerm(searchTerm) {
|
||||||
|
// Allow exact searches by checking to see if the first and last
|
||||||
|
// chars are quotes.
|
||||||
|
if ((searchTerm.substr(0, 1) === '"' && searchTerm.substr(searchTerm.length - 1, 1) === '"') ||
|
||||||
|
(searchTerm.substr(0, 1) === "'" && searchTerm.substr(searchTerm.length - 1, 1) === "'")) {
|
||||||
|
// Remove the quotes, because of how elasticsearch processses.
|
||||||
|
// This will mean that elasticsearch will return any object that has
|
||||||
|
// that searchTerm as a part of the name _separated by spaces_.
|
||||||
|
searchTerm = searchTerm.substring(1, searchTerm.length - 1);
|
||||||
|
}
|
||||||
|
// If the search starts with 'type:', then search for domain object type, rather
|
||||||
|
// than the domain object name.
|
||||||
|
else if (searchTerm.includes('type:')) {
|
||||||
|
// Do nothing for now
|
||||||
|
} else if (searchTerm.includes('name:')) {
|
||||||
|
// Do nothing for now
|
||||||
|
} 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 + '*';
|
||||||
|
|
||||||
|
// Assume that the search term is for the name by default
|
||||||
|
searchTerm = "name:" + searchTerm;
|
||||||
|
}
|
||||||
|
|
||||||
|
return searchTerm;
|
||||||
|
}
|
||||||
|
|
||||||
// Use elasticsearch's search to search through all the objects
|
// Use elasticsearch's search to search through all the objects
|
||||||
function queryElasticsearch(inputID, maxResults) {
|
function queryElasticsearch(inputID, maxResults) {
|
||||||
var searchTerm;
|
var searchTerm;
|
||||||
@ -140,26 +173,10 @@ define(
|
|||||||
searchTerm = document.getElementById("searchinput").value;
|
searchTerm = document.getElementById("searchinput").value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process search term.
|
// Process search term
|
||||||
// Allow exact searches by checking to see if the first and last
|
searchTerm = processSearchTerm(searchTerm);
|
||||||
// chars are quotes.
|
|
||||||
if ((searchTerm.substr(0, 1) === '"' && searchTerm.substr(searchTerm.length - 1, 1) === '"') ||
|
console.log(searchTerm);
|
||||||
(searchTerm.substr(0, 1) === "'" && searchTerm.substr(searchTerm.length - 1, 1) === "'")) {
|
|
||||||
// Remove the quotes, because of how elasticsearch processses.
|
|
||||||
// This will mean that elasticsearch will return any object that has
|
|
||||||
// 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 + '*';
|
|
||||||
}
|
|
||||||
// Assume that the search term is for the name by default
|
|
||||||
searchTerm = "name:" + searchTerm;
|
|
||||||
|
|
||||||
// Get the data...
|
// Get the data...
|
||||||
return $http({
|
return $http({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user