Skip to content

Commit

Permalink
fix ranking algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasb committed Apr 10, 2012
1 parent 6be4f61 commit 8e20171
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/completion.js
Expand Up @@ -61,13 +61,12 @@ var completion = (function() {
str = self.normalize(str);
var sum = 0;
// only iterate over slices of the query starting at an offset up to 10 to save resources
for (var start = 0; start < 20; ++start) {
for (var start = 0; start < 20 && start < query.length; ++start) {
for (var i = query.length; i >= start; --i) {
if (str.indexOf(query.slice(start, i)) >= 0) {
sum += i - start;
sum += (i - start) * (i - start);
break;
}

}
}
return sum * sum * sum;
Expand Down Expand Up @@ -256,7 +255,7 @@ var completion = (function() {
refresh: function() { },

calculateRelevancy: function(query, match) {
return match.url.length * 10 /
return match.url.length /
(fuzzyMatcher.calculateRelevancy(query, this.extractStringFromMatch(match)) + 1);
},

Expand Down

0 comments on commit 8e20171

Please sign in to comment.