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, #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.
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.
76
77
78
79
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
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 76
def autocomplete
return [] if query_string.blank?
queries = [
autocomplete_exact_id,
autocomplete_verbatim_label_md5,
autocomplete_identifier_identifier_exact,
autocomplete_identifier_cached_exact,
autocomplete_identifier_cached_like.limit(4),
autocomplete_verbatim_field_number_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:) 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
20
21
22
23
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 20
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
25
26
27
28
29
30
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 25
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
36
37
38
39
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 36
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
46
47
48
49
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 46
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_field_number_match ⇒ Object
32
33
34
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 32
def autocomplete_verbatim_field_number_match
base_query.where( table[:verbatim_field_number].matches(end_wildcard).to_sql).limit(20)
end
|
#autocomplete_verbatim_habitat ⇒ Object
51
52
53
54
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 51
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
14
15
16
17
18
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 14
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
56
57
58
59
60
61
62
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 56
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
41
42
43
44
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 41
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
64
65
66
67
68
69
70
71
72
|
# File 'lib/queries/collecting_event/autocomplete.rb', line 64
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].in(a).
and( table[:verbatim_locality].matches(string_fragments.join))
.to_sql)
.limit(20)
end
|