diff --git a/app/assets/javascripts/sitewide/atwho_res.js.erb b/app/assets/javascripts/sitewide/atwho_res.js.erb index ca14052fa..78a4f207e 100644 --- a/app/assets/javascripts/sitewide/atwho_res.js.erb +++ b/app/assets/javascripts/sitewide/atwho_res.js.erb @@ -352,7 +352,23 @@ var SmartAnnotation = (function() { }, beforeInsert: function(value, li) { return _generateInputTag(value, li); - } + }, + matcher:function(flag, subtext, should_startWithSpace, acceptSpaceBar) { + var _a, _y, match, regexp, space; + flag = flag.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + if (should_startWithSpace) { + flag = '(?:^|\\s)' + flag; + } + _a = decodeURI("%C3%80"); + _y = decodeURI("%C3%BF"); + regexp = new RegExp(flag + "([A-Za-z" + _a + "-" + _y + "0-9_\\s\+\-\]*)$|" + flag + "([^\\x00-\\xff]*)$", 'gi'); + match = regexp.exec(subtext); + if (match) { + return match[2] || match[1]; + } else { + return null; + } + }, }, headerTpl: generateFilterMenu(defaultFilterType), limit: <%= Constants::ATWHO_SEARCH_LIMIT %>, diff --git a/app/models/concerns/searchable_model.rb b/app/models/concerns/searchable_model.rb index 859739037..7d38bdbc0 100644 --- a/app/models/concerns/searchable_model.rb +++ b/app/models/concerns/searchable_model.rb @@ -21,17 +21,22 @@ module SearchableModel end if options[:whole_word].to_s == 'true' || - options[:whole_phrase].to_s == 'true' + options[:whole_phrase].to_s == 'true' || + options[:at_search].to_s == 'true' unless attrs.empty? like = options[:match_case].to_s == 'true' ? '~' : '~*' + like = 'SIMILAR TO' if options[:at_search].to_s == 'true' if options[:whole_word].to_s == 'true' a_query = query.split .map { |a| Regexp.escape(a) } .join('|') + elsif options[:at_search].to_s == 'true' + a_query = "%#{Regexp.escape(query).downcase}%" else a_query = Regexp.escape(query) end + # quick fix to enable searching by repositoy_row id id_index = { present: false } where_str = @@ -40,7 +45,8 @@ module SearchableModel id_index = { present: true, val: i } "(#{a}) = :t#{i} OR " else - "(trim_html_tags(#{a})) #{like} :t#{i} OR " + col = options[:at_search].to_s == 'true' ? "lower(#{a})": a + "(trim_html_tags(#{col})) #{like} :t#{i} OR " end end ).join[0..-5] @@ -53,7 +59,6 @@ module SearchableModel end end ).to_h - return where(where_str, vals) end end diff --git a/app/utilities/smart_annotation.rb b/app/utilities/smart_annotation.rb index b5f5eaf8f..6c35577ca 100644 --- a/app/utilities/smart_annotation.rb +++ b/app/utilities/smart_annotation.rb @@ -101,7 +101,7 @@ class SmartAnnotation def repository_rows(repository) res = RepositoryRow .where(repository: repository) - .where_attributes_like('name', @query) + .where_attributes_like('name', @query, at_search: true) .limit(Constants::ATWHO_SEARCH_LIMIT) rep_items_list = [] splitted_name = repository.name.gsub(/[^0-9a-z ]/i, '').split