Class: Queries::AssertedEnvironment::Autocomplete
Constant Summary
collapse
- DEFAULT_LIMIT =
20
Query::Autocomplete::DELEGATED_DEPTH, Query::Autocomplete::DELEGATED_MINIMUM_LENGTH, Query::Autocomplete::LITERAL_RESTRICTION_MAX
Instance Attribute Summary
#delegated_results, #dynamic_limit, #limit, #project_id, #query_string, #restrict_to
Attributes inherited from Query
#query_string, #terms
Instance Method Summary
collapse
#apply_restriction, #asserted_object_autocomplete, #asserted_object_restriction, #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, #delegated_autocomplete, #exactly_named, #fragments, #integers, #least_levenshtein, #match_wildcard_end_in_cached, #match_wildcard_in_cached, #named, #only_ids, #only_integers?, #order_by_id_rank, #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, restrict_to: nil, limit: nil) ⇒ Autocomplete
Returns a new instance of Autocomplete.
7
8
9
|
# File 'lib/queries/asserted_environment/autocomplete.rb', line 7
def initialize(string, project_id: nil, restrict_to: nil, limit: nil)
super(string, project_id:, restrict_to:, limit:)
end
|
Instance Method Details
#autocomplete ⇒ Array
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/queries/asserted_environment/autocomplete.rb', line 52
def autocomplete
queries = %i[
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
]
result = []
queries.each do |m|
q = send(m)
next if q.nil?
q = q.where(project_id:) if project_id.present?
result += apply_restriction(q).to_a
result.uniq!
break if result.count >= limit
end
result.first(limit)
end
|
#autocomplete_collecting_event_object ⇒ Object
26
27
28
|
# File 'lib/queries/asserted_environment/autocomplete.rb', line 26
def autocomplete_collecting_event_object
autocomplete_object('CollectingEvent', ::Queries::CollectingEvent::Autocomplete)
end
|
#autocomplete_gazetteer_object ⇒ Object
34
35
36
|
# File 'lib/queries/asserted_environment/autocomplete.rb', line 34
def autocomplete_gazetteer_object
autocomplete_object('Gazetteer', ::Queries::Gazetteer::Autocomplete)
end
|
#autocomplete_object(object_type, object_autocomplete_class) ⇒ Scope?
41
42
43
44
45
46
47
48
49
|
# File 'lib/queries/asserted_environment/autocomplete.rb', line 41
def autocomplete_object(object_type, object_autocomplete_class)
return nil if query_string.length < 3
asserted_object_autocomplete(
object_type:,
object_autocomplete_class:,
object_association: :asserted_environment_object
)
end
|
#autocomplete_otu_object ⇒ Object
30
31
32
|
# File 'lib/queries/asserted_environment/autocomplete.rb', line 30
def autocomplete_otu_object
autocomplete_object('Otu', ::Queries::Otu::Autocomplete)
end
|
#autocomplete_uri_ends_with ⇒ Object
21
22
23
24
|
# File 'lib/queries/asserted_environment/autocomplete.rb', line 21
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
16
17
18
19
|
# File 'lib/queries/asserted_environment/autocomplete.rb', line 16
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
11
12
13
14
|
# File 'lib/queries/asserted_environment/autocomplete.rb', line 11
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
|