Skip to content

Commit 115ffa8

Browse files
committed
Improve ranking of search results when multiple exact matches are found
1 parent ec0e9f0 commit 115ffa8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

assets/javascripts/app/searcher.coffee

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class app.Searcher
135135
#
136136

137137
index = # position of the query in the string being matched
138+
lastIndex = # last position of the query in the string being matched
138139
match = # regexp match data
139140
score = # score for the current match
140141
separators = # counter
@@ -144,6 +145,14 @@ class app.Searcher
144145
index = value.indexOf @query
145146
return unless index >= 0
146147

148+
lastIndex = value.lastIndexOf @query
149+
150+
if index isnt lastIndex
151+
Math.max(@scoreExactMatch(value, index), @scoreExactMatch(value, lastIndex))
152+
else
153+
@scoreExactMatch(value, index)
154+
155+
scoreExactMatch: (value, index) ->
147156
# Remove one point for each unmatched character.
148157
score = 100 - (value.length - @queryLength)
149158

0 commit comments

Comments
 (0)