Class: ControlledVocabularyTerm::Autocomplete

Inherits:
Queries::Query show all
Defined in:
lib/queries/controlled_vocabulary_term/autocomplete.rb

Instance Attribute Summary (collapse)

Attributes inherited from Queries::Query

#dynamic_limit, #options, #project_id, #query_string, #terms

Instance Method Summary (collapse)

Methods inherited from Queries::Query

#alphabetic_strings, #autocomplete, #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_identifier_cached_exact, #autocomplete_identifier_cached_like, #autocomplete_ordered_wildcard_pieces_in_cached, #autocomplete_start_date, #build_terms, #cached, #combine_or_clauses, #end_wildcard, #exactly_named, #fragments, #identifier_table, #integers, #match_ordered_wildcard_pieces_in_cached, #match_wildcard_cached, #named, #no_digits, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #pieces, #result, #scope, #simple_date, #start_and_end_wildcard, #start_wildcard, #wildcard_pieces, #wildcard_wrapped_integers, #with_id, #with_identifier, #with_identifier_like, #with_project_id, #with_start_date, #year_letter, #years

Constructor Details

- (Autocomplete) initialize(string, project_id: nil, of_type: [])

Returns a new instance of Autocomplete



9
10
11
12
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 9

def initialize(string, project_id: nil, of_type: [])
  super(string, project_id: project_id) 
  @of_type = of_type
end

Instance Attribute Details

- (Object) of_type

Array

of :type



7
8
9
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 7

def of_type
  @of_type
end

Instance Method Details

- (Scope) all

Returns:

  • (Scope)


44
45
46
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 44

def all 
  ::ControlledVocabularyTerm.where(where_sql).order(:type, :name).limit(40)
end

- (Object) definition_matches



64
65
66
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 64

def definition_matches
  table[:definition].matches_any(terms)
end

- (Object) keyword_named



52
53
54
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 52

def keyword_named
  table[:name].matches_any(terms)
end

- (Object) or_clauses



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 28

def or_clauses
  clauses = [
    named,
    definition_matches,
    uri_equal_to,
    with_id
  ].compact

  a = clauses.shift
  clauses.each do |b|
    a = a.or(b)
  end
  a
end

- (Object) table



48
49
50
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 48

def table
  ::ControlledVocabularyTerm.arel_table
end

- (Object) uri_eq

not used



69
70
71
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 69

def uri_eq
  table[:uri].eq(query_string) 
end

- (Object) uri_equal_to



60
61
62
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 60

def uri_equal_to
  table[:uri].eq(query_string)
end

- (Object) where_sql



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 14

def where_sql
  c = [or_clauses]
  c.push with_project_id if !project_id.blank?
  c.push with_type if !of_type.blank?

  c.compact

  a = c.pop
  c.each do |q|
    a.and(q)
  end
  a
end

- (Object) with_type



56
57
58
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 56

def with_type 
  table[:type].eq_any(of_type)
end