History

Improve ranking of search results when multiple exact matches are found

Thibaut committed 12 years ago

Commit 115ffa81 parent ec0e9f01 file · +9 −0Browse files

Unified · Split

assets/javascripts/app/searcher.coffee+9−0
@@ -135,6 +135,7 @@ class app.Searcher · 134 unmodified lines
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 · 3 unmodified lines
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