Class: ControlledVocabularyTerm::Autocomplete
Instance Attribute Summary collapse
#dynamic_limit, #options, #project_id, #query_string, #terms
Instance Method Summary
collapse
#alphabetic_strings, #attribute_exact_facet, #autocomplete, #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, **keyword_args) ⇒ Autocomplete
Returns a new instance of Autocomplete.
9
10
11
12
13
|
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 9
def initialize(string, **keyword_args)
@query_string = string
@project_id = keyword_args[:project_id]
@type = keyword_args[:type] || []
end
|
Instance Attribute Details
#type ⇒ Object
7
8
9
|
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 7
def type
@type
end
|
Instance Method Details
#all ⇒ Scope
48
49
50
51
52
53
54
55
56
|
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 48
def all
a = [or_clauses, and_clauses].compact
b = a.shift
b = b.and(a.shift) if !a.empty?
b.nil? ?
::ControlledVocabularyTerm.all.order(:type, :name).limit(40) :
::ControlledVocabularyTerm.where(b).order(:type, :name).limit(40)
end
|
#and_clauses ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 15
def and_clauses
clauses = [
with_project_id,
with_type
].compact
return nil if clauses.empty?
a = clauses.shift
clauses.each do |b|
a = a.and(b)
end
a
end
|
#definition_matches ⇒ Object
74
75
76
|
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 74
def definition_matches
table[:definition].matches_any(terms) if terms.any?
end
|
#keyword_named ⇒ Object
62
63
64
|
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 62
def keyword_named
table[:name].matches_any(terms) if terms.any?
end
|
#or_clauses ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 30
def or_clauses
clauses = [
named,
definition_matches,
uri_equal_to,
with_id
].compact
return nil if clauses.empty?
a = clauses.shift
clauses.each do |b|
a = a.or(b)
end
a
end
|
#table ⇒ Object
58
59
60
|
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 58
def table
::ControlledVocabularyTerm.arel_table
end
|
#uri_equal_to ⇒ Object
70
71
72
|
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 70
def uri_equal_to
table[:uri].eq(query_string) if !query_string.blank?
end
|
#with_type ⇒ Object
66
67
68
|
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 66
def with_type
table[:type].eq_any(type) if type.any?
end
|