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

#alphabetic_strings, #autocomplete, #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_ordered_wildcard_pieces_in_cached, #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, #start_and_end_wildcard, #start_wildcard, #wildcard_pieces, #wildcard_wrapped_integers, #with_id, #with_identifier, #with_identifier_like, #with_project_id, #year_letter, #years

Constructor Details

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

Returns a new instance of ControlledVocabularyTermAutocompleteQuery

Parameters:

  • args (Hash)


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

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_query.rb', line 7

def of_type
  @of_type
end

Instance Method Details

- (Scope) all

Returns:

  • (Scope)


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

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

- (Arel::Nodes::Matches) definition_matches

Returns:

  • (Arel::Nodes::Matches)


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

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

- (Arel::Nodes::Matching) keyword_named

Returns:

  • (Arel::Nodes::Matching)


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

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

- (Arel::Nodes::Grouping) or_clauses

Returns:

  • (Arel::Nodes::Grouping)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/queries/controlled_vocabulary_term_autocomplete_query.rb', line 23

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

- (Arel::Table) table

Returns:

  • (Arel::Table)


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

def table
  ControlledVocabularyTerm.arel_table
end

- (Arel::Nodes::Equatity) uri_eq

not used

Returns:

  • (Arel::Nodes::Equatity)


70
71
72
# File 'lib/queries/controlled_vocabulary_term_autocomplete_query.rb', line 70

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

- (Arel::Nodes::Equatity) uri_equal_to

Returns:

  • (Arel::Nodes::Equatity)


59
60
61
# File 'lib/queries/controlled_vocabulary_term_autocomplete_query.rb', line 59

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

- (String) where_sql

Returns:

  • (String)


16
17
18
19
20
# File 'lib/queries/controlled_vocabulary_term_autocomplete_query.rb', line 16

def where_sql
  a = with_project_id.and(or_clauses)
  a = a.and(with_type) if !of_type.blank?
  a.to_sql
end

- (Arel::Nodes::Equatity) with_type

Returns:

  • (Arel::Nodes::Equatity)


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

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