mirror of
https://github.com/nasa/openmct.git
synced 2025-05-29 13:44:21 +00:00
[Search] Manual search works
Manual search which does not use elasticsearch implemented. It matches based on if the name contains the search term as a substring.
This commit is contained in:
parent
fdcc6432f1
commit
6b3088f241
@ -41,106 +41,33 @@ define(
|
|||||||
*/
|
*/
|
||||||
function QueryService($http, objectService, ROOT) {
|
function QueryService($http, objectService, ROOT) {
|
||||||
|
|
||||||
/////////////// The following is for non-Elastic Search /////////////////
|
/////////////// The following is for non-Elastic Search /////////////////
|
||||||
/*
|
|
||||||
function foo (children, i) {
|
|
||||||
if children [i] does not have composition,
|
|
||||||
return children
|
|
||||||
if children [i] does have composition,
|
|
||||||
return merge([children before i], foo(children[i], i++), [children after i]);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Recursive helper function for getItems
|
// Recursive helper function for getItems
|
||||||
function itemsHelper2(children, i) {
|
function itemsHelper(children, i) {
|
||||||
|
|
||||||
console.log('itemshelpher2 called..... children', children);
|
|
||||||
|
|
||||||
var composition;
|
var composition;
|
||||||
if (i >= children.length) {
|
if (i >= children.length) {
|
||||||
|
// Base case, is a leaf
|
||||||
console.log('base case..... children', children);
|
|
||||||
|
|
||||||
// Base case.
|
|
||||||
return children;
|
return children;
|
||||||
} else if (children[i].hasCapability('composition')) {
|
} else if (children[i].hasCapability('composition')) {
|
||||||
|
// Handle this child's children
|
||||||
composition = children[i].getCapability('composition');
|
composition = children[i].getCapability('composition');
|
||||||
|
|
||||||
console.log('composition..... child[', i, ']', children[i]);
|
|
||||||
console.log('................ children', children);
|
|
||||||
|
|
||||||
return composition.invoke().then(function (grandchildren) {
|
return composition.invoke().then(function (grandchildren) {
|
||||||
|
// Add grandchildren to the end of the list
|
||||||
console.log('grandchildren', grandchildren);
|
// They will also be checked for composition
|
||||||
|
return itemsHelper(children.concat(grandchildren), i + 1);
|
||||||
return itemsHelper2(
|
|
||||||
children.splice(0, i).concat(grandchildren, children.splice(i + 1, children.length)),
|
|
||||||
i);
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
return itemsHelper(children, i + 1);
|
||||||
console.log('not composition..... child[', i, ']', children[i]);
|
|
||||||
|
|
||||||
return itemsHelper2(children, i + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recursive helper function for getItems
|
|
||||||
function itemsHelper(current) {
|
|
||||||
var composition;
|
|
||||||
if (current.hasCapability('composition')) {
|
|
||||||
composition = current.getCapability('composition');
|
|
||||||
} else {
|
|
||||||
// Base case.
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recursive case. Is asynchronous.
|
|
||||||
return composition.invoke().then(function (children) {
|
|
||||||
|
|
||||||
|
|
||||||
// Second attempt
|
|
||||||
/*
|
|
||||||
// "global" variables
|
|
||||||
var children;
|
|
||||||
|
|
||||||
// Helper function for itemsHelper to help with loops asynchronously
|
|
||||||
var looper = function (children, childIndex) {
|
|
||||||
return itemsHelper(children[childIndex]).then(function (c) {
|
|
||||||
childIndex++;
|
|
||||||
if (childIndex >= children.length) {
|
|
||||||
return children;
|
|
||||||
} else {
|
|
||||||
return looper(children, childIndex);
|
|
||||||
}
|
|
||||||
//return remainingChildren.concat(c);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kickoff the helper-helper
|
|
||||||
return itemsHelperHelper(children, 0).concat();
|
|
||||||
*/
|
|
||||||
|
|
||||||
// First attempt
|
|
||||||
/*
|
|
||||||
var subList = [current],
|
|
||||||
i;
|
|
||||||
for (i = 0; i < children.length; i += 1) {
|
|
||||||
subList.push(itemsHelper(children[i]));
|
|
||||||
}
|
|
||||||
return subList;
|
|
||||||
*/
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Converts the filetree into a list
|
// Converts the filetree into a list
|
||||||
// Used for the fallback
|
// 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) {
|
||||||
return itemsHelper2([objects.mine], 0).then(function (c) {
|
return itemsHelper([objects.mine], 0).then(function (c) {
|
||||||
return c;
|
return c;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -148,8 +75,7 @@ define(
|
|||||||
|
|
||||||
// Search through items for items manually
|
// Search through items for items manually
|
||||||
// This is a fallback if other search services aren't avaliable
|
// This is a fallback if other search services aren't avaliable
|
||||||
// ... currently only searches 1 layer down (TODO)
|
function queryManual(inputID) {
|
||||||
function queryFallback(inputID) {
|
|
||||||
var term,
|
var term,
|
||||||
searchResults = [],
|
searchResults = [],
|
||||||
itemsLength,
|
itemsLength,
|
||||||
@ -157,21 +83,14 @@ define(
|
|||||||
itemName,
|
itemName,
|
||||||
i;
|
i;
|
||||||
|
|
||||||
// Get the user input
|
// Get the user input
|
||||||
if (inputID) {
|
term = document.getElementById(inputID).value;
|
||||||
term = document.getElementById(inputID).value;
|
|
||||||
} else {
|
|
||||||
// Backward compatibility?
|
|
||||||
// TODO: May be unnecsisary
|
|
||||||
term = document.getElementById("searchinput").value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make not case sensitive
|
// Make not case sensitive
|
||||||
term = term.toLocaleLowerCase();
|
term = term.toLocaleLowerCase();
|
||||||
|
|
||||||
// Get items list
|
// Get items list
|
||||||
return getItems().then(function (items) {
|
return getItems().then(function (items) {
|
||||||
// (slight time optimization)
|
|
||||||
itemsLength = items.length;
|
itemsLength = items.length;
|
||||||
|
|
||||||
// Then filter through the items list
|
// Then filter through the items list
|
||||||
@ -317,7 +236,8 @@ define(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
// Takes a serach term and (optionally) the max number of results.
|
// Takes a serach term and (optionally) the max number of results.
|
||||||
query: queryElasticsearch
|
// Currently queryElasticsearch and queryManual are valid implementations.
|
||||||
|
query: queryManual
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user