Class: DbTextSearch::CaseInsensitive::CollateNocaseAdapter Private
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- DbTextSearch::CaseInsensitive::CollateNocaseAdapter
- Defined in:
- lib/db_text_search/case_insensitive/collate_nocase_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 via COLLATE NOCASE.
Class Method Summary collapse
-
.add_index(connection, table_name, column_name, options = {}) ⇒ Object
abstract
private
Add an index for case-insensitive string search.
Instance Method Summary collapse
- #column_for_order(asc_or_desc) ⇒ Arel::Collectors::SQLString abstract private
- #in(values) ⇒ ActiveRecord::Relation abstract private
- #prefix(query) ⇒ ActiveRecord::Relation abstract private
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 part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Add an index for case-insensitive string search.
31 32 33 34 35 36 37 38 |
# File 'lib/db_text_search/case_insensitive/collate_nocase_adapter.rb', line 31 def self.add_index(connection, table_name, column_name, = {}) # TODO: Switch to the native Rails solution once it's landed, as the current one requires SQL dump format. # https://github.com/rails/rails/pull/18499 = .dup [:name] ||= "#{column_name}_nocase" [:expression] = "(#{connection.quote_column_name(column_name)} COLLATE NOCASE)" connection.exec_query quoted_create_index(connection, table_name, **) end |
Instance Method Details
#column_for_order(asc_or_desc) ⇒ Arel::Collectors::SQLString
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 |
# File 'lib/db_text_search/case_insensitive/collate_nocase_adapter.rb', line 26 def column_for_order(asc_or_desc) Arel.sql("#{quoted_scope_column} COLLATE NOCASE #{asc_or_desc}") end |
#in(values) ⇒ ActiveRecord::Relation
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
10 11 12 13 |
# File 'lib/db_text_search/case_insensitive/collate_nocase_adapter.rb', line 10 def in(values) conn = @scope.connection @scope.where "#{quoted_scope_column} COLLATE NOCASE IN (#{values.map { |v| conn.quote(v.to_s) }.join(', ')})" end |
#prefix(query) ⇒ ActiveRecord::Relation
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 19 20 21 22 23 |
# File 'lib/db_text_search/case_insensitive/collate_nocase_adapter.rb', line 16 def prefix(query) escape = '\\' escaped_query = "#{sanitize_sql_like(query, escape)}%" # assuming case_sensitive_prefix mode to be disabled, prefix it is by default. # this is to avoid adding COLLATE NOCASE here, which prevents index use in SQLite LIKE. @scope.where "#{quoted_scope_column} LIKE ?#{" ESCAPE '#{escape}'" if escaped_query.include?(escape)}", escaped_query end |