Class: Queries::CollectingEvent::Autocomplete
- Inherits:
-
Query::Autocomplete
show all
- Includes:
- Queries::Concerns::DateRanges, Queries::Concerns::Roles
- Defined in:
- lib/queries/collecting_event/autocomplete.rb
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, #combine_or_clauses, #common_name_name, #common_name_table, #common_name_wild_pieces, #exactly_named, #fragments, #integers, #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, #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_union, #start_and_end_wildcard, #start_wildcard, #table, #wildcard_pieces
Constructor Details
#initialize(string, project_id: nil) ⇒ Autocomplete
Returns a new instance of Autocomplete.
10
11
12
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 10
def initialize(string, project_id: nil)
super
end
|
Instance Method Details
#autocomplete ⇒ Array
Returns TODO: optimize limits.
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 80
def autocomplete
queries = [
autocomplete_exact_id,
autocomplete_verbatim_label_md5,
autocomplete_identifier_identifier_exact,
autocomplete_identifier_cached_exact,
autocomplete_identifier_cached_like.limit(4),
autocomplete_verbatim_trip_identifier_match,
autocomplete_start_or_end_date,
autocomplete_start_date_wild_card(:verbatim_locality),
autocomplete_start_date_wild_card(:cached),
autocomplete_matching_collectors,
autocomplete_verbatim_latitude_or_longitude,
autocomplete_verbatim_collectors_wildcard,
autocomplete_verbatim_date,
autocomplete_verbatim_habitat,
autocomplete_verbatim_locality_wildcard_end,
autocomplete_verbatim_locality_wildcard_end_starting_year,
autocomplete_cached_wildcard_anywhere&.limit(20),
]
queries.compact!
return [] if queries.empty?
updated_queries = []
queries.each_with_index do |q ,i|
a = q.where(project_id: project_id) if project_id.present?
a ||= q
updated_queries[i] = a
end
result = []
updated_queries.each do |q|
result += q.to_a
result.uniq!
break if result.count > 29
end
result[0..39]
end
|
#autocomplete_matching_collectors ⇒ Object
24
25
26
27
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 24
def autocomplete_matching_collectors
return nil if no_terms?
matching_person_cached(:collector).limit(20)
end
|
#autocomplete_start_date_wild_card(field = :verbatim_locality) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 29
def autocomplete_start_date_wild_card(field = :verbatim_locality)
a = with_start_date
b = string_fragments
return nil if a.nil? || b.empty? || field.nil?
base_query.where( a.and(table[field].matches(b.join)).to_sql).limit(20)
end
|
#autocomplete_verbatim_collectors_wildcard ⇒ Object
40
41
42
43
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 40
def autocomplete_verbatim_collectors_wildcard
return nil if query_string.length < 4
base_query.where( table[:verbatim_collectors].matches(start_and_end_wildcard).to_sql).limit(20)
end
|
#autocomplete_verbatim_date ⇒ Object
50
51
52
53
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 50
def autocomplete_verbatim_date
return nil if query_string.length < 4
base_query.where( table[:verbatim_date].matches(start_and_end_wildcard).to_sql).limit(20)
end
|
#autocomplete_verbatim_habitat ⇒ Object
55
56
57
58
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 55
def autocomplete_verbatim_habitat
return nil if query_string.length < 4
base_query.where( table[:verbatim_habitat].matches(start_and_end_wildcard).to_sql).limit(20)
end
|
#autocomplete_verbatim_label_md5 ⇒ Object
18
19
20
21
22
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 18
def autocomplete_verbatim_label_md5
return nil if query_string.to_s.length < 4
md5 = Utilities::Strings.generate_md5(query_string)
base_query.where( table[:md5_of_verbatim_label].eq(md5)).limit(3)
end
|
#autocomplete_verbatim_latitude_or_longitude ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 60
def autocomplete_verbatim_latitude_or_longitude
return nil if query_string.nil?
base_query.where(
table[:verbatim_latitude].matches(start_and_end_wildcard)
.or(table[:verbatim_longitude].matches(start_and_end_wildcard)).to_sql
).limit(20)
end
|
#autocomplete_verbatim_locality_wildcard_end ⇒ Object
45
46
47
48
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 45
def autocomplete_verbatim_locality_wildcard_end
return nil if query_string.length < 4
base_query.where( table[:verbatim_locality].matches(end_wildcard).to_sql).limit(20)
end
|
#autocomplete_verbatim_locality_wildcard_end_starting_year ⇒ Object
68
69
70
71
72
73
74
75
76
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 68
def autocomplete_verbatim_locality_wildcard_end_starting_year
a = years
return nil if query_string.length < 7 || a.empty?
base_query.where(
table[:start_date_year].eq_any(a).
and( table[:verbatim_locality].matches(string_fragments.join))
.to_sql)
.limit(20)
end
|
#autocomplete_verbatim_trip_identifier_match ⇒ Object
36
37
38
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 36
def autocomplete_verbatim_trip_identifier_match
base_query.where( table[:verbatim_trip_identifier].matches(end_wildcard).to_sql).limit(20)
end
|
#base_query ⇒ Object
14
15
16
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 14
def base_query
::CollectingEvent.select('collecting_events.*')
end
|