From cc8876d62326395ca1d3485f39c07e6a83bda406 Mon Sep 17 00:00:00 2001 From: Rob Hoelz Date: Thu, 25 Oct 2018 19:37:59 -0500 Subject: [PATCH] Make sure fuzzy strings have fuzziness at the end Fixes GH #375 Before, insertions were not made at the end of a fuzzy string for token sets --- lib/token_set.js | 12 ++++++------ test/token_set_test.js | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/token_set.js b/lib/token_set.js index ec6fd22a..9c7802d8 100644 --- a/lib/token_set.js +++ b/lib/token_set.js @@ -117,13 +117,13 @@ lunr.TokenSet.fromFuzzyString = function (str, editDistance) { if (frame.str.length == 1) { noEditNode.final = true - } else { - stack.push({ - node: noEditNode, - editsRemaining: frame.editsRemaining, - str: frame.str.slice(1) - }) } + + stack.push({ + node: noEditNode, + editsRemaining: frame.editsRemaining, + str: frame.str.slice(1) + }) } // deletion diff --git a/test/token_set_test.js b/test/token_set_test.js index 14e2fe26..41cba5ab 100644 --- a/test/token_set_test.js +++ b/test/token_set_test.js @@ -272,6 +272,7 @@ suite('lunr.TokenSet', function () { x4 = lunr.TokenSet.fromString('bar'), x5 = lunr.TokenSet.fromString('ba'), x6 = lunr.TokenSet.fromString('foo'), + x7 = lunr.TokenSet.fromString('bara'), y = lunr.TokenSet.fromFuzzyString('bar', 1) assert.sameMembers(x1.intersect(y).toArray(), ["bbar"]) @@ -280,6 +281,7 @@ suite('lunr.TokenSet', function () { assert.sameMembers(x4.intersect(y).toArray(), ["bar"]) assert.sameMembers(x5.intersect(y).toArray(), ["ba"]) assert.equal(x6.intersect(y).toArray().length, 0) + assert.sameMembers(x7.intersect(y).toArray(), ["bara"]) }) test('intersect with fuzzy string transpose', function () {