Class: Queries::Sound::Autocomplete
Instance Attribute Summary
#dynamic_limit, #project_id, #query_string
Attributes inherited from Query
#query_string, #terms
Instance Method Summary
collapse
#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.
6
7
8
|
# File 'lib/queries/sound/autocomplete.rb', line 6
def initialize(string, project_id: nil)
super
end
|
Instance Method Details
#autocomplete ⇒ Array
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/queries/sound/autocomplete.rb', line 35
def autocomplete
queries = updated_queries
result = []
updated_queries.each do |q|
result += q.to_a
result.uniq!
break if result.count > 19
end
result[0..40]
end
|
#autocomplete_conveying_otu_by_otu_name ⇒ Object
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/queries/sound/autocomplete.rb', line 48
def autocomplete_conveying_otu_by_otu_name
o = ::Otu.arel_table[:name].matches_any(terms)
::Sound.
includes(:otus).
joins(:otus).
where(o.to_sql).
references(:conveyances, :otus).
order('otus.name ASC').limit(20)
end
|
#autocomplete_conveying_otu_by_taxon_name ⇒ Object
59
60
61
62
63
64
65
66
67
|
# File 'lib/queries/sound/autocomplete.rb', line 59
def autocomplete_conveying_otu_by_taxon_name
o = ::TaxonName.arel_table[:cached].matches_any(terms)
::Sound
.with_taxon_names
.where(o.to_sql)
.order('taxon_names.cached ASC')
.limit(20)
end
|
#autocomplete_name_ilike ⇒ Object
69
70
71
72
73
74
|
# File 'lib/queries/sound/autocomplete.rb', line 69
def autocomplete_name_ilike
::Sound
.where(named)
.order(:name)
.limit(20)
end
|
#updated_queries ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/queries/sound/autocomplete.rb', line 10
def updated_queries
queries = [
autocomplete_exact_id,
autocomplete_identifier_identifier_exact,
autocomplete_identifier_cached_like,
autocomplete_name_ilike,
autocomplete_conveying_otu_by_otu_name,
autocomplete_conveying_otu_by_taxon_name
]
queries.compact!
return [] if queries.empty?
updated_queries = []
queries.each do |q|
a = q.where(project_id:) if project_id.present?
updated_queries.push a
end
updated_queries
end
|