Class: DbTextSearch::CaseInsensitive::LowerAdapter Private
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- DbTextSearch::CaseInsensitive::LowerAdapter
- Defined in:
- lib/db_text_search/case_insensitive/lower_adapter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Provides case-insensitive string-in-set querying by applying the database LOWER function.
Class Method Summary collapse
-
.add_index(connection, table_name, column_name, options = {}) ⇒ Object
abstract
Add an index for case-insensitive string search.
Instance Method Summary collapse
- #column_for_order(asc_or_desc) ⇒ Arel::Collectors::SQLString abstract
- #in(values) ⇒ ActiveRecord::Relation abstract
- #prefix(query) ⇒ ActiveRecord::Relation abstract
Methods inherited from AbstractAdapter
Methods included from QueryBuilding
Constructor Details
This class inherits a constructor from DbTextSearch::CaseInsensitive::AbstractAdapter
Class Method Details
.add_index(connection, table_name, column_name, options = {}) ⇒ Object
This method is abstract.
Add an index for case-insensitive string search.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/db_text_search/case_insensitive/lower_adapter.rb', line 26 def self.add_index(connection, table_name, column_name, = {}) unsupported = -> { DbTextSearch.unsupported_adapter! connection } DbTextSearch.match_adapter( connection, # TODO: Switch to native Rails support once it lands. # https://github.com/rails/rails/pull/18499 postgres: -> { = .dup [:name] ||= "#{table_name}_#{column_name}_lower" [:expression] = "(LOWER(#{connection.quote_column_name(column_name)}) text_pattern_ops)" connection.exec_query(quoted_create_index(connection, table_name, **)) }, mysql: unsupported, sqlite: unsupported ) end |
Instance Method Details
#column_for_order(asc_or_desc) ⇒ Arel::Collectors::SQLString
This method is abstract.
21 22 23 |
# File 'lib/db_text_search/case_insensitive/lower_adapter.rb', line 21 def column_for_order(asc_or_desc) Arel.sql("LOWER(#{quoted_scope_column}) #{asc_or_desc}") end |
#in(values) ⇒ ActiveRecord::Relation
This method is abstract.
10 11 12 13 |
# File 'lib/db_text_search/case_insensitive/lower_adapter.rb', line 10 def in(values) conn = @scope.connection @scope.where "LOWER(#{quoted_scope_column}) IN (#{values.map { |v| "LOWER(#{conn.quote(v)})" }.join(', ')})" end |
#prefix(query) ⇒ ActiveRecord::Relation
This method is abstract.
16 17 18 |
# File 'lib/db_text_search/case_insensitive/lower_adapter.rb', line 16 def prefix(query) @scope.where "LOWER(#{quoted_scope_column}) LIKE LOWER(?)", "#{sanitize_sql_like(query)}%" end |