Class: Queries::ObservationMatrixRow::Autocomplete
- Inherits:
-
Query::Autocomplete
- Object
- Query
- Query::Autocomplete
- Queries::ObservationMatrixRow::Autocomplete
- Defined in:
- lib/queries/observation_matrix_row/autocomplete.rb
Overview
A wrapper around Otu and CollectionObject filters
Instance Attribute Summary collapse
-
#observation_matrix_id ⇒ Object
Returns the value of attribute observation_matrix_id.
Attributes inherited from Query::Autocomplete
#dynamic_limit, #project_id, #query_string
Attributes inherited from Query
Instance Method Summary collapse
-
#autocomplete ⇒ Array
TODO: optimize limits.
-
#initialize(string, project_id: nil, observation_matrix_id: nil) ⇒ Autocomplete
constructor
A new instance of Autocomplete.
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, #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, observation_matrix_id: nil) ⇒ Autocomplete
Returns a new instance of Autocomplete.
8 9 10 11 |
# File 'lib/queries/observation_matrix_row/autocomplete.rb', line 8 def initialize(string, project_id: nil, observation_matrix_id: nil) super @observation_matrix_id = observation_matrix_id end |
Instance Attribute Details
#observation_matrix_id ⇒ Object
Returns the value of attribute observation_matrix_id.
6 7 8 |
# File 'lib/queries/observation_matrix_row/autocomplete.rb', line 6 def observation_matrix_id @observation_matrix_id end |
Instance Method Details
#autocomplete ⇒ Array
Returns TODO: optimize limits.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/queries/observation_matrix_row/autocomplete.rb', line 15 def autocomplete a = Queries::Otu::Autocomplete.new(query_string, project_id: project_id).base_queries b = Queries::CollectionObject::Autocomplete.new(query_string, project_id: project_id).base_queries return [] if a.nil? && b.nil? updated_queries = [] a.each do |q| j = ::ObservationMatrixRow.joins(:otu).where(otu: q.limit(50).pluck(:id)).order('observation_matrix_rows.position') c = j.where(observation_matrix_id: observation_matrix_id) if observation_matrix_id c ||= j updated_queries.push c end b.each do |q| j = ::ObservationMatrixRow.joins(:collection_object).where(otu: q.limit(50).pluck(:id)).order('observation_matrix_rows.position') c = j.where(observation_matrix_id: observation_matrix_id) if observation_matrix_id c ||= j updated_queries.push c end result = [] updated_queries.each do |q| result += q.to_a result.uniq! break if result.count > 50 end result[0..49] end |