Skip to content

Commit

Permalink
Upgrade Lunrjs to 2.3.9 and switch to relative_url (mmistakes#2805)
Browse files Browse the repository at this point in the history
* Update Lunr to 2.3.9

* Switch from absolute_url to relative_url
  • Loading branch information
lsolesen authored and chukycheese committed Sep 18, 2023
1 parent 8d0ad37 commit dec88d2
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 79 deletions.
4 changes: 2 additions & 2 deletions assets/js/lunr/lunr-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ var store = [
{%- endif -%}
"categories": {{ doc.categories | jsonify }},
"tags": {{ doc.tags | jsonify }},
"url": {{ doc.url | absolute_url | jsonify }},
"teaser": {{ teaser | absolute_url | jsonify }}
"url": {{ doc.url | relative_url | jsonify }},
"teaser": {{ teaser | relative_url | jsonify }}
}{%- unless forloop.last and l -%},{%- endunless -%}
{%- endfor -%}
{%- endfor -%}]
143 changes: 67 additions & 76 deletions assets/js/lunr/lunr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 2.3.5
* Copyright (C) 2018 Oliver Nightingale
* lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 2.3.9
* Copyright (C) 2020 Oliver Nightingale
* @license MIT
*/

Expand Down Expand Up @@ -54,10 +54,10 @@ var lunr = function (config) {
return builder.build()
}

lunr.version = "2.3.5"
lunr.version = "2.3.9"
/*!
* lunr.utils
* Copyright (C) 2018 Oliver Nightingale
* Copyright (C) 2020 Oliver Nightingale
*/

/**
Expand Down Expand Up @@ -177,7 +177,7 @@ lunr.FieldRef.prototype.toString = function () {
}
/*!
* lunr.Set
* Copyright (C) 2018 Oliver Nightingale
* Copyright (C) 2020 Oliver Nightingale
*/

/**
Expand Down Expand Up @@ -211,8 +211,8 @@ lunr.Set.complete = {
return other
},

union: function (other) {
return other
union: function () {
return this
},

contains: function () {
Expand Down Expand Up @@ -389,7 +389,7 @@ lunr.Token.prototype.clone = function (fn) {
}
/*!
* lunr.tokenizer
* Copyright (C) 2018 Oliver Nightingale
* Copyright (C) 2020 Oliver Nightingale
*/

/**
Expand Down Expand Up @@ -424,7 +424,7 @@ lunr.tokenizer = function (obj, metadata) {
})
}

var str = obj.toString().trim().toLowerCase(),
var str = obj.toString().toLowerCase(),
len = str.length,
tokens = []

Expand Down Expand Up @@ -465,7 +465,7 @@ lunr.tokenizer = function (obj, metadata) {
lunr.tokenizer.separator = /[\s\-]+/
/*!
* lunr.Pipeline
* Copyright (C) 2018 Oliver Nightingale
* Copyright (C) 2020 Oliver Nightingale
*/

/**
Expand Down Expand Up @@ -509,8 +509,8 @@ lunr.Pipeline.registeredFunctions = Object.create(null)
* or mutate (or add) metadata for a given token.
*
* A pipeline function can indicate that the passed token should be discarded by returning
* null. This token will not be passed to any downstream pipeline functions and will not be
* added to the index.
* null, undefined or an empty string. This token will not be passed to any downstream pipeline
* functions and will not be added to the index.
*
* Multiple tokens can be returned by returning an array of tokens. Each token will be passed
* to any downstream pipeline functions and all will returned tokens will be added to the index.
Expand Down Expand Up @@ -673,7 +673,7 @@ lunr.Pipeline.prototype.run = function (tokens) {
for (var j = 0; j < tokens.length; j++) {
var result = fn(tokens[j], j, tokens)

if (result === void 0 || result === '') continue
if (result === null || result === void 0 || result === '') continue

if (Array.isArray(result)) {
for (var k = 0; k < result.length; k++) {
Expand Down Expand Up @@ -732,7 +732,7 @@ lunr.Pipeline.prototype.toJSON = function () {
}
/*!
* lunr.Vector
* Copyright (C) 2018 Oliver Nightingale
* Copyright (C) 2020 Oliver Nightingale
*/

/**
Expand Down Expand Up @@ -929,7 +929,7 @@ lunr.Vector.prototype.toJSON = function () {
/* eslint-disable */
/*!
* lunr.stemmer
* Copyright (C) 2018 Oliver Nightingale
* Copyright (C) 2020 Oliver Nightingale
* Includes code from - http://tartarus.org/~martin/PorterStemmer/js.txt
*/

Expand Down Expand Up @@ -1151,7 +1151,7 @@ lunr.stemmer = (function(){
lunr.Pipeline.registerFunction(lunr.stemmer, 'stemmer')
/*!
* lunr.stopWordFilter
* Copyright (C) 2018 Oliver Nightingale
* Copyright (C) 2020 Oliver Nightingale
*/

/**
Expand Down Expand Up @@ -1316,7 +1316,7 @@ lunr.stopWordFilter = lunr.generateStopWordFilter([
lunr.Pipeline.registerFunction(lunr.stopWordFilter, 'stopWordFilter')
/*!
* lunr.trimmer
* Copyright (C) 2018 Oliver Nightingale
* Copyright (C) 2020 Oliver Nightingale
*/

/**
Expand All @@ -1343,7 +1343,7 @@ lunr.trimmer = function (token) {
lunr.Pipeline.registerFunction(lunr.trimmer, 'trimmer')
/*!
* lunr.TokenSet
* Copyright (C) 2018 Oliver Nightingale
* Copyright (C) 2020 Oliver Nightingale
*/

/**
Expand Down Expand Up @@ -1469,41 +1469,49 @@ lunr.TokenSet.fromFuzzyString = function (str, editDistance) {
})
}

if (frame.editsRemaining == 0) {
continue
}

// insertion
if ("*" in frame.node.edges) {
var insertionNode = frame.node.edges["*"]
} else {
var insertionNode = new lunr.TokenSet
frame.node.edges["*"] = insertionNode
}

if (frame.str.length == 0) {
insertionNode.final = true
}

stack.push({
node: insertionNode,
editsRemaining: frame.editsRemaining - 1,
str: frame.str
})

// deletion
// can only do a deletion if we have enough edits remaining
// and if there are characters left to delete in the string
if (frame.editsRemaining > 0 && frame.str.length > 1) {
var char = frame.str.charAt(1),
deletionNode

if (char in frame.node.edges) {
deletionNode = frame.node.edges[char]
} else {
deletionNode = new lunr.TokenSet
frame.node.edges[char] = deletionNode
}

if (frame.str.length <= 2) {
deletionNode.final = true
} else {
stack.push({
node: deletionNode,
editsRemaining: frame.editsRemaining - 1,
str: frame.str.slice(2)
})
}
if (frame.str.length > 1) {
stack.push({
node: frame.node,
editsRemaining: frame.editsRemaining - 1,
str: frame.str.slice(1)
})
}

// deletion
// just removing the last character from the str
if (frame.editsRemaining > 0 && frame.str.length == 1) {
if (frame.str.length == 1) {
frame.node.final = true
}

// substitution
// can only do a substitution if we have enough edits remaining
// and if there are characters left to substitute
if (frame.editsRemaining > 0 && frame.str.length >= 1) {
if (frame.str.length >= 1) {
if ("*" in frame.node.edges) {
var substitutionNode = frame.node.edges["*"]
} else {
Expand All @@ -1513,40 +1521,19 @@ lunr.TokenSet.fromFuzzyString = function (str, editDistance) {

if (frame.str.length == 1) {
substitutionNode.final = true
} else {
stack.push({
node: substitutionNode,
editsRemaining: frame.editsRemaining - 1,
str: frame.str.slice(1)
})
}
}

// insertion
// can only do insertion if there are edits remaining
if (frame.editsRemaining > 0) {
if ("*" in frame.node.edges) {
var insertionNode = frame.node.edges["*"]
} else {
var insertionNode = new lunr.TokenSet
frame.node.edges["*"] = insertionNode
}

if (frame.str.length == 0) {
insertionNode.final = true
} else {
stack.push({
node: insertionNode,
editsRemaining: frame.editsRemaining - 1,
str: frame.str
})
}
stack.push({
node: substitutionNode,
editsRemaining: frame.editsRemaining - 1,
str: frame.str.slice(1)
})
}

// transposition
// can only do a transposition if there are edits remaining
// and there are enough characters to transpose
if (frame.editsRemaining > 0 && frame.str.length > 1) {
if (frame.str.length > 1) {
var charA = frame.str.charAt(0),
charB = frame.str.charAt(1),
transposeNode
Expand All @@ -1560,13 +1547,13 @@ lunr.TokenSet.fromFuzzyString = function (str, editDistance) {

if (frame.str.length == 1) {
transposeNode.final = true
} else {
stack.push({
node: transposeNode,
editsRemaining: frame.editsRemaining - 1,
str: charA + frame.str.slice(2)
})
}

stack.push({
node: transposeNode,
editsRemaining: frame.editsRemaining - 1,
str: charA + frame.str.slice(2)
})
}
}

Expand Down Expand Up @@ -1619,6 +1606,10 @@ lunr.TokenSet.fromString = function (str) {
* Converts this TokenSet into an array of strings
* contained within the TokenSet.
*
* This is not intended to be used on a TokenSet that
* contains wildcards, in these cases the results are
* undefined and are likely to cause an infinite loop.
*
* @returns {string[]}
*/
lunr.TokenSet.prototype.toArray = function () {
Expand Down Expand Up @@ -1836,7 +1827,7 @@ lunr.TokenSet.Builder.prototype.minimize = function (downTo) {
}
/*!
* lunr.Index
* Copyright (C) 2018 Oliver Nightingale
* Copyright (C) 2020 Oliver Nightingale
*/

/**
Expand Down Expand Up @@ -2003,7 +1994,7 @@ lunr.Index.prototype.query = function (fn) {
*/
var clause = query.clauses[i],
terms = null,
clauseMatches = lunr.Set.complete
clauseMatches = lunr.Set.empty

if (clause.usePipeline) {
terms = this.pipeline.runString(clause.term, {
Expand Down Expand Up @@ -2328,7 +2319,7 @@ lunr.Index.load = function (serializedIndex) {
}
/*!
* lunr.Builder
* Copyright (C) 2018 Oliver Nightingale
* Copyright (C) 2020 Oliver Nightingale
*/

/**
Expand Down
Loading

0 comments on commit dec88d2

Please sign in to comment.