Skip to content

Commit e654e63

Browse files
authored
Merge pull request #364 from canjs/fix-search-results
Fix search results and keep them working in Safari
2 parents 1f59bb0 + 4f6041e commit e654e63

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

static/search.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ var Search = Control.extend({
320320
if (index && currentIndexVersion === indexVersion) {
321321
searchEngine = lunr.Index.load(index);
322322
}else{
323+
var dummyContainer = document.createElement('div');
323324
searchEngine = lunr(function(){
324325
lunr.tokenizer.separator = /[\s]+/;
325326

@@ -340,6 +341,10 @@ var Search = Control.extend({
340341
if(!item.title){
341342
item.title = item.name;
342343
}
344+
// Convert HTML to text
345+
dummyContainer.innerHTML = item.description;
346+
item.description = dummyContainer.innerText;
347+
343348
this.add(item);
344349
}
345350
}
@@ -379,6 +384,8 @@ var Search = Control.extend({
379384
var split = searchTerm.split(lunr.tokenizer.separator);
380385
split.forEach(function(term) {
381386
q.term(term, { boost: 10, fields: q.allFields });
387+
388+
q.term(term, { usePipeline: false, fields: q.allFields, wildcard: lunr.Query.wildcard.TRAILING });
382389
});
383390
});
384391

test/search.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ QUnit.module('search control');
2727
QUnit.test('Search for “about”', function(assert) {
2828
var done = assert.async();
2929
search.searchEngineSearch('about').then(function(results) {
30-
assert.equal(results.length > 0, true, 'got results');
30+
assert.equal(results.length > 1, true, 'got more than 1 result');
3131
assert.equal(indexOfPageInResults('about', results), 0, 'first result is the About page');
3232
done();
3333
});
@@ -36,7 +36,7 @@ QUnit.test('Search for “about”', function(assert) {
3636
QUnit.test('Search for “can-component”', function(assert) {
3737
var done = assert.async();
3838
search.searchEngineSearch('can-component').then(function(results) {
39-
assert.equal(results.length > 0, true, 'got results');
39+
assert.equal(results.length > 1, true, 'got more than 1 result');
4040
assert.equal(indexOfPageInResults('can-component', results), 0, 'first result is the can-component page');
4141
done();
4242
});
@@ -45,7 +45,7 @@ QUnit.test('Search for “can-component”', function(assert) {
4545
QUnit.test('Search for “can-connect”', function(assert) {
4646
var done = assert.async();
4747
search.searchEngineSearch('can-connect').then(function(results) {
48-
assert.equal(results.length > 0, true, 'got results');
48+
assert.equal(results.length > 1, true, 'got more than 1 result');
4949
assert.equal(indexOfPageInResults('can-connect', results), 0, 'first result is the can-connect page');
5050
done();
5151
});
@@ -54,15 +54,15 @@ QUnit.test('Search for “can-connect”', function(assert) {
5454
QUnit.test('Search for “helpers/', function(assert) {
5555
var done = assert.async();
5656
search.searchEngineSearch('helpers/').then(function(results) {
57-
assert.equal(results.length > 0, true, 'got results');
57+
assert.equal(results.length > 1, true, 'got more than 1 result');
5858
done();
5959
});
6060
});
6161

6262
QUnit.test('Search for “Live Binding”', function(assert) {
6363
var done = assert.async();
6464
search.searchEngineSearch('Live Binding').then(function(results) {
65-
assert.equal(results.length > 0, true, 'got results');
65+
assert.equal(results.length > 1, true, 'got more than 1 result');
6666
assert.equal(indexOfPageInResults('can-stache.Binding', results) < 2, true, 'first result is the can-stache Live Binding page');
6767
done();
6868
});
@@ -80,7 +80,7 @@ QUnit.test('Search for “Play”', function(assert) {
8080
QUnit.test('Search for “stache”', function(assert) {
8181
var done = assert.async();
8282
search.searchEngineSearch('stache').then(function(results) {
83-
assert.equal(results.length > 0, true, 'got results');
83+
assert.equal(results.length > 1, true, 'got more than 1 result');
8484
assert.equal(indexOfPageInResults('can-stache', results), 0, 'first result is the can-stache page');
8585
done();
8686
});
@@ -98,7 +98,7 @@ QUnit.test('Search for “%special”', function(assert) {
9898
QUnit.test('Search for “define/map”', function(assert) {
9999
var done = assert.async();
100100
search.searchEngineSearch('define/map').then(function(results) {
101-
assert.equal(results.length > 0, true, 'got results');
101+
assert.equal(results.length > 1, true, 'got more than 1 result');
102102
assert.equal(indexOfPageInResults('can-define/map/map', results), 0, 'first result is the can-define/map/map page');
103103
done();
104104
});

0 commit comments

Comments
 (0)