Skip to content

Commit

Permalink
Merge pull request #38 from ConvivioTeam/replace-default-stop-words-f…
Browse files Browse the repository at this point in the history
…ilter

Replace default stop words filter with a custom function.
  • Loading branch information
MatMoore authored Jul 27, 2018
2 parents 445243c + e6fc9fd commit 51ae107
Showing 1 changed file with 130 additions and 1 deletion.
131 changes: 130 additions & 1 deletion lib/assets/javascripts/_modules/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
success: function(data) {
s.lunrData = data;
s.lunrIndex = lunr.Index.load(s.lunrData.index);
replaceStopWordFilter();
$(document).trigger('lunrIndexLoaded');
}
});
Expand Down Expand Up @@ -84,7 +85,6 @@
results.push(s.lunrData.docs[item.ref]);
}
});

return results;
}

Expand Down Expand Up @@ -175,6 +175,135 @@
.attr('aria-hidden', 'true');
$html.removeClass('has-search-results-open');
}

function replaceStopWordFilter() {
// Replace the default stopWordFilter as it excludes useful words like
// 'get'
// See: https://lunrjs.com/docs/stop_word_filter.js.html#line43
s.lunrIndex.pipeline.remove(lunr.stopWordFilter);
s.lunrIndex.pipeline.add(s.govukStopWorldFilter);
}

this.govukStopWorldFilter = 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',
'every',
'for',
'from',
'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',
'of',
'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'
])
};

// Polyfill includes
Expand Down

0 comments on commit 51ae107

Please sign in to comment.