From 77f0742b100978a8a2f119974f8054c4089a1154 Mon Sep 17 00:00:00 2001 From: Tom Wardrop Date: Tue, 19 Dec 2017 09:42:09 +1000 Subject: [PATCH] Added word boundaries options Added option to allow searching only at the beginning of word boundaries --- lib/sifter.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/sifter.js b/lib/sifter.js index 31adec6..9d3f0cf 100644 --- a/lib/sifter.js +++ b/lib/sifter.js @@ -45,7 +45,7 @@ * @param {string} query * @returns {array} */ - Sifter.prototype.tokenize = function(query) { + Sifter.prototype.tokenize = function(query, respect_word_boundaries) { query = trim(String(query || '').toLowerCase()); if (!query || !query.length) return []; @@ -62,6 +62,7 @@ } } } + if (respect_word_boundaries) regex = "\\b"+regex tokens.push({ string : words[i], regex : new RegExp(regex, 'i') @@ -318,7 +319,7 @@ return { options : options, query : String(query || '').toLowerCase(), - tokens : this.tokenize(query), + tokens : this.tokenize(query, options.respect_word_boundaries), total : 0, items : [] };