Class: Queries::AssertedEnvironment::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, #safe_integers, #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_environment/autocomplete.rb', line 5
def initialize(string, project_id: nil)
super
end
|
Instance Method Details
#autocomplete ⇒ Array
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/queries/asserted_environment/autocomplete.rb', line 78
def autocomplete
queries = updated_queries
result = []
queries.each do |q|
result += q.to_a
result.uniq!
break if result.count > 19
end
result[0..19]
end
|
#autocomplete_collecting_event_object ⇒ Object
Matching by ENVO term alone can't distinguish two assertions with the
same uri_label on different objects (see asserted_environment_tag), so
also let the object's own label reach its AssertedEnvironments - one
subquery per polymorphic type, each delegating to that object's own
(already comprehensive) Autocomplete class rather than reimplementing
a narrower match here.
31
32
33
34
35
36
|
# File 'lib/queries/asserted_environment/autocomplete.rb', line 31
def autocomplete_collecting_event_object
return nil if query_string.length < 3
ids = ::Queries::CollectingEvent::Autocomplete.new(query_string, project_id:).autocomplete.map(&:id)
return nil if ids.empty?
base_query.where(asserted_environment_object_type: 'CollectingEvent', asserted_environment_object_id: ids)
end
|
#autocomplete_gazetteer_object ⇒ Object
45
46
47
48
49
50
|
# File 'lib/queries/asserted_environment/autocomplete.rb', line 45
def autocomplete_gazetteer_object
return nil if query_string.length < 3
ids = ::Queries::Gazetteer::Autocomplete.new(query_string, project_id:).autocomplete.map(&:id)
return nil if ids.empty?
base_query.where(asserted_environment_object_type: 'Gazetteer', asserted_environment_object_id: ids)
end
|
#autocomplete_otu_object ⇒ Object
38
39
40
41
42
43
|
# File 'lib/queries/asserted_environment/autocomplete.rb', line 38
def autocomplete_otu_object
return nil if query_string.length < 3
ids = ::Queries::Otu::Autocomplete.new(query_string, project_id:).autocomplete.map(&:id)
return nil if ids.empty?
base_query.where(asserted_environment_object_type: 'Otu', asserted_environment_object_id: ids)
end
|
#autocomplete_uri_ends_with ⇒ Object
19
20
21
22
|
# File 'lib/queries/asserted_environment/autocomplete.rb', line 19
def autocomplete_uri_ends_with
return nil if query_string.length < 3
base_query.where('asserted_environments.uri ILIKE ?', '%' + query_string).limit(20)
end
|
#autocomplete_uri_exact ⇒ Object
14
15
16
17
|
# File 'lib/queries/asserted_environment/autocomplete.rb', line 14
def autocomplete_uri_exact
return nil if query_string.length < 10
base_query.where(uri: query_string).limit(20)
end
|
#autocomplete_uri_label_contains_match ⇒ Object
9
10
11
12
|
# File 'lib/queries/asserted_environment/autocomplete.rb', line 9
def autocomplete_uri_label_contains_match
return nil if query_string.length < 3
base_query.where('asserted_environments.uri_label ILIKE ?', '%' + query_string + '%').limit(20)
end
|
#updated_queries ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/queries/asserted_environment/autocomplete.rb', line 52
def updated_queries
queries = [
autocomplete_exact_id,
autocomplete_uri_label_contains_match,
autocomplete_uri_exact,
autocomplete_uri_ends_with,
autocomplete_collecting_event_object,
autocomplete_otu_object,
autocomplete_gazetteer_object
]
queries.compact!
return [] if queries.empty?
project_queries = []
queries.each do |q|
a = project_id.present? ? q.where(project_id:) : q
project_queries.push a
end
project_queries
end
|