Skip to content

Commit

Permalink
Fix loading serialized index from sessionStorage (#1579)
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyvanderaerden committed Jun 16, 2022
1 parent 935f2da commit 7f3b649
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions assets/js/search-page.js
Expand Up @@ -58,6 +58,7 @@ function loadIndex () {
try {
const serializedIndex = sessionStorage.getItem(indexStorageKey())
if (serializedIndex) {
registerElixirTokenFunction()
return lunr.Index.load(JSON.parse(serializedIndex))
} else {
return null
Expand Down Expand Up @@ -97,24 +98,28 @@ function createIndex () {
}

function elixirTokenSplitter (builder) {
function elixirTokenFunction (token) {
const tokens = token
.toString()
.split(/\.|\/|_/)
.map(part => {
return token.clone().update(() => part)
})
registerElixirTokenFunction()
builder.pipeline.before(lunr.stemmer, elixirTokenFunction)
builder.searchPipeline.before(lunr.stemmer, elixirTokenFunction)
}

if (tokens.length > 1) {
return [...tokens, token]
}
function elixirTokenFunction (token) {
const tokens = token
.toString()
.split(/\.|\/|_/)
.map(part => {
return token.clone().update(() => part)
})

return tokens
if (tokens.length > 1) {
return [...tokens, token]
}

lunr.Pipeline.registerFunction(elixirTokenFunction, 'elixirTokenSplitter')
builder.pipeline.before(lunr.stemmer, elixirTokenFunction)
builder.searchPipeline.before(lunr.stemmer, elixirTokenFunction)
return tokens
}

function registerElixirTokenFunction () {
return lunr.Pipeline.registerFunction(elixirTokenFunction, 'elixirTokenSplitter')
}

function searchResultsToDecoratedSearchNodes (results) {
Expand Down

0 comments on commit 7f3b649

Please sign in to comment.