Showing the changes to assets/javascripts (2 of 2 files). Show all
Unified · Split
| @@ -112,6 +112,25 @@ class app.Searcher · 111 unmodified lines | |||
| 112 | max_results: app.config.max_results | 112 | max_results: app.config.max_results |
| 113 | fuzzy_min_length: 3 | 113 | fuzzy_min_length: 3 |
| 114 | 114 | ||
| 115 | SEPARATORS_REGEXP = /\:?\ |#|::|->/g | ||
| 116 | PARANTHESES_REGEXP = /\(.*?\)$/ | ||
| 117 | EVENT_REGEXP = /\ event$/ | ||
| 118 | DOT_REGEXP = /\.+/g | ||
| 119 | WHITESPACE_REGEXP = /\s/g | ||
| 120 | |||
| 121 | EMPTY_STRING = '' | ||
| 122 | ELLIPSIS = '...' | ||
| 123 | |||
| 124 | @normalizeString: (string) -> | ||
| 125 | string | ||
| 126 | .toLowerCase() | ||
| 127 | .replace ELLIPSIS, EMPTY_STRING | ||
| 128 | .replace EVENT_REGEXP, EMPTY_STRING | ||
| 129 | .replace SEPARATORS_REGEXP, SEPARATOR | ||
| 130 | .replace DOT_REGEXP, SEPARATOR | ||
| 131 | .replace PARANTHESES_REGEXP, EMPTY_STRING | ||
| 132 | .replace WHITESPACE_REGEXP, EMPTY_STRING | ||
| 133 | |||
| 115 | constructor: (options = {}) -> | 134 | constructor: (options = {}) -> |
| 116 | @options = $.extend {}, DEFAULTS, options | 135 | @options = $.extend {}, DEFAULTS, options |
| 117 | 136 | ||
| @@ -127,7 +146,7 @@ class app.Searcher · 9 unmodified lines | |||
| 127 | return | 146 | return |
| 128 | 147 | ||
| 129 | setup: -> | 148 | setup: -> |
| 130 | query = @query = @normalizeQuery(@query) | 149 | query = @query = @constructor.normalizeString(@query) |
| 131 | queryLength = query.length | 150 | queryLength = query.length |
| 132 | @dataLength = @data.length | 151 | @dataLength = @data.length |
| 133 | @matchers = [exactMatch] | 152 | @matchers = [exactMatch] |
| @@ -231,9 +250,6 @@ class app.Searcher · 97 unmodified lines | |||
| 231 | delay: (fn) -> | 250 | delay: (fn) -> |
| 232 | @timeout = setTimeout(fn, 1) | 251 | @timeout = setTimeout(fn, 1) |
| 233 | 252 | ||
| 234 | normalizeQuery: (string) -> | ||
| 235 | string.replace(/\s/g, '').toLowerCase() | ||
| 236 | |||
| 237 | queryToFuzzyRegexp: (string) -> | 253 | queryToFuzzyRegexp: (string) -> |
| 238 | chars = string.split '' | 254 | chars = string.split '' |
| 239 | chars[i] = $.escapeRegexp(char) for char, i in chars | 255 | chars[i] = $.escapeRegexp(char) for char, i in chars |
| @@ -1,24 +1,11 @@ | |||
| 1 | #= require app/searcher | ||
| 2 | |||
| 1 | class app.models.Entry extends app.Model | 3 | class app.models.Entry extends app.Model |
| 2 | # Attributes: name, type, path | 4 | # Attributes: name, type, path |
| 3 | 5 | ||
| 4 | SEPARATORS_REGEXP = /\:?\ |#|::|->/g | ||
| 5 | PARANTHESES_REGEXP = /\(.*?\)$/ | ||
| 6 | EVENT_REGEXP = /\ event$/ | ||
| 7 | DOT_REGEXP = /\.+/g | ||
| 8 | |||
| 9 | constructor: -> | 6 | constructor: -> |
| 10 | super | 7 | super |
| 11 | @text = @searchValue() | 8 | @text = app.Searcher.normalizeString(@name) |
| 12 | |||
| 13 | searchValue: -> | ||
| 14 | @name | ||
| 15 | .toLowerCase() | ||
| 16 | .replace '...', ' ' | ||
| 17 | .replace EVENT_REGEXP, '' | ||
| 18 | .replace SEPARATORS_REGEXP, '.' | ||
| 19 | .replace DOT_REGEXP, '.' | ||
| 20 | .replace PARANTHESES_REGEXP, '' | ||
| 21 | .trim() | ||
| 22 | 9 | ||
| 23 | fullPath: -> | 10 | fullPath: -> |
| 24 | @doc.fullPath if @isIndex() then '' else @path | 11 | @doc.fullPath if @isIndex() then '' else @path |