Class: Queries::Note::Autocomplete
- Inherits:
-
Query
- Object
- Query
- Queries::Note::Autocomplete
show all
- Defined in:
- lib/queries/note/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.
6
7
8
|
# File 'lib/queries/note/autocomplete.rb', line 6
def initialize(string, project_id: nil)
super
end
|
Instance Method Details
#autocomplete ⇒ Array
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
79
80
|
# File 'lib/queries/note/autocomplete.rb', line 54
def autocomplete
queries = [
autocomplete_exact_note,
autocomplete_wildcard_end,
autocomplete_wildcard_wrapped,
autocomplete_ordered_wildcard_pieces,
autocomplete_wildcard_anywhere,
autocomplete_any_wildcard_anywhere
]
queries.compact!
updated_queries = []
queries.each_with_index do |q ,i|
a = q.where(with_project_id.to_sql) if project_id
a ||= q
updated_queries[i] = a
end
result = []
updated_queries.each do |q|
result += q.to_a
result.uniq!
break if result.count > 40
end
result[0..40]
end
|
#autocomplete_any_wildcard_anywhere ⇒ Object
46
47
48
49
50
51
|
# File 'lib/queries/note/autocomplete.rb', line 46
def autocomplete_any_wildcard_anywhere
b = fragments
return nil if b.empty?
a = table[:text].matches_any(b)
base_query.where(a.to_sql).limit(20)
end
|
#autocomplete_exact_note ⇒ ActiveRecord::Relation
16
17
18
19
|
# File 'lib/queries/note/autocomplete.rb', line 16
def autocomplete_exact_note
a = table[:text].eq(query_string)
base_query.where(a.to_sql).limit(20)
end
|
#autocomplete_ordered_wildcard_pieces ⇒ Arel::Nodes::Matches
34
35
36
37
|
# File 'lib/queries/note/autocomplete.rb', line 34
def autocomplete_ordered_wildcard_pieces
a = table[:text].matches(wildcard_pieces)
base_query.where(a.to_sql).limit(10)
end
|
#autocomplete_wildcard_anywhere ⇒ Object
39
40
41
42
43
44
|
# File 'lib/queries/note/autocomplete.rb', line 39
def autocomplete_wildcard_anywhere
b = fragments
return nil if b.empty?
a = table[:text].matches_all(b)
base_query.where(a.to_sql).limit(20)
end
|
#autocomplete_wildcard_end ⇒ ActiveRecord::Relation
22
23
24
25
|
# File 'lib/queries/note/autocomplete.rb', line 22
def autocomplete_wildcard_end
a = table[:text].matches(query_string + '%')
base_query.where(a.to_sql).limit(8)
end
|
#autocomplete_wildcard_wrapped ⇒ ActiveRecord::Relation
28
29
30
31
|
# File 'lib/queries/note/autocomplete.rb', line 28
def autocomplete_wildcard_wrapped
a = table[:text].matches('%' + query_string + '%')
base_query.where(a.to_sql).limit(5)
end
|
#base_query ⇒ Scope
11
12
13
|
# File 'lib/queries/note/autocomplete.rb', line 11
def base_query
::Note.select('notes.*')
end
|
#table ⇒ Arel::Table
83
84
85
|
# File 'lib/queries/note/autocomplete.rb', line 83
def table
::Note.arel_table
end
|