Class: Queries::TypeMaterial::Autocomplete

Inherits:
Query::Autocomplete show all
Defined in:
lib/queries/type_material/autocomplete.rb

Instance Attribute Summary

Attributes inherited from Query::Autocomplete

#dynamic_limit, #project_id, #query_string

Attributes inherited from Query

#query_string, #terms

Instance Method Summary collapse

Methods inherited from Query::Autocomplete

#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, #initialize, #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

This class inherits a constructor from Queries::Query::Autocomplete

Instance Method Details

#allScope

Returns:

  • (Scope)


11
12
13
# File 'lib/queries/type_material/autocomplete.rb', line 11

def all
  ::TypeMaterial.includes(:protonym, collection_object: [:identifiers] ).where(where_sql).references(:taxon_names).limit(dynamic_limit).all
end

#identifier_tableArel::Table

Returns:

  • (Arel::Table)


21
22
23
# File 'lib/queries/type_material/autocomplete.rb', line 21

def identifier_table
  ::Identifier.arel_table
end

#taxon_name_tableArel::Table

Returns:

  • (Arel::Table)


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

def taxon_name_table
  ::TaxonName.arel_table
end

#where_sqlString

Returns:

  • (String)


6
7
8
# File 'lib/queries/type_material/autocomplete.rb', line 6

def where_sql
  with_project_id.and(with_cached_taxon_name.or(with_cached_identifier)).to_sql
end

#with_cached_identifierArel::Nodes::Matches

Returns:

  • (Arel::Nodes::Matches)


32
33
34
# File 'lib/queries/type_material/autocomplete.rb', line 32

def with_cached_identifier
  identifier_table[:cached].matches_any(terms)
end

#with_cached_taxon_nameArel::Nodes::Matches

source, material, prototonym

Returns:

  • (Arel::Nodes::Matches)


27
28
29
# File 'lib/queries/type_material/autocomplete.rb', line 27

def with_cached_taxon_name
  taxon_name_table[:cached].matches_any(terms)
end