diff --git a/dist/ratchet.js b/dist/ratchet.js index b7c4c08..c8fa272 100644 --- a/dist/ratchet.js +++ b/dist/ratchet.js @@ -765,7 +765,7 @@ }(); /* ---------------------------------- - * lunr v0.2.1 + * lunr v0.2.2 * http://lunrjs.com - A bit like Solr, but much smaller and not as bright * Copyright (C) 2013 Oliver Nightingale * Licensed under The MIT License @@ -782,7 +782,7 @@ var lunr = function (config) { return idx } -lunr.version = "0.2.1" +lunr.version = "0.2.2" if (typeof module !== 'undefined') { module.exports = lunr @@ -960,19 +960,19 @@ lunr.SortedSet.prototype.intersect = function (otherSet) { if (a[i] === b[j]) { intersectSet.add(a[i]); - i++; + i++; j++; - continue + continue; } if (a[i] < b[j]) { - i++ - continue + i++; + continue; } if (a[i] > b[j]) { - j++ - continue + j++; + continue; } }; @@ -1102,10 +1102,15 @@ lunr.Index.prototype.search = function (query) { var set = this.tokenStore.expand(token).reduce(function (memo, key) { var pos = self.corpusTokens.indexOf(key), idf = self.idf(key), + exactMatchBoost = (key === token ? 10 : 1), set = new lunr.SortedSet - if (pos > -1) queryArr[pos] = tf * idf + // calculate the query tf-idf score for this token + // applying an exactMatchBoost to ensure these rank + // higher than expanded terms + if (pos > -1) queryArr[pos] = tf * idf * exactMatchBoost + // add all the documents that have this key into a set Object.keys(self.tokenStore.get(key)).forEach(function (ref) { set.add(ref) }) return memo.union(set) diff --git a/lib/js/lunr.js b/lib/js/lunr.js index ce0c57c..b50d79f 100644 --- a/lib/js/lunr.js +++ b/lib/js/lunr.js @@ -1,5 +1,5 @@ /* ---------------------------------- - * lunr v0.2.1 + * lunr v0.2.2 * http://lunrjs.com - A bit like Solr, but much smaller and not as bright * Copyright (C) 2013 Oliver Nightingale * Licensed under The MIT License @@ -16,7 +16,7 @@ var lunr = function (config) { return idx } -lunr.version = "0.2.1" +lunr.version = "0.2.2" if (typeof module !== 'undefined') { module.exports = lunr @@ -370,9 +370,8 @@ lunr.SortedSet.prototype.intersect = function (otherSet) { if (i > a_len - 1 || j > b_len - 1) break if (a[i] === b[j]) { - intersectSet.add(a[i]); - i++; - j++; + intersectSet.add(a[i]) + i++, j++ continue } @@ -417,11 +416,9 @@ lunr.SortedSet.prototype.union = function (otherSet) { var longSet, shortSet, unionSet if (this.length >= otherSet.length) { - longSet = this; - shortSet = otherSet; + longSet = this, shortSet = otherSet } else { - longSet = otherSet; - shortSet = this; + longSet = otherSet, shortSet = this } unionSet = longSet.clone() @@ -633,10 +630,15 @@ lunr.Index.prototype.search = function (query) { var set = this.tokenStore.expand(token).reduce(function (memo, key) { var pos = self.corpusTokens.indexOf(key), idf = self.idf(key), + exactMatchBoost = (key === token ? 10 : 1), set = new lunr.SortedSet - if (pos > -1) queryArr[pos] = tf * idf + // calculate the query tf-idf score for this token + // applying an exactMatchBoost to ensure these rank + // higher than expanded terms + if (pos > -1) queryArr[pos] = tf * idf * exactMatchBoost + // add all the documents that have this key into a set Object.keys(self.tokenStore.get(key)).forEach(function (ref) { set.add(ref) }) return memo.union(set) diff --git a/submodules/lunrjs b/submodules/lunrjs index 5bcfe57..269e4ad 160000 --- a/submodules/lunrjs +++ b/submodules/lunrjs @@ -1 +1 @@ -Subproject commit 5bcfe579a8fe72dab7fbb1f179e9ca0d5ea6df6d +Subproject commit 269e4ad5b66d8481f9fce67ec485f1f4a09ffc4e