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, #wildcard_wrapped_years, #with_id, #with_identifier, #with_identifier_like, #with_project_id, #with_start_date, #year_letter, #years

Constructor Details

- (Autocomplete) initialize(string, **keyword_args)

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]
  @of_type = keyword_args[: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)


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

- (Object) and_clauses



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

- (Object) definition_matches



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

- (Object) keyword_named



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

- (Object) or_clauses



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

- (Object) table



58
59
60
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 58

def table
  ::ControlledVocabularyTerm.arel_table
end

- (Object) uri_equal_to



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

- (Object) with_type



66
67
68
# File 'lib/queries/controlled_vocabulary_term/autocomplete.rb', line 66

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