Normalize search values and search queries the same way

pull/165/head
Thibaut 10 years ago
parent ec9cb1004f
commit add213e0f4

@ -112,6 +112,25 @@ class app.Searcher
max_results: app.config.max_results max_results: app.config.max_results
fuzzy_min_length: 3 fuzzy_min_length: 3
SEPARATORS_REGEXP = /\:?\ |#|::|->/g
PARANTHESES_REGEXP = /\(.*?\)$/
EVENT_REGEXP = /\ event$/
DOT_REGEXP = /\.+/g
WHITESPACE_REGEXP = /\s/g
EMPTY_STRING = ''
ELLIPSIS = '...'
@normalizeString: (string) ->
string
.toLowerCase()
.replace ELLIPSIS, EMPTY_STRING
.replace EVENT_REGEXP, EMPTY_STRING
.replace SEPARATORS_REGEXP, SEPARATOR
.replace DOT_REGEXP, SEPARATOR
.replace PARANTHESES_REGEXP, EMPTY_STRING
.replace WHITESPACE_REGEXP, EMPTY_STRING
constructor: (options = {}) -> constructor: (options = {}) ->
@options = $.extend {}, DEFAULTS, options @options = $.extend {}, DEFAULTS, options
@ -127,7 +146,7 @@ class app.Searcher
return return
setup: -> setup: ->
query = @query = @normalizeQuery(@query) query = @query = @constructor.normalizeString(@query)
queryLength = query.length queryLength = query.length
@dataLength = @data.length @dataLength = @data.length
@matchers = [exactMatch] @matchers = [exactMatch]
@ -231,9 +250,6 @@ class app.Searcher
delay: (fn) -> delay: (fn) ->
@timeout = setTimeout(fn, 1) @timeout = setTimeout(fn, 1)
normalizeQuery: (string) ->
string.replace(/\s/g, '').toLowerCase()
queryToFuzzyRegexp: (string) -> queryToFuzzyRegexp: (string) ->
chars = string.split '' chars = string.split ''
chars[i] = $.escapeRegexp(char) for char, i in chars chars[i] = $.escapeRegexp(char) for char, i in chars

@ -1,24 +1,11 @@
#= require app/searcher
class app.models.Entry extends app.Model class app.models.Entry extends app.Model
# Attributes: name, type, path # Attributes: name, type, path
SEPARATORS_REGEXP = /\:?\ |#|::|->/g
PARANTHESES_REGEXP = /\(.*?\)$/
EVENT_REGEXP = /\ event$/
DOT_REGEXP = /\.+/g
constructor: -> constructor: ->
super super
@text = @searchValue() @text = app.Searcher.normalizeString(@name)
searchValue: ->
@name
.toLowerCase()
.replace '...', ' '
.replace EVENT_REGEXP, ''
.replace SEPARATORS_REGEXP, '.'
.replace DOT_REGEXP, '.'
.replace PARANTHESES_REGEXP, ''
.trim()
fullPath: -> fullPath: ->
@doc.fullPath if @isIndex() then '' else @path @doc.fullPath if @isIndex() then '' else @path

Loading…
Cancel
Save