class DbTextSearch::CaseInsensitive::LowerAdapter
Provides case-insensitive string-in-set querying by applying the database LOWER function. @api private
Public Class Methods
add_index(connection, table_name, column_name, options = {})
click to toggle source
(see AbstractAdapter.add_index
)
# File lib/db_text_search/case_insensitive/lower_adapter.rb, line 26 def self.add_index(connection, table_name, column_name, options = {}) 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: -> { options = options.dup options[:name] ||= "#{table_name}_#{column_name}_lower" options[:expression] = "(LOWER(#{connection.quote_column_name(column_name)}) text_pattern_ops)" connection.exec_query(quoted_create_index(connection, table_name, **options)) }, mysql: unsupported, sqlite: unsupported ) end
Public Instance Methods
column_for_order(asc_or_desc)
click to toggle source
(see AbstractAdapter#column_for_order
)
# 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)
click to toggle source
(see AbstractAdapter#in
)
# 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)
click to toggle source
(see AbstractAdapter#prefix
)
# 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