Class: DbTextSearch::FullText
- Inherits:
-
Object
- Object
- DbTextSearch::FullText
- Defined in:
- lib/db_text_search/full_text.rb,
lib/db_text_search/full_text/mysql_adapter.rb,
lib/db_text_search/full_text/sqlite_adapter.rb,
lib/db_text_search/full_text/abstract_adapter.rb,
lib/db_text_search/full_text/postgres_adapter.rb
Overview
Provides basic full-text search for a list of terms, and FTS index creation.
Defined Under Namespace
Classes: AbstractAdapter, MysqlAdapter, PostgresAdapter, SqliteAdapter
Constant Summary collapse
- DEFAULT_PG_TS_CONFIG =
The default Postgres text search config.
%q('english')
Class Method Summary collapse
- .adapter_class(connection, _table_name, _column_name) ⇒ Class<AbstractAdapter> private
-
.add_index(connection, table_name, column_name, name: "#{table_name}_#{column_name}_fts", pg_ts_config: DEFAULT_PG_TS_CONFIG) ⇒ Object
Add an index for full text search.
Instance Method Summary collapse
-
#initialize(scope, column) ⇒ FullText
constructor
A new instance of FullText.
- #search(term_or_terms, pg_ts_config: DEFAULT_PG_TS_CONFIG) ⇒ ActiveRecord::Relation
Constructor Details
#initialize(scope, column) ⇒ FullText
Returns a new instance of FullText.
15 16 17 18 |
# File 'lib/db_text_search/full_text.rb', line 15 def initialize(scope, column) @adapter = self.class.adapter_class(scope.connection, scope.table_name, column).new(scope, column) @scope = scope end |
Class Method Details
.adapter_class(connection, _table_name, _column_name) ⇒ Class<AbstractAdapter>
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.
47 48 49 50 51 52 53 54 |
# File 'lib/db_text_search/full_text.rb', line 47 def self.adapter_class(connection, _table_name, _column_name) DbTextSearch.match_adapter( connection, mysql: -> { MysqlAdapter }, postgres: -> { PostgresAdapter }, sqlite: -> { SqliteAdapter } ) end |
.add_index(connection, table_name, column_name, name: "#{table_name}_#{column_name}_fts", pg_ts_config: DEFAULT_PG_TS_CONFIG) ⇒ Object
Add an index for full text search.
36 37 38 39 40 |
# File 'lib/db_text_search/full_text.rb', line 36 def self.add_index(connection, table_name, column_name, name: "#{table_name}_#{column_name}_fts", pg_ts_config: DEFAULT_PG_TS_CONFIG) adapter_class(connection, table_name, column_name) .add_index(connection, table_name, column_name, name: name, pg_ts_config: pg_ts_config) end |
Instance Method Details
#search(term_or_terms, pg_ts_config: DEFAULT_PG_TS_CONFIG) ⇒ ActiveRecord::Relation
23 24 25 26 27 |
# File 'lib/db_text_search/full_text.rb', line 23 def search(term_or_terms, pg_ts_config: DEFAULT_PG_TS_CONFIG) values = Array(term_or_terms) return @scope.none if values.empty? @adapter.search(values, pg_ts_config: pg_ts_config) end |