Skip to content

Commit

Permalink
fix: catch search errors and remove problematic stemmer (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
vpicone authored Nov 15, 2019
1 parent d57b6bd commit ac005b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 0 additions & 6 deletions packages/gatsby-theme-carbon/config/lunr-options.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
const removeStemmerPlugin = lunr => builder => {
builder.pipeline.remove(lunr.stemmer);
builder.searchPipeline.remove(lunr.stemmer);
};

module.exports = {
languages: [
{
name: 'en',
filterNodes: node => node.context && node.context.MdxNode,
plugins: [removeStemmerPlugin],
},
],
fields: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ const MAX_RESULT_LIST_SIZE = 8;

const search = _throttle(queryString => {
if (window.__LUNR__) {
const lunrIndex = window.__LUNR__.en;
const searchResults = lunrIndex.index
.search(`${queryString}*`)
.slice(0, MAX_RESULT_LIST_SIZE);
return searchResults.map(({ ref }) => lunrIndex.store[ref]);
try {
const lunrIndex = window.__LUNR__.en;
const searchResults = lunrIndex.index
.search(`${queryString}*`)
.slice(0, MAX_RESULT_LIST_SIZE);
return searchResults.map(({ ref }) => lunrIndex.store[ref]);
} catch {
console.error(`Lunr is having issues querying for '${queryString}'`);
}
}
}, 150);

Expand Down

1 comment on commit ac005b8

@vercel
Copy link

@vercel vercel bot commented on ac005b8 Nov 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.