Class: Queries::DataAttribute::ValueAutocomplete

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

Instance Attribute Summary collapse

Attributes inherited from Query

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

Instance Method Summary collapse

Methods inherited from Query

#alphabetic_strings, #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_exact_id, #autocomplete_ordered_wildcard_pieces_in_cached, #autocomplete_start_date, #build_terms, #cached, #combine_or_clauses, #end_wildcard, #exactly_named, #fragments, #integers, #match_ordered_wildcard_pieces_in_cached, #match_wildcard_end_in_cached, #match_wildcard_in_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_cached, #with_cached_like, #with_id, #with_project_id, #with_start_date, #year_letter, #years

Constructor Details

#initialize(string, predicate_id: nil, project_id: nil) ⇒ ValueAutocomplete

Returns a new instance of ValueAutocomplete



6
7
8
9
# File 'lib/queries/data_attribute/value_autocomplete.rb', line 6

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

Instance Attribute Details

#predicate_idObject

Returns the value of attribute predicate_id



4
5
6
# File 'lib/queries/data_attribute/value_autocomplete.rb', line 4

def predicate_id
  @predicate_id
end

Instance Method Details

#autocompleteArray

Returns of matching strings

Returns:

  • (Array)

    of matching strings



18
19
20
# File 'lib/queries/data_attribute/value_autocomplete.rb', line 18

def autocomplete
  ::DataAttribute.where(where_sql).order(Arel.sql('LENGTH(value) ASC')).distinct.limit(50).pluck(:value, 'LENGTH(value)').map(&:first)
end

#matching_controlled_vocabulary_term_idArel::Nodes::Matches

Returns:

  • (Arel::Nodes::Matches)


34
35
36
37
# File 'lib/queries/data_attribute/value_autocomplete.rb', line 34

def matching_controlled_vocabulary_term_id
  return nil if query_string.nil?
  table[:controlled_vocabulary_term_id].eq(predicate_id)
end

#matching_valueArel::Nodes::Matches

Returns:

  • (Arel::Nodes::Matches)


28
29
30
31
# File 'lib/queries/data_attribute/value_autocomplete.rb', line 28

def matching_value 
  return nil if query_string.nil?
  table[:value].matches(start_and_end_wildcard)
end

#tableArel::Table

Returns:

  • (Arel::Table)


23
24
25
# File 'lib/queries/data_attribute/value_autocomplete.rb', line 23

def table
  ::DataAttribute.arel_table
end

#where_sqlScope

Returns:

  • (Scope)


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

def where_sql
  with_project_id.and(matching_value.and(matching_controlled_vocabulary_term_id)).to_sql
end