Class: Queries::DataAttribute::ValueAutocomplete
- Defined in:
- lib/queries/data_attribute/value_autocomplete.rb
Instance Attribute Summary collapse
-
#predicate_id ⇒ Object
Returns the value of attribute predicate_id.
Attributes inherited from Query
#dynamic_limit, #options, #project_id, #query_string, #terms
Instance Method Summary collapse
-
#autocomplete ⇒ Array
Of matching strings.
-
#initialize(string, predicate_id: nil, project_id: nil) ⇒ ValueAutocomplete
constructor
A new instance of ValueAutocomplete.
- #matching_controlled_vocabulary_term_id ⇒ Arel::Nodes::Matches
- #matching_value ⇒ Arel::Nodes::Matches
- #table ⇒ Arel::Table
- #where_sql ⇒ Scope
Methods inherited from Query
#alphabetic_strings, #alphanumeric_strings, #attribute_exact_facet, #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_common_name_exact, #autocomplete_common_name_like, #autocomplete_exact_id, #autocomplete_exactly_named, #autocomplete_named, #autocomplete_ordered_wildcard_pieces_in_cached, #build_terms, #cached, #combine_or_clauses, #common_name_name, #common_name_table, #common_name_wild_pieces, #end_wildcard, #exactly_named, #fragments, #integers, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #match_wildcard_end_in_cached, #match_wildcard_in_cached, #named, #no_terms?, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #pieces, #result, #scope, #start_and_end_wildcard, #start_wildcard, #string_fragments, #wildcard_pieces, #wildcard_wrapped_integers, #wildcard_wrapped_years, #with_cached, #with_cached_like, #with_id, #with_project_id, #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_id ⇒ Object
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
#autocomplete ⇒ Array
Returns 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_id ⇒ 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_value ⇒ 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 |
#table ⇒ Arel::Table
23 24 25 |
# File 'lib/queries/data_attribute/value_autocomplete.rb', line 23 def table ::DataAttribute.arel_table end |
#where_sql ⇒ 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 |