Class: Queries::TaxonNameAutocompleteQuery

Inherits:
Query
  • Object
show all
Defined in:
lib/queries/taxon_name_autocomplete_query.rb

Instance Attribute Summary

Attributes inherited from Query

#dynamic_limit, #project_id, #query_string, #terms

Instance Method Summary (collapse)

Methods inherited from Query

#build_terms, #end_wildcard, #fragments, #identifier_table, #initialize, #integers, #named, #no_digits, #only_ids, #only_integers?, #parent, #parent_child_join, #result, #scope, #start_and_end_wildcard, #start_wildcard, #strings, #wildcard_wrapped_integers, #with_id, #with_identifier_like, #with_project_id, #years

Constructor Details

This class inherits a constructor from Queries::Query

Instance Method Details

- (Object) all



9
10
11
12
13
14
# File 'lib/queries/taxon_name_autocomplete_query.rb', line 9

def all 
 a = TaxonName.where(with_project_id.to_sql).where(['name = ?', query_string]).order(:name).all +
 b = TaxonName.joins(parent_child_join).where(with_project_id.to_sql).where(parent_child_where.to_sql).limit(3).order(:name).all       
 c = TaxonName.where(where_sql).limit(dynamic_limit).order(:cached).all
 (a + b + c).uniq
end

- (Object) parent_child_where

Note this overwrites the commonly used Geo parent/child!



37
38
39
40
41
# File 'lib/queries/taxon_name_autocomplete_query.rb', line 37

def parent_child_where
  b,a = query_string.split(/\s+/, 2)
  return table[:id].eq('-1') if a.nil? || b.nil?
  table[:name].matches("#{a}%").and(parent[:name].matches("#{b}%"))
end

- (Object) table



16
17
18
# File 'lib/queries/taxon_name_autocomplete_query.rb', line 16

def table
  TaxonName.arel_table
end

- (Object) where_sql



5
6
7
# File 'lib/queries/taxon_name_autocomplete_query.rb', line 5

def where_sql
  with_project_id.and(named.or(with_cached).or(with_verbatim_author).or(with_year_of_publication)).to_sql
end

- (Object) with_cached



20
21
22
# File 'lib/queries/taxon_name_autocomplete_query.rb', line 20

def with_cached
  table[:cached].matches_any(terms)
end

- (Object) with_verbatim_author



24
25
26
# File 'lib/queries/taxon_name_autocomplete_query.rb', line 24

def with_verbatim_author
  table[:verbatim_author].matches_any(terms)
end

- (Object) with_year_of_publication



28
29
30
31
32
33
34
# File 'lib/queries/taxon_name_autocomplete_query.rb', line 28

def with_year_of_publication
  if integers.any?
    table[:year_of_publication].eq_any(integers)
  else
    table[:id].eq(-1)
  end
end