Skip to content

Commit

Permalink
chore: use custom stop word filter for lunr
Browse files Browse the repository at this point in the history
  • Loading branch information
tmair committed May 24, 2022
1 parent afc03b1 commit b290007
Showing 1 changed file with 127 additions and 0 deletions.
127 changes: 127 additions & 0 deletions docs_app/src/app/search/search.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ function createIndex(loadIndexFn: IndexLoader): lunr.Index {
queryLexer.termSeparator = lunr.tokenizer.separator = /\s+/;
return lunr(function () {
this.pipeline.remove(lunr.stemmer);
this.pipeline.remove(lunr.stopWordFilter);
this.pipeline.add(stopWordFilter);
this.ref('path');
this.field('topics', { boost: 15 });
this.field('title', { boost: 10 });
Expand Down Expand Up @@ -146,4 +148,129 @@ function queryIndex(query: string): PageInfo[] {
return [];
}

/**
* stop words are copied from lunr default list with the following words removed:
* - from
* - of
* - every
*/
const stopWordFilter = lunr.generateStopWordFilter([
'a',
'able',
'about',
'across',
'after',
'all',
'almost',
'also',
'am',
'among',
'an',
'and',
'any',
'are',
'as',
'at',
'be',
'because',
'been',
'but',
'by',
'can',
'cannot',
'could',
'dear',
'did',
'do',
'does',
'either',
'else',
'ever',
'for',
'get',
'got',
'had',
'has',
'have',
'he',
'her',
'hers',
'him',
'his',
'how',
'however',
'i',
'if',
'in',
'into',
'is',
'it',
'its',
'just',
'least',
'let',
'like',
'likely',
'may',
'me',
'might',
'most',
'must',
'my',
'neither',
'no',
'nor',
'not',
'off',
'often',
'on',
'only',
'or',
'other',
'our',
'own',
'rather',
'said',
'say',
'says',
'she',
'should',
'since',
'so',
'some',
'than',
'that',
'the',
'their',
'them',
'then',
'there',
'these',
'they',
'this',
'tis',
'to',
'too',
'twas',
'us',
'wants',
'was',
'we',
'were',
'what',
'when',
'where',
'which',
'while',
'who',
'whom',
'why',
'will',
'with',
'would',
'yet',
'you',
'your',
]);

type IndexLoader = (indexBuilder: lunr.Builder) => void;

0 comments on commit b290007

Please sign in to comment.