Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion assets/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, ' ')
Copy link
Member

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?

Copy link
Contributor Author

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.Fun was only getting split into Mod Mod2.Fun so you couldn't search for Mod2 or Fun independently.

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 })
Copy link
Member

Choose a reason for hiding this comment

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

My JavaScript-fu is weak, so what does clone().update(function() { return str }) does? It feels unnatural but I am sure there is a reason. :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 token is an object, not just a string, so I think it's capturing the meta-data of the base token but changing the text associated with it.

})
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)
Expand Down
1 change: 0 additions & 1 deletion formatters/epub/dist/app-55d870bb4ec26b7e0a4d.js

This file was deleted.

1 change: 1 addition & 0 deletions formatters/epub/dist/app-68d4672fcc635d8d3973.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.