- Notifications
You must be signed in to change notification settings - Fork 352
Handling snake case terms in search results #1182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -122,21 +122,37 @@ function titleExtractor (document) { | |
| | ||
| if (type === 'function' || type === 'callback' || type === 'type') { | ||
| var modFun = title.replace(/\/\d+/, '') | ||
| var modOrFun = modFun.replace('.', ' ') | ||
| var modOrFun = modFun.replace(/\./g, ' ') | ||
| var parts = title.split('.') | ||
| title = title + ' ' + modFun + ' ' + modOrFun + ' ' + parts[parts.length - 1] | ||
| } | ||
| | ||
| return title | ||
| } | ||
| | ||
| function snakeCaseSplitter (builder) { | ||
| function snakeCaseFunction (token) { | ||
| var snakeTokens = token.toString().split("_").map(function (str) { | ||
| return token.clone().update(function () { return str }) | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My JavaScript-fu is weak, so what does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My Javascript is non-existent :) It's from the example they provide of splitting up email addresses (https://lunrjs.com/guides/core_concepts.html). The | ||
| }) | ||
| if (snakeTokens.length > 1) { | ||
| snakeTokens.push(token) | ||
| } | ||
| return snakeTokens | ||
| } | ||
| | ||
| lunr.Pipeline.registerFunction(snakeCaseFunction, 'snakeCaseSplitter') | ||
| builder.pipeline.before(lunr.stemmer, snakeCaseFunction) | ||
| } | ||
| | ||
| function createIndex () { | ||
| return lunr(function () { | ||
| this.ref('ref') | ||
| this.field('title', {boost: 3, extractor: titleExtractor}) | ||
| this.field('doc') | ||
| this.metadataWhitelist = ['position'] | ||
| this.pipeline.remove(lunr.stopWordFilter) | ||
| this.use(snakeCaseSplitter) | ||
| | ||
| searchNodes.forEach(function (doc) { | ||
| this.add(doc) | ||
| | ||
This file was deleted.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this change is necessary as otherwise it replaces only the first one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. This is expanding the name to make it searchable, so
Mod.Mod2.Funwas only getting split intoMod Mod2.Funso you couldn't search forMod2orFunindependently.