HTML: list-lib Search must support spaces in the search string

The search result of a string consisting of separate words must be the
intersection of the search results of each word.
This way searching strings with spaces will be supported.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Gehad elrobey 2014-07-17 05:15:28 +02:00 committed by Dirk Hohndel
parent c7cefd421c
commit 6f6ed864bc

View file

@ -460,6 +460,20 @@ Set.prototype.Union = function(another_set)
}; };
}; };
Set.prototype.intersect = function(another_set)
{
if (another_set === null) {
return;
}
var result = new Array();
for (var i = 0; i < another_set.keys.length; i++) {
if(this.contains(another_set.keys[i])) {
result.push(another_set.keys[i]);
}
};
this.keys = result;
};
function Node(value) function Node(value)
{ {
this.children = new Array(); this.children = new Array();
@ -486,24 +500,32 @@ function SearchModules(searchfor)
return; return;
} }
searchingModules.forEach (function(x) { var keywords = searchfor.split(" ");
resultKeys.Union(x.search(searchfor));
}); for (var i = 0; i < keywords.length; i++) {
var keywordResult = new Set();
if (searchingModules["location"].enabled === true) if (searchingModules["location"].enabled === true)
resultKeys.Union(searchingModules["location"].search(searchfor)); keywordResult.Union(searchingModules["location"].search(keywords[i]));
if (searchingModules["divemaster"].enabled === true) if (searchingModules["divemaster"].enabled === true)
resultKeys.Union(searchingModules["divemaster"].search(searchfor)); keywordResult.Union(searchingModules["divemaster"].search(keywords[i]));
if (searchingModules["buddy"].enabled === true) if (searchingModules["buddy"].enabled === true)
resultKeys.Union(searchingModules["buddy"].search(searchfor)); keywordResult.Union(searchingModules["buddy"].search(keywords[i]));
if (searchingModules["notes"].enabled === true) if (searchingModules["notes"].enabled === true)
resultKeys.Union(searchingModules["notes"].search(searchfor)); keywordResult.Union(searchingModules["notes"].search(keywords[i]));
if (searchingModules["tags"].enabled === true) if (searchingModules["tags"].enabled === true)
resultKeys.Union(searchingModules["tags"].search(searchfor)); keywordResult.Union(searchingModules["tags"].search(keywords[i]));
if (resultKeys.isEmpty()) {
resultKeys.Union(keywordResult);
} else {
resultKeys.intersect(keywordResult);
}
}
if (resultKeys.isEmpty()) { if (resultKeys.isEmpty()) {
//didn't find keys //didn't find keys