Class: Queries::AssertedDistribution::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.
5
6
7
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 5
def initialize(string, project_id: nil)
super
end
|
Instance Method Details
#autocomplete ⇒ Array
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 119
def autocomplete
queries = [
autocomplete_matching_source,
autocomplete_matching_otu_name,
autocomplete_matching_taxon_name,
autocomplete_biological_association,
autocomplete_observation_otu_name,
autocomplete_observation_taxon_name,
autocomplete_conveyance_otu_name,
autocomplete_conveyance_taxon_name,
autocomplete_depiction_otu_name,
autocomplete_depiction_taxon_name,
autocomplete_matching_geographic_area,
autocomplete_matching_gazetteer,
autocomplete_biological_associations_graph,
]
queries = queries.compact
return [] if queries.empty?
updated_queries = []
queries.each_with_index do |q ,i|
a = q.where(asserted_distributions: {project_id:})
updated_queries[i] = a
end
result = []
updated_queries.each do |q|
result += q.to_a
result.uniq!
break if result.count > 50
end
result[0..50]
end
|
#autocomplete_biological_association ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 41
def autocomplete_biological_association
a = Queries::BiologicalAssociation::Autocomplete
.new(query_string, project_id: project_id).updated_queries
queries = a.map do |q|
::AssertedDistribution
.where(asserted_distribution_object_type: 'BiologicalAssociation')
.where(asserted_distribution_object_id: q.pluck(:id))
end
referenced_klass_union(queries)
end
|
#autocomplete_biological_associations_graph ⇒ Object
56
57
58
59
60
61
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 56
def autocomplete_biological_associations_graph
base_query
.with_biological_associations_graphs
.where( biological_associations_graph_table[:name].matches(query_string + '%') ).limit(20)
end
|
#autocomplete_conveyance_otu_name ⇒ Object
63
64
65
66
67
68
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 63
def autocomplete_conveyance_otu_name
base_query
.with_otu_conveyances
.joins('JOIN otus ON otus.id = conveyances.conveyance_object_id')
.where( otu_table[:name].matches(query_string + '%') ).limit(20)
end
|
#autocomplete_conveyance_taxon_name ⇒ Object
70
71
72
73
74
75
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 70
def autocomplete_conveyance_taxon_name
base_query
.with_otu_conveyances
.joins('JOIN otus ON otus.id = conveyances.conveyance_object_id JOIN taxon_names ON taxon_names.id = otus.taxon_name_id')
.where( taxon_name_table[:cached].matches(query_string + '%') ).limit(20)
end
|
#autocomplete_depiction_otu_name ⇒ Object
77
78
79
80
81
82
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 77
def autocomplete_depiction_otu_name
base_query
.with_otu_depictions
.joins('JOIN otus ON otus.id = depictions.depiction_object_id')
.where( otu_table[:name].matches(query_string + '%') ).limit(20)
end
|
#autocomplete_depiction_taxon_name ⇒ Object
84
85
86
87
88
89
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 84
def autocomplete_depiction_taxon_name
base_query
.with_otu_depictions
.joins('JOIN otus ON otus.id = depictions.depiction_object_id JOIN taxon_names ON taxon_names.id = otus.taxon_name_id')
.where( taxon_name_table[:cached].matches(query_string + '%') ).limit(20)
end
|
#autocomplete_matching_gazetteer ⇒ Object
109
110
111
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 109
def autocomplete_matching_gazetteer
base_query.joins("JOIN gazetteers ON asserted_distributions.asserted_distribution_shape_type = 'Gazetteer' AND asserted_distribution_shape_id = gazetteers.id").where( gazetteer_table[:name].matches(query_string + '%') ).limit(50)
end
|
#autocomplete_matching_geographic_area ⇒ Object
105
106
107
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 105
def autocomplete_matching_geographic_area
base_query.joins("JOIN geographic_areas ON asserted_distributions.asserted_distribution_shape_type = 'GeographicArea' AND asserted_distribution_shape_id = geographic_areas.id").where( geographic_area_table[:name].matches(query_string + '%') ).limit(50)
end
|
#autocomplete_matching_otu_name ⇒ Object
33
34
35
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 33
def autocomplete_matching_otu_name
base_query.with_otus.where( otu_table[:name].matches(query_string + '%') ).limit(20)
end
|
#autocomplete_matching_source ⇒ Object
114
115
116
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 114
def autocomplete_matching_source
base_query.joins(:sources).where( source_table[:cached].matches('%' + query_string + '%') ).limit(5)
end
|
#autocomplete_matching_taxon_name ⇒ Object
37
38
39
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 37
def autocomplete_matching_taxon_name
base_query.with_taxon_names.where( taxon_name_table[:cached].matches(query_string + '%') ).limit(20)
end
|
#autocomplete_observation_otu_name ⇒ Object
91
92
93
94
95
96
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 91
def autocomplete_observation_otu_name
base_query
.with_otu_observations
.joins('JOIN otus ON otus.id = observations.observation_object_id')
.where( otu_table[:name].matches(query_string + '%') ).limit(20)
end
|
#autocomplete_observation_taxon_name ⇒ Object
98
99
100
101
102
103
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 98
def autocomplete_observation_taxon_name
base_query
.with_otu_observations
.joins('JOIN otus ON otus.id = observations.observation_object_id JOIN taxon_names ON taxon_names.id = otus.taxon_name_id')
.where( taxon_name_table[:cached].matches(query_string + '%') ).limit(20)
end
|
#biological_associations_graph_table ⇒ Object
17
18
19
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 17
def biological_associations_graph_table
::BiologicalAssociationsGraph.arel_table
end
|
#gazetteer_table ⇒ Object
25
26
27
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 25
def gazetteer_table
::Gazetteer.arel_table
end
|
#geographic_area_table ⇒ Object
21
22
23
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 21
def geographic_area_table
::GeographicArea.arel_table
end
|
#otu_table ⇒ Object
9
10
11
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 9
def otu_table
::Otu.arel_table
end
|
#source_table ⇒ Object
29
30
31
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 29
def source_table
::Source.arel_table
end
|
#taxon_name_table ⇒ Object
13
14
15
|
# File 'lib/queries/asserted_distribution/autocomplete.rb', line 13
def taxon_name_table
::TaxonName.arel_table
end
|