Skip to content

Commit

Permalink
Fixed olivernn#117
Browse files Browse the repository at this point in the history
Updated to add the actual reference instead of relying on the map's key.
  • Loading branch information
kkirby committed Nov 13, 2014
1 parent c7a85b6 commit 9364782
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,12 @@ lunr.Index.prototype.search = function (query) {
if (pos > -1) queryVector.insert(pos, tf * idf * similarityBoost)

// add all the documents that have this key into a set
Object.keys(self.tokenStore.get(key)).forEach(function (ref) { set.add(ref) })

var documents = self.tokenStore.get(key);
for(var ref in documents){
if(!documents.hasOwnProperty(ref))continue;
set.add(documents[ref].ref);
}

return memo.union(set)
}, new lunr.SortedSet)

Expand Down
11 changes: 11 additions & 0 deletions test/search_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ module('search', {
id: 'e',
title: 'title',
body: 'hand',
},{
id: 10,
title: 'ten',
body: 'ten 10'
}]).forEach(function (doc) { idx.add(doc) })

this.idx = idx
Expand Down Expand Up @@ -75,3 +79,10 @@ test('search boosts exact matches', function () {

ok(results[0].score > results[1].score)
})

test('returning the correct type for reference', function () {
var results = this.idx.search('ten');
equal(results.length, 1)
equal(typeof results[0].ref, 'number')
equal(results[0].ref, 10)
})

0 comments on commit 9364782

Please sign in to comment.