From dbb5b2e8c384e0ad2040cc04ffc03b24f369b4de Mon Sep 17 00:00:00 2001 From: squidfunk Date: Wed, 4 Mar 2020 21:42:19 +0100 Subject: [PATCH] Refactored search pipeline configuration --- .../integrations/search/_/index.ts | 28 ++++++++++--------- src/partials/language/ar.html | 3 +- src/partials/language/en.html | 3 +- src/partials/language/et.html | 3 +- src/partials/language/fa.html | 3 +- src/partials/language/gr.html | 3 +- src/partials/language/he.html | 3 +- src/partials/language/hi.html | 3 +- src/partials/language/hr.html | 3 +- src/partials/language/id.html | 3 +- src/partials/language/pl.html | 3 +- src/partials/language/sr.html | 3 +- 12 files changed, 26 insertions(+), 35 deletions(-) diff --git a/src/assets/javascripts/integrations/search/_/index.ts b/src/assets/javascripts/integrations/search/_/index.ts index 000be4c2f..6f9cdc784 100644 --- a/src/assets/javascripts/integrations/search/_/index.ts +++ b/src/assets/javascripts/integrations/search/_/index.ts @@ -52,13 +52,20 @@ export interface SearchIndexDocument { text: string /* Document text */ } +/* ------------------------------------------------------------------------- */ + +/** + * Search index pipeline function + */ +export type SearchIndexPipelineFn = + | "stemmer" /* Stemmer */ + | "stopWordFilter" /* Stop word filter */ + | "trimmer" /* Trimmer */ + /** * Search index pipeline */ -export interface SearchIndexPipeline { - trimmer: boolean /* Add trimmer to pipeline */ - stopwords: boolean /* Add stopword filter to pipeline */ -} +export type SearchIndexPipeline = SearchIndexPipelineFn[] /* ------------------------------------------------------------------------- */ @@ -129,17 +136,12 @@ export class SearchIndex { /* If no index was given, create it */ if (typeof index === "undefined") { this.index = lunr(function() { - pipeline = pipeline || { - trimmer: true, - stopwords: true - } + pipeline = pipeline || ["trimmer", "stopWordFilter"] - /* Remove stemmer, as it cripples search experience */ + /* Set up pipeline according to configuration */ this.pipeline.reset() - if (pipeline.trimmer) - this.pipeline.add(lunr.trimmer) - if (pipeline.stopwords) - this.pipeline.add(lunr.stopWordFilter) + for (const fn of pipeline) + this.pipeline.add(lunr[fn]) /* Set up alternate search languages */ if (config.lang.length === 1 && config.lang[0] !== "en") { diff --git a/src/partials/language/ar.html b/src/partials/language/ar.html index 1b68d0b5c..60e90c82c 100644 --- a/src/partials/language/ar.html +++ b/src/partials/language/ar.html @@ -32,8 +32,7 @@ "meta.comments": "التعليقات", "meta.source": "المصدر", "search.language": "", - "search.pipeline.stopwords": false, - "search.pipeline.trimmer": false, + "search.pipeline": "", "search.placeholder": "بحث", "search.result.placeholder": "اكتب لبدء البحث", "search.result.none": "لا توجد نتائج", diff --git a/src/partials/language/en.html b/src/partials/language/en.html index 77c2487c2..bd19393bb 100644 --- a/src/partials/language/en.html +++ b/src/partials/language/en.html @@ -32,8 +32,7 @@ "meta.comments": "Comments", "meta.source": "Source", "search.language": "en", - "search.pipeline.stopwords": true, - "search.pipeline.trimmer": true, + "search.pipeline": "trimmer, stopWordFilter", "search.placeholder": "Search", "search.result.placeholder": "Type to start searching", "search.result.none": "No matching documents", diff --git a/src/partials/language/et.html b/src/partials/language/et.html index 1fea4d8c6..2e87d5599 100644 --- a/src/partials/language/et.html +++ b/src/partials/language/et.html @@ -31,8 +31,7 @@ "meta.comments": "Kommentaarid", "meta.source": "Lähtekood", "search.language": "", - "search.pipeline.stopwords": false, - "search.pipeline.trimmer": false, + "search.pipeline": "", "search.placeholder": "Otsi", "search.result.placeholder": "Otsimiseks kirjuta siia", "search.result.none": "Otsingule ei leitud ühtegi vastet", diff --git a/src/partials/language/fa.html b/src/partials/language/fa.html index 0336616c6..6d10fc6c2 100644 --- a/src/partials/language/fa.html +++ b/src/partials/language/fa.html @@ -32,8 +32,7 @@ "meta.comments": "نظرات", "meta.source": "منبع", "search.language": "", - "search.pipeline.stopwords": false, - "search.pipeline.trimmer": false, + "search.pipeline": "", "search.placeholder": "جستجو", "search.result.placeholder": "برای شروع جستجو تایپ کنید", "search.result.none": "سندی یافت نشد", diff --git a/src/partials/language/gr.html b/src/partials/language/gr.html index 2c9e1fccd..e3ed4f05a 100644 --- a/src/partials/language/gr.html +++ b/src/partials/language/gr.html @@ -31,8 +31,7 @@ "meta.comments": "Σχόλια", "meta.source": "Πηγή", "search.language": "", - "search.pipeline.stopwords": false, - "search.pipeline.trimmer": false, + "search.pipeline": "", "search.placeholder": "Αναζήτηση", "search.result.placeholder": "Πληκτρολογήστε για να αρχίσει η αναζήτηση", "search.result.none": "Δε βρέθηκαν αντίστοιχα αρχεία", diff --git a/src/partials/language/he.html b/src/partials/language/he.html index eb154f560..db343c17b 100644 --- a/src/partials/language/he.html +++ b/src/partials/language/he.html @@ -32,8 +32,7 @@ "meta.comments": "הערות", "meta.source": "מָקוֹר", "search.language": "", - "search.pipeline.stopwords": false, - "search.pipeline.trimmer": false, + "search.pipeline": "", "search.placeholder": "לחפש", "search.result.placeholder": "הקלד כדי להתחיל לחפש", "search.result.none": "אין מסמכים תואמים", diff --git a/src/partials/language/hi.html b/src/partials/language/hi.html index 8dc86241b..f146ec5cf 100644 --- a/src/partials/language/hi.html +++ b/src/partials/language/hi.html @@ -31,8 +31,7 @@ "meta.comments": "टिप्पणियाँ", "meta.source": "स्रोत", "search.language": "", - "search.pipeline.stopwords": false, - "search.pipeline.trimmer": false, + "search.pipeline": "", "search.placeholder": "खोज", "search.result.placeholder": "खोज शुरू करने के लिए टाइप करें", "search.result.none": "कोई मिलान डॉक्यूमेंट नहीं", diff --git a/src/partials/language/hr.html b/src/partials/language/hr.html index b76291171..f242547b5 100644 --- a/src/partials/language/hr.html +++ b/src/partials/language/hr.html @@ -31,8 +31,7 @@ "meta.comments": "Komentari", "meta.source": "Izvor", "search.language": "", - "search.pipeline.stopwords": false, - "search.pipeline.trimmer": false, + "search.pipeline": "", "search.placeholder": "Pretraživanje", "search.result.placeholder": "Unesite pojam pretraživanja", "search.result.none": "Ništa nije pronađeno", diff --git a/src/partials/language/id.html b/src/partials/language/id.html index e59d2b221..b6f250419 100644 --- a/src/partials/language/id.html +++ b/src/partials/language/id.html @@ -31,8 +31,7 @@ "meta.comments": "Komentar", "meta.source": "Sumber", "search.language": "", - "search.pipeline.stopwords": false, - "search.pipeline.trimmer": false, + "search.pipeline": "", "search.placeholder": "Cari", "search.result.placeholder": "Ketik untuk mulai pencarian", "search.result.none": "Tidak ada dokumen yang sesuai", diff --git a/src/partials/language/pl.html b/src/partials/language/pl.html index bfd9820c7..3be29e899 100755 --- a/src/partials/language/pl.html +++ b/src/partials/language/pl.html @@ -31,8 +31,7 @@ "meta.comments": "Komentarze", "meta.source": "Kod źródłowy", "search.language": "", - "search.pipeline.stopwords": false, - "search.pipeline.trimmer": false, + "search.pipeline": "", "search.placeholder": "Szukaj", "search.result.placeholder": "Zacznij pisać, aby szukać", "search.result.none": "Brak wyników wyszukiwania", diff --git a/src/partials/language/sr.html b/src/partials/language/sr.html index 8db4879c7..44ec8c366 100644 --- a/src/partials/language/sr.html +++ b/src/partials/language/sr.html @@ -31,8 +31,7 @@ "meta.comments": "Коментари", "meta.source": "Извор", "search.language": "", - "search.pipeline.stopwords": false, - "search.pipeline.trimmer": false, + "search.pipeline": "", "search.placeholder": "Претрага", "search.result.placeholder": "Унесите појам претраге", "search.result.none": "Нису пронађени документи",