Skip to content

Commit d22fc01

Browse files
authored
Merge pull request #299 from canjs/279-special
Fix searching for terms like “%special”
2 parents 2d21cf9 + ebb8897 commit d22fc01

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

static/search.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ var Search = Control.extend({
313313
var searchIndexVersionKey = this.formatLocalStorageKey(this.searchIndexVersionLocalStorageKey);
314314
var index = this.getLocalStorageItem(searchIndexKey);
315315
var indexVersion = this.getLocalStorageItem(searchIndexVersionKey);
316-
var currentIndexVersion = 1;// Bump this whenever the index code is changed
316+
var currentIndexVersion = 2;// Bump this whenever the index code is changed
317317

318318
if (index && currentIndexVersion === indexVersion) {
319319
searchEngine = lunr.Index.load(index);
@@ -323,6 +323,7 @@ var Search = Control.extend({
323323

324324
this.pipeline.remove(lunr.stemmer);
325325
this.pipeline.remove(lunr.stopWordFilter);
326+
this.pipeline.remove(lunr.trimmer);
326327
this.searchPipeline.remove(lunr.stemmer);
327328

328329
this.ref('name');
@@ -353,11 +354,10 @@ var Search = Control.extend({
353354
//run the search
354355
.query(function(q) {
355356

356-
357357
if (searchTerm.indexOf('can-') > -1) {// If the search term includes “can-”
358358

359359
// look for an exact match and apply a large positive boost
360-
q.term(searchTerm, { usePipeline: true, boost: 120 });
360+
q.term(searchTerm, { usePipeline: true, boost: 375 });
361361

362362
} else {
363363
// add “can-”, look for an exact match in the title field, and apply a positive boost

test/search.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,12 @@ QUnit.test('Search for “stache”', function(assert) {
8585
done();
8686
});
8787
});
88+
89+
QUnit.test('Search for “%special”', function(assert) {
90+
var done = assert.async();
91+
search.searchEngineSearch('%special').then(function(results) {
92+
assert.equal(results.length > 0, true, 'got results');
93+
assert.equal(indexOfPageInResults('can-stache/keys/special', results), 0, 'first result is the can-stache/keys/special page');
94+
done();
95+
});
96+
});

0 commit comments

Comments
 (0)