Class: Queries::Organization::Autocomplete
- Defined in:
- lib/queries/organization/autocomplete.rb
Instance Attribute Summary
Attributes inherited from Query
#dynamic_limit, #options, #project_id, #query_string, #terms
Instance Method Summary collapse
-
#autocomplete ⇒ Array
TODO: optimize limits.
- #autocomplete_name_wildcard_end ⇒ Object
- #base_query ⇒ Object
-
#initialize(string) ⇒ Autocomplete
constructor
A new instance of Autocomplete.
- #table ⇒ Arel::Table
Methods inherited from Query
#alphabetic_strings, #alphanumeric_strings, #attribute_exact_facet, #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_common_name_exact, #autocomplete_common_name_like, #autocomplete_exact_id, #autocomplete_exactly_named, #autocomplete_named, #autocomplete_ordered_wildcard_pieces_in_cached, #build_terms, #cached, #combine_or_clauses, #common_name_name, #common_name_table, #common_name_wild_pieces, #end_wildcard, #exactly_named, #fragments, #integers, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #match_wildcard_end_in_cached, #match_wildcard_in_cached, #named, #no_terms?, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #pieces, #result, #scope, #start_and_end_wildcard, #start_wildcard, #string_fragments, #wildcard_pieces, #wildcard_wrapped_integers, #wildcard_wrapped_years, #with_cached, #with_cached_like, #with_id, #with_project_id, #year_letter, #years
Constructor Details
#initialize(string) ⇒ Autocomplete
Returns a new instance of Autocomplete.
7 8 9 |
# File 'lib/queries/organization/autocomplete.rb', line 7 def initialize(string) super end |
Instance Method Details
#autocomplete ⇒ Array
Returns TODO: optimize limits.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/queries/organization/autocomplete.rb', line 22 def autocomplete queries = [ autocomplete_identifier_cached_like, autocomplete_name_wildcard_end ] queries.compact! return [] if queries.nil? result = [] queries.each do |q| result += q.to_a result.uniq! break if result.count > 39 end result[0..39] end |
#autocomplete_name_wildcard_end ⇒ Object
15 16 17 18 |
# File 'lib/queries/organization/autocomplete.rb', line 15 def autocomplete_name_wildcard_end return nil if query_string.length < 2 base_query.where( table[:name].matches(query_string + '%').to_sql).limit(20) end |
#base_query ⇒ Object
11 12 13 |
# File 'lib/queries/organization/autocomplete.rb', line 11 def base_query ::Organization.select('organizations.*') end |
#table ⇒ Arel::Table
42 43 44 |
# File 'lib/queries/organization/autocomplete.rb', line 42 def table ::Organization.arel_table end |