From ebb8897165adeb758f559121b461b4cbd8e723c1 Mon Sep 17 00:00:00 2001 From: Chasen Le Hara Date: Fri, 2 Jun 2017 17:30:47 -0700 Subject: [PATCH] =?UTF-8?q?Fix=20searching=20for=20terms=20like=20?= =?UTF-8?q?=E2=80=9C%special=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://github.com/canjs/bit-docs-html-canjs/issues/279 --- static/search.js | 6 +++--- test/search.js | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/static/search.js b/static/search.js index 44ec9d16..94f503e1 100644 --- a/static/search.js +++ b/static/search.js @@ -313,7 +313,7 @@ var Search = Control.extend({ var searchIndexVersionKey = this.formatLocalStorageKey(this.searchIndexVersionLocalStorageKey); var index = this.getLocalStorageItem(searchIndexKey); var indexVersion = this.getLocalStorageItem(searchIndexVersionKey); - var currentIndexVersion = 1;// Bump this whenever the index code is changed + var currentIndexVersion = 2;// Bump this whenever the index code is changed if (index && currentIndexVersion === indexVersion) { searchEngine = lunr.Index.load(index); @@ -323,6 +323,7 @@ var Search = Control.extend({ this.pipeline.remove(lunr.stemmer); this.pipeline.remove(lunr.stopWordFilter); + this.pipeline.remove(lunr.trimmer); this.searchPipeline.remove(lunr.stemmer); this.ref('name'); @@ -353,11 +354,10 @@ var Search = Control.extend({ //run the search .query(function(q) { - if (searchTerm.indexOf('can-') > -1) {// If the search term includes “can-” // look for an exact match and apply a large positive boost - q.term(searchTerm, { usePipeline: true, boost: 120 }); + q.term(searchTerm, { usePipeline: true, boost: 375 }); } else { // add “can-”, look for an exact match in the title field, and apply a positive boost diff --git a/test/search.js b/test/search.js index 385dd374..a80acbd5 100644 --- a/test/search.js +++ b/test/search.js @@ -85,3 +85,12 @@ QUnit.test('Search for “stache”', function(assert) { done(); }); }); + +QUnit.test('Search for “%special”', function(assert) { + var done = assert.async(); + search.searchEngineSearch('%special').then(function(results) { + assert.equal(results.length > 0, true, 'got results'); + assert.equal(indexOfPageInResults('can-stache/keys/special', results), 0, 'first result is the can-stache/keys/special page'); + done(); + }); +});