Class: Queries::DataAttribute::ValueAutocomplete
- Inherits:
-
Query::Autocomplete
- Object
- Query
- Query::Autocomplete
- 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::Autocomplete
#dynamic_limit, #project_id, #query_string
Attributes inherited from Query
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
- #where_sql ⇒ Scope
Methods inherited from Query::Autocomplete
#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, #combine_or_clauses, #common_name_name, #common_name_table, #common_name_wild_pieces, #exactly_named, #fragments, #integers, #least_levenshtein, #match_wildcard_end_in_cached, #match_wildcard_in_cached, #named, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #pieces, #scope, #string_fragments, #wildcard_wrapped_integers, #wildcard_wrapped_years, #with_cached, #with_cached_like, #with_id, #with_project_id, #year_letter, #years
Methods inherited from Query
#alphabetic_strings, #alphanumeric_strings, base_name, #base_name, #base_query, #build_terms, #cached_facet, #end_wildcard, #levenshtein_distance, #match_ordered_wildcard_pieces_in_cached, #no_terms?, referenced_klass, #referenced_klass, #referenced_klass_except, #referenced_klass_intersection, #referenced_klass_union, #start_and_end_wildcard, #start_wildcard, #table, #wildcard_pieces
Constructor Details
#initialize(string, predicate_id: nil, project_id: nil) ⇒ ValueAutocomplete
Returns a new instance of ValueAutocomplete.
7 8 9 10 |
# File 'lib/queries/data_attribute/value_autocomplete.rb', line 7 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.
5 6 7 |
# File 'lib/queries/data_attribute/value_autocomplete.rb', line 5 def predicate_id @predicate_id end |
Instance Method Details
#autocomplete ⇒ Array
Returns of matching strings.
19 20 21 |
# File 'lib/queries/data_attribute/value_autocomplete.rb', line 19 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
30 31 32 33 |
# File 'lib/queries/data_attribute/value_autocomplete.rb', line 30 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
24 25 26 27 |
# File 'lib/queries/data_attribute/value_autocomplete.rb', line 24 def matching_value return nil if query_string.nil? table[:value].matches(start_and_end_wildcard) end |
#where_sql ⇒ Scope
13 14 15 |
# File 'lib/queries/data_attribute/value_autocomplete.rb', line 13 def where_sql with_project_id.and(matching_value.and(matching_controlled_vocabulary_term_id)).to_sql end |