[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:
shale 2015-07-15 10:10:29 -07:00
parent fdcc6432f1
commit 6b3088f241

View File

@ -41,106 +41,33 @@ define(
*/
function QueryService($http, objectService, ROOT) {
/////////////// 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]);
}
*/
/////////////// The following is for non-Elastic Search /////////////////
// Recursive helper function for getItems
function itemsHelper2(children, i) {
console.log('itemshelpher2 called..... children', children);
function itemsHelper(children, i) {
var composition;
if (i >= children.length) {
console.log('base case..... children', children);
// Base case.
// Base case, is a leaf
return children;
} else if (children[i].hasCapability('composition')) {
// Handle this child's children
composition = children[i].getCapability('composition');
console.log('composition..... child[', i, ']', children[i]);
console.log('................ children', children);
return composition.invoke().then(function (grandchildren) {
console.log('grandchildren', grandchildren);
return itemsHelper2(
children.splice(0, i).concat(grandchildren, children.splice(i + 1, children.length)),
i);
// Add grandchildren to the end of the list
// They will also be checked for composition
return itemsHelper(children.concat(grandchildren), i + 1);
});
} else {
console.log('not composition..... child[', i, ']', children[i]);
return itemsHelper2(children, i + 1);
return itemsHelper(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
// Used for the fallback
// Used for queryManual
function getItems() {
// Aquire My Items (root folder)
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;
});
});
@ -148,8 +75,7 @@ define(
// Search through items for items manually
// This is a fallback if other search services aren't avaliable
// ... currently only searches 1 layer down (TODO)
function queryFallback(inputID) {
function queryManual(inputID) {
var term,
searchResults = [],
itemsLength,
@ -157,21 +83,14 @@ define(
itemName,
i;
// Get the user input
if (inputID) {
term = document.getElementById(inputID).value;
} else {
// Backward compatibility?
// TODO: May be unnecsisary
term = document.getElementById("searchinput").value;
}
// Get the user input
term = document.getElementById(inputID).value;
// Make not case sensitive
term = term.toLocaleLowerCase();
// Get items list
return getItems().then(function (items) {
// (slight time optimization)
itemsLength = items.length;
// Then filter through the items list
@ -317,7 +236,8 @@ define(
return {
// Takes a serach term and (optionally) the max number of results.
query: queryElasticsearch
// Currently queryElasticsearch and queryManual are valid implementations.
query: queryManual
};
}