Class: Queries::ControlledVocabularyTermAutocompleteQuery

Inherits:
Query
  • Object
show all
Defined in:
lib/queries/controlled_vocabulary_term_autocomplete_query.rb

Instance Attribute Summary (collapse)

Attributes inherited from Query

#dynamic_limit, #project_id, #query_string, #terms

Instance Method Summary (collapse)

Methods inherited from Query

#autocomplete, #build_terms, #cached, #combine_or_clauses, #end_wildcard, #exactly_named, #fragments, #identifier_table, #integers, #named, #no_digits, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #result, #scope, #start_and_end_wildcard, #start_wildcard, #strings, #wildcard_wrapped_integers, #with_id, #with_identifier, #with_identifier_like, #with_project_id, #years

Constructor Details

- (ControlledVocabularyTermAutocompleteQuery) initialize(string, project_id: nil, object_type: nil)

Returns a new instance of ControlledVocabularyTermAutocompleteQuery



7
8
9
10
# File 'lib/queries/controlled_vocabulary_term_autocomplete_query.rb', line 7

def initialize(string, project_id: nil, object_type: nil)
  super(string, project_id: project_id) 
  @object_type = object_type
end

Instance Attribute Details

- (Object) object_type

Returns the value of attribute object_type



5
6
7
# File 'lib/queries/controlled_vocabulary_term_autocomplete_query.rb', line 5

def object_type
  @object_type
end

Instance Method Details

- (Scope) all

Returns:

  • (Scope)


32
33
34
# File 'lib/queries/controlled_vocabulary_term_autocomplete_query.rb', line 32

def all 
  ControlledVocabularyTerm.where(where_sql).limit(50)
end

- (Object) definition_matches



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

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

- (Object) keyword_named



40
41
42
# File 'lib/queries/controlled_vocabulary_term_autocomplete_query.rb', line 40

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

- (Object) or_clauses



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/queries/controlled_vocabulary_term_autocomplete_query.rb', line 16

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



36
37
38
# File 'lib/queries/controlled_vocabulary_term_autocomplete_query.rb', line 36

def table
  ControlledVocabularyTerm.arel_table
end

- (Object) uri_equal_to



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

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

- (Object) uri_matches



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

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

- (Object) where_sql



12
13
14
# File 'lib/queries/controlled_vocabulary_term_autocomplete_query.rb', line 12

def where_sql
  with_project_id.and(with_type).and(or_clauses).to_sql
end

- (Object) with_type



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

def with_type 
  table[:type].eq(object_type)
end