Class: Repository::Autocomplete
- Inherits:
-
Queries::Query
show all
- Includes:
- Queries::Concerns::AlternateValues
- Defined in:
- lib/queries/repository/autocomplete.rb
Instance Attribute Summary
#dynamic_limit, #options, #project_id, #query_string, #terms
Instance Method Summary
collapse
#alphabetic_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, #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, params = {}) ⇒ Autocomplete
Returns a new instance of Autocomplete.
8
9
10
11
12
|
# File 'lib/queries/repository/autocomplete.rb', line 8
def initialize(string, params = {})
set_identifier(params)
set_alternate_value(params)
super
end
|
Instance Method Details
#autocomplete ⇒ Array
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/queries/repository/autocomplete.rb', line 34
def autocomplete
return [] if query_string.blank?
queries = [
autocomplete_acronym_match,
autocomplete_exact_id,
autocomplete_exactly_named,
autocomplete_identifier_identifier_exact,
autocomplete_named,
autocomplete_alternate_values_acronym,
autocomplete_alternate_values_name
]
queries.compact!
result = []
queries.each do |q|
result += q.to_a
result.uniq!
break if result.count > 19
end
result[0..19]
end
|
#autocomplete_acronym_match ⇒ Scope
19
20
21
22
23
|
# File 'lib/queries/repository/autocomplete.rb', line 19
def autocomplete_acronym_match
base_query.where(
table[:acronym].matches_any(terms).to_sql
).limit(20)
end
|
#autocomplete_alternate_values_acronym ⇒ Object
25
26
27
|
# File 'lib/queries/repository/autocomplete.rb', line 25
def autocomplete_alternate_values_acronym
matching_alternate_value_on(:acronym).limit(20)
end
|
#autocomplete_alternate_values_name ⇒ Object
29
30
31
|
# File 'lib/queries/repository/autocomplete.rb', line 29
def autocomplete_alternate_values_name
matching_alternate_value_on(:name).limit(20)
end
|
#base_query ⇒ Object
14
15
16
|
# File 'lib/queries/repository/autocomplete.rb', line 14
def base_query
::Repository.select('repositories.*')
end
|
#table ⇒ Arel::Table
58
59
60
|
# File 'lib/queries/repository/autocomplete.rb', line 58
def table
::Repository.arel_table
end
|