Class: Queries::ControlledVocabularyTermAutocompleteQuery

Inherits:
Query
  • Object
show all
Includes:
Arel::Nodes
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

#build_terms, #cached, #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_like, #with_project_id, #years

Constructor Details

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

Returns a new instance of ControlledVocabularyTermAutocompleteQuery



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

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



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

def object_type
  @object_type
end

Instance Method Details

- (Scope) all

Returns:

  • (Scope)


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

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

- (Object) definition_matches



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

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

- (Object) keyword_named



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

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

- (Object) or_clauses



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

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



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

def table
  ControlledVocabularyTerm.arel_table
end

- (Object) uri_equal_to



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

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

- (Object) uri_matches



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

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

- (Object) where_sql



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

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

- (Object) with_type



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

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