From 7d8d5c86cfce682166bb55bc2298f2658c75cdc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Goetz?= Date: Mon, 1 Oct 2018 22:25:59 +0200 Subject: [PATCH] Search only in current language, fixes #48 --- templates/layout/00_layout.php | 1 + tipuesearch/tipuesearch.js | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/templates/layout/00_layout.php b/templates/layout/00_layout.php index bc94a40..52bd749 100755 --- a/templates/layout/00_layout.php +++ b/templates/layout/00_layout.php @@ -82,6 +82,7 @@ } ?> + window.searchLanguage = ; window.searchTranslation = ; diff --git a/tipuesearch/tipuesearch.js b/tipuesearch/tipuesearch.js index 7f9263d..45342ac 100644 --- a/tipuesearch/tipuesearch.js +++ b/tipuesearch/tipuesearch.js @@ -169,32 +169,41 @@ function getResults(searchFor, standard) { var found = []; + var pages = tipuesearch_in.pages; + + // If a searchLanguage is set, filter out all other pages + if (window.searchLanguage) { + pages = pages.filter(function(item) { + return item.url.indexOf(window.searchLanguage + "/") === 0; + }) + } + if (standard) { var d_w = searchFor.split(' '); - for (var i = 0; i < tipuesearch_in.pages.length; i++) { + for (var i = 0; i < pages.length; i++) { var score = 0; - var text = tipuesearch_in.pages[i].text; + var text = pages[i].text; for (var f = 0; f < d_w.length; f++) { if (d_w[f].match('^-')) { var pat = new RegExp(d_w[f].substring(1), 'i'); - if (tipuesearch_in.pages[i].title.search(pat) != -1 || tipuesearch_in.pages[i].text.search(pat) != -1 || tipuesearch_in.pages[i].tags.search(pat) != -1) { + if (pages[i].title.search(pat) != -1 || pages[i].text.search(pat) != -1 || pages[i].tags.search(pat) != -1) { score = 0; } } else { - score += getScore(d_w[f], tipuesearch_in.pages[i]); + score += getScore(d_w[f], pages[i]); text = highlightText(d_w[f], text); } } if (score != 0) { - found.push(makeResult(score, tipuesearch_in.pages[i], text)); + found.push(makeResult(score, pages[i], text)); } } } else { - for (var i = 0; i < tipuesearch_in.pages.length; i++) { - var score = getScore(searchFor, tipuesearch_in.pages[i]); + for (var i = 0; i < pages.length; i++) { + var score = getScore(searchFor, pages[i]); if (score != 0) { - found.push(makeResult(score, tipuesearch_in.pages[i], highlightText(searchFor, tipuesearch_in.pages[i].text))); + found.push(makeResult(score, pages[i], highlightText(searchFor, pages[i].text))); } } }