Skip to content

Commit

Permalink
Account for left-hand whitespace in token positions
Browse files Browse the repository at this point in the history
Fixes GH olivernn#417
  • Loading branch information
hoelzro committed Oct 5, 2019
1 parent 28d4f97 commit c00c2b9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ lunr.tokenizer = function (obj, metadata) {
})
}

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

for (var sliceEnd = 0, sliceStart = 0; sliceEnd <= len; sliceEnd++) {
Expand All @@ -47,7 +49,7 @@ lunr.tokenizer = function (obj, metadata) {

if (sliceLength > 0) {
var tokenMetadata = lunr.utils.clone(metadata) || {}
tokenMetadata["position"] = [sliceStart, sliceLength]
tokenMetadata["position"] = [sliceStart + leftPadLength, sliceLength]
tokenMetadata["index"] = tokens.length

tokens.push(
Expand Down

0 comments on commit c00c2b9

Please sign in to comment.