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 | 112 | max_results: app.config.max_results |
| 113 | 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 | 134 | constructor: (options = {}) -> |
| 116 | 135 | @options = $.extend {}, DEFAULTS, options |
| 117 | 136 | |
| @@ -127,7 +146,7 @@ class app.Searcher · 9 unmodified lines | ||
| 127 | 146 | return |
| 128 | 147 | |
| 129 | 148 | setup: -> |
| 130 | − query = @query = @normalizeQuery(@query) | |
| 149 | + query = @query = @constructor.normalizeString(@query) | |
| 131 | 150 | queryLength = query.length |
| 132 | 151 | @dataLength = @data.length |
| 133 | 152 | @matchers = [exactMatch] |
| @@ -231,9 +250,6 @@ class app.Searcher · 97 unmodified lines | ||
| 231 | 250 | delay: (fn) -> |
| 232 | 251 | @timeout = setTimeout(fn, 1) |
| 233 | 252 | |
| 234 | − normalizeQuery: (string) -> | |
| 235 | − string.replace(/\s/g, '').toLowerCase() | |
| 236 | − | |
| 237 | 253 | queryToFuzzyRegexp: (string) -> |
| 238 | 254 | chars = string.split '' |
| 239 | 255 | chars[i] = $.escapeRegexp(char) for char, i in chars |
| @@ -1,24 +1,11 @@ | ||
| 1 | +#= require app/searcher | |
| 2 | + | |
| 1 | 3 | class app.models.Entry extends app.Model |
| 2 | 4 | # Attributes: name, type, path |
| 3 | 5 | |
| 4 | − SEPARATORS_REGEXP = /\:?\ |#|::|->/g | |
| 5 | − PARANTHESES_REGEXP = /\(.*?\)$/ | |
| 6 | − EVENT_REGEXP = /\ event$/ | |
| 7 | − DOT_REGEXP = /\.+/g | |
| 8 | − | |
| 9 | 6 | constructor: -> |
| 10 | 7 | super |
| 11 | − @text = @searchValue() | |
| 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() | |
| 8 | + @text = app.Searcher.normalizeString(@name) | |
| 22 | 9 | |
| 23 | 10 | fullPath: -> |
| 24 | 11 | @doc.fullPath if @isIndex() then '' else @path |