Class: Queries::FieldOccurrence::Autocomplete
- Inherits:
-
Query::Autocomplete
- Object
- Query
- Query::Autocomplete
- Queries::FieldOccurrence::Autocomplete
- Defined in:
- lib/queries/field_occurrence/autocomplete.rb
Instance Attribute Summary
Attributes inherited from Query::Autocomplete
#dynamic_limit, #project_id, #query_string
Attributes inherited from Query
Instance Method Summary collapse
-
#autocomplete ⇒ Array
TODO: optimize limits.
- #autocomplete_otu_determined_as ⇒ Object
- #autocomplete_taxon_name_determined_as ⇒ Object
- #base_queries ⇒ Object
-
#initialize(string, project_id: nil) ⇒ Autocomplete
constructor
A new instance of Autocomplete.
- #otu_table ⇒ Arel::Table
- #taxon_name_table ⇒ Arel::Table
Methods inherited from Query::Autocomplete
#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, #cached_facet, #combine_or_clauses, #common_name_name, #common_name_table, #common_name_wild_pieces, #exactly_named, #fragments, #integers, #least_levenshtein, #match_wildcard_end_in_cached, #match_wildcard_in_cached, #named, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #pieces, #scope, #string_fragments, #wildcard_wrapped_integers, #wildcard_wrapped_years, #with_cached, #with_cached_like, #with_id, #with_project_id, #year_letter, #years
Methods inherited from Query
#alphabetic_strings, #alphanumeric_strings, base_name, #base_name, #base_query, #build_terms, #cached_facet, #end_wildcard, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #no_terms?, referenced_klass, #referenced_klass, #referenced_klass_except, #referenced_klass_intersection, #referenced_klass_union, #start_and_end_wildcard, #start_wildcard, #table, #wildcard_pieces
Constructor Details
#initialize(string, project_id: nil) ⇒ Autocomplete
Returns a new instance of Autocomplete.
7 8 9 |
# File 'lib/queries/field_occurrence/autocomplete.rb', line 7 def initialize(string, project_id: nil) super end |
Instance Method Details
#autocomplete ⇒ Array
Returns TODO: optimize limits.
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/queries/field_occurrence/autocomplete.rb', line 66 def autocomplete updated_queries = base_queries result = [] updated_queries.each do |q| result += q.to_a result.uniq! break if result.count > 39 end result[0..39] end |
#autocomplete_otu_determined_as ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/queries/field_occurrence/autocomplete.rb', line 32 def autocomplete_otu_determined_as t = otu_table[:name].matches_any(terms) ::FieldOccurrence. joins(taxon_determinations: [:otu]). where(t.to_sql).references(:taxon_determinations, :otus). order('otus.name ASC').limit(10) end |
#autocomplete_taxon_name_determined_as ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/queries/field_occurrence/autocomplete.rb', line 21 def autocomplete_taxon_name_determined_as t = taxon_name_table[:name].matches_any(terms).or(taxon_name_table[:cached].matches_any(terms) ) ::FieldOccurrence. includes(:identifiers, taxon_determinations: [otu: :taxon_name]). joins(taxon_determinations: [:otu]). where(t.to_sql). references(:taxon_determinations, :otus, :taxon_names). order('otus.name ASC').limit(10) end |
#base_queries ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/queries/field_occurrence/autocomplete.rb', line 41 def base_queries queries = [ autocomplete_exact_id, autocomplete_identifier_cached_exact, autocomplete_identifier_identifier_exact, autocomplete_taxon_name_determined_as, autocomplete_otu_determined_as, autocomplete_identifier_cached_like, ] queries.compact! return [] if queries.nil? updated_queries = [] queries.each_with_index do |q ,i| a = q.where(project_id: project_id) if project_id.present? a ||= q updated_queries[i] = a end updated_queries end |
#otu_table ⇒ Arel::Table
17 18 19 |
# File 'lib/queries/field_occurrence/autocomplete.rb', line 17 def otu_table ::Otu.arel_table end |
#taxon_name_table ⇒ Arel::Table
12 13 14 |
# File 'lib/queries/field_occurrence/autocomplete.rb', line 12 def taxon_name_table ::TaxonName.arel_table end |