Class: DbTextSearch::FullText::PostgresAdapter Private

Inherits:
AbstractAdapter show all
Defined in:
lib/db_text_search/full_text/postgres_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 basic FTS support for PostgreSQL.

Runs a ‘@@ plainto_tsquery` query against a `gist(to_tsvector(…))` index.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractAdapter

#initialize

Methods included from QueryBuilding

included, #sanitize_sql_like

Constructor Details

This class inherits a constructor from DbTextSearch::FullText::AbstractAdapter

Class Method Details

.add_index(connection, table_name, column_name, name:, pg_ts_config:) ⇒ 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.

This method is abstract.

Add an index for full text search.

Parameters:

  • connection (ActiveRecord::ConnectionAdapters::AbstractAdapter)
  • table_name (String, Symbol)
  • column_name (String, Symbol)
  • name (String, Symbol)

    index name

  • pg_ts_config (String)

    for Postgres, the TS config to use; ignored for non-postgres.



20
21
22
23
# File 'lib/db_text_search/full_text/postgres_adapter.rb', line 20

def self.add_index(connection, table_name, column_name, name:, pg_ts_config:)
  expression = "USING gist(to_tsvector(#{pg_ts_config}, #{connection.quote_column_name column_name}))"
  connection.exec_query quoted_create_index(connection, table_name, name: name, expression: expression)
end

Instance Method Details

#search(terms, pg_ts_config:) ⇒ 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.

This method is abstract.

Parameters:

  • terms (Array<String>)
  • pg_ts_config (String)

    a pg text search config

Returns:

  • (ActiveRecord::Relation)


14
15
16
17
# File 'lib/db_text_search/full_text/postgres_adapter.rb', line 14

def search(terms, pg_ts_config:)
  @scope.where("to_tsvector(#{pg_ts_config}, #{quoted_scope_column}) @@ plainto_tsquery(#{pg_ts_config}, ?)",
               terms.uniq.join(' '))
end