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
135 #135 #
136 136
137 index = # position of the query in the string being matched137 index = # position of the query in the string being matched
138 lastIndex = # last position of the query in the string being matched
138 match = # regexp match data139 match = # regexp match data
139 score = # score for the current match140 score = # score for the current match
140 separators = # counter141 separators = # counter
@@ -144,6 +145,14 @@ class app.Searcher · 3 unmodified lines
144 index = value.indexOf @query145 index = value.indexOf @query
145 return unless index >= 0146 return unless index >= 0
146 147
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) ->
147 # Remove one point for each unmatched character.156 # Remove one point for each unmatched character.
148 score = 100 - (value.length - @queryLength)157 score = 100 - (value.length - @queryLength)
149 158