Class: Queries::Loan::Autocomplete
- Inherits:
-
Query
- Object
- Query
- Queries::Loan::Autocomplete
show all
- Defined in:
- lib/queries/loan/autocomplete.rb
Instance Attribute Summary
Attributes inherited from Query
#dynamic_limit, #options, #project_id, #query_string, #terms
Instance Method Summary
collapse
Methods inherited from Query
#alphabetic_strings, #alphanumeric_strings, #attribute_exact_facet, #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, #build_terms, #cached, #combine_or_clauses, #common_name_name, #common_name_table, #common_name_wild_pieces, #end_wildcard, #exactly_named, #fragments, #integers, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #match_wildcard_end_in_cached, #match_wildcard_in_cached, #named, #no_terms?, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #pieces, #result, #scope, #start_and_end_wildcard, #start_wildcard, #string_fragments, #wildcard_pieces, #wildcard_wrapped_integers, #wildcard_wrapped_years, #with_cached, #with_cached_like, #with_id, #with_project_id, #year_letter, #years
Constructor Details
#initialize(string, project_id: nil) ⇒ Autocomplete
Returns a new instance of Autocomplete.
7
8
9
|
# File 'lib/queries/loan/autocomplete.rb', line 7
def initialize(string, project_id: nil)
super
end
|
Instance Method Details
#autocomplete ⇒ Array
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/queries/loan/autocomplete.rb', line 17
def autocomplete
return [] if query_string.blank?
queries = [
autocomplete_recipient_email,
autocomplete_exact_date_sent,
autocomplete_exact_date_requested,
autocomplete_exact_date_received,
autocomplete_exact_id,
autocomplete_identifier_identifier_exact,
autocomplete_identifier_cached_like,
autocomplete_identifier_matching_cached_fragments_anywhere,
autocomplete_by_role
]
queries.compact!
updated_queries = []
queries.each_with_index do |q,i|
a = q
a = q.where(project_id: project_id) if project_id
updated_queries[i] = a
end
result = []
updated_queries.each do |q|
result += q.to_a
result.uniq!
break if result.count > 19
end
result[0..40]
end
|
#autocomplete_by_role ⇒ Object
70
71
72
73
74
|
# File 'lib/queries/loan/autocomplete.rb', line 70
def autocomplete_by_role
r = ::Person.arel_table
o = r[:cached].matches('%' + query_string + '%')
::Loan.joins(:people).where(roles: { type: ['LoanRecipient', 'LoanSupervisor']}).where(o.to_sql)
end
|
#autocomplete_exact_date_received ⇒ Object
65
66
67
68
|
# File 'lib/queries/loan/autocomplete.rb', line 65
def autocomplete_exact_date_received
o = table[:date_received].eq(query_string)
::Loan.where(o.to_sql)
end
|
#autocomplete_exact_date_requested ⇒ Object
60
61
62
63
|
# File 'lib/queries/loan/autocomplete.rb', line 60
def autocomplete_exact_date_requested
o = table[:date_requested].eq(query_string)
::Loan.where(o.to_sql)
end
|
#autocomplete_exact_date_sent ⇒ Object
55
56
57
58
|
# File 'lib/queries/loan/autocomplete.rb', line 55
def autocomplete_exact_date_sent
o = table[:date_sent].eq(query_string)
::Loan.where(o.to_sql)
end
|
#autocomplete_recipient_email ⇒ Object
50
51
52
53
|
# File 'lib/queries/loan/autocomplete.rb', line 50
def autocomplete_recipient_email
o = table[:recipient_email].matches('%' + query_string + '%')
::Loan.where(o.to_sql)
end
|
#base_query ⇒ Scope
77
78
79
|
# File 'lib/queries/loan/autocomplete.rb', line 77
def base_query
::Loan.select('loans.*')
end
|
#table ⇒ Arel::Table
82
83
84
|
# File 'lib/queries/loan/autocomplete.rb', line 82
def table
::Loan.arel_table
end
|
#where_sql ⇒ String
12
13
14
|
# File 'lib/queries/loan/autocomplete.rb', line 12
def where_sql
with_project_id.and(or_and).to_sql
end
|