Class: ObservationMatrixRow::Autocomplete

Inherits:
Queries::Query show all
Defined in:
lib/queries/observation_matrix_row/autocomplete.rb

Overview

A wrapper around Otu and CollectionObject filters

Instance Attribute Summary collapse

Attributes inherited from Queries::Query

#dynamic_limit, #options, #project_id, #query_string, #terms

Instance Method Summary collapse

Methods inherited from Queries::Query

#alphabetic_strings, #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_exact_id, #autocomplete_ordered_wildcard_pieces_in_cached, #autocomplete_start_date, #build_terms, #cached, #combine_or_clauses, #end_wildcard, #exactly_named, #fragments, #integers, #match_ordered_wildcard_pieces_in_cached, #match_wildcard_end_in_cached, #match_wildcard_in_cached, #named, #no_digits, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #pieces, #result, #scope, #simple_date, #start_and_end_wildcard, #start_wildcard, #wildcard_pieces, #wildcard_wrapped_integers, #wildcard_wrapped_years, #with_cached, #with_cached_like, #with_id, #with_project_id, #with_start_date, #year_letter, #years

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_idObject

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

#autocompleteArray

Returns TODO: optimize limits

Returns:

  • (Array)

    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