Skip to content

Commit

Permalink
fix for #1588
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoopman committed Aug 16, 2022
1 parent f0bf412 commit 2b0ac8d
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion assets/js/search-page.js
Expand Up @@ -83,13 +83,16 @@ function indexStorageKey () {
return `index:${getProjectNameAndVersion()}`
}

function createIndex () {
export function createIndex () {
lunr.QueryLexer.termSeparator = /\s+/
return lunr(function () {
this.tokenizer.separator = /\s+/
this.ref('ref')
this.field('title', { boost: 3 })
this.field('doc')
this.metadataWhitelist = ['position']
this.pipeline.remove(lunr.stopWordFilter)
this.use(hyphenSearchPipeline)
this.use(elixirTokenSplitter)
this.pipeline.remove(lunr.trimmer)
this.use(elixirTrimmer)
Expand All @@ -100,6 +103,28 @@ function createIndex () {
})
}

function hyphenSearchPipeline (builder) {
var pipelineFunction = function (token) {
var tokenStr = token.toString()
if (tokenStr.indexOf('-') < 0) return token

let tokens = []

tokens.push(
token.clone(function (s) {
return s.replace('-', '')
})
)

tokens.push(token)
return tokens
}

lunr.Pipeline.registerFunction(pipelineFunction, 'customPipeline')
builder.pipeline.before(lunr.stemmer, pipelineFunction)
builder.searchPipeline.before(lunr.stemmer, pipelineFunction)
}

function elixirTokenSplitter (builder) {
registerElixirTokenFunction()
builder.pipeline.before(lunr.stemmer, elixirTokenFunction)
Expand Down

0 comments on commit 2b0ac8d

Please sign in to comment.