From 6f6ed864bce317e06ecd0283456b9349fcf9bd02 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Thu, 17 Jul 2014 05:15:28 +0200 Subject: 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 Signed-off-by: Miika Turkia Signed-off-by: Dirk Hohndel --- theme/list_lib.js | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/theme/list_lib.js b/theme/list_lib.js index 6ba366043..dd7be94a9 100644 --- a/theme/list_lib.js +++ b/theme/list_lib.js @@ -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) { this.children = new Array(); @@ -486,24 +500,32 @@ function SearchModules(searchfor) return; } - searchingModules.forEach (function(x) { - resultKeys.Union(x.search(searchfor)); - }); + var keywords = searchfor.split(" "); + + for (var i = 0; i < keywords.length; i++) { + var keywordResult = new Set(); + + if (searchingModules["location"].enabled === true) + keywordResult.Union(searchingModules["location"].search(keywords[i])); - if (searchingModules["location"].enabled === true) - resultKeys.Union(searchingModules["location"].search(searchfor)); + if (searchingModules["divemaster"].enabled === true) + keywordResult.Union(searchingModules["divemaster"].search(keywords[i])); - if (searchingModules["divemaster"].enabled === true) - resultKeys.Union(searchingModules["divemaster"].search(searchfor)); + if (searchingModules["buddy"].enabled === true) + keywordResult.Union(searchingModules["buddy"].search(keywords[i])); - if (searchingModules["buddy"].enabled === true) - resultKeys.Union(searchingModules["buddy"].search(searchfor)); + if (searchingModules["notes"].enabled === true) + keywordResult.Union(searchingModules["notes"].search(keywords[i])); - if (searchingModules["notes"].enabled === true) - resultKeys.Union(searchingModules["notes"].search(searchfor)); + if (searchingModules["tags"].enabled === true) + keywordResult.Union(searchingModules["tags"].search(keywords[i])); - if (searchingModules["tags"].enabled === true) - resultKeys.Union(searchingModules["tags"].search(searchfor)); + if (resultKeys.isEmpty()) { + resultKeys.Union(keywordResult); + } else { + resultKeys.intersect(keywordResult); + } + } if (resultKeys.isEmpty()) { //didn't find keys -- cgit v1.2.3-70-g09d2