Build the two strings you feed to Postgres full-text search, both produced by the
same SearchCore.Pipeline so the index side and the query side always agree.
Because tokens are already stemmed and accent-folded in Elixir, you use the
'simple' Postgres configuration (no further stemming/stopwords in the database):
-- indexing (store `searchable_text/3` in a column, index its tsvector)
to_tsvector('simple', search_text)
-- querying
to_tsquery('simple', $1) -- $1 = tsquery/3Tokens are restricted to letters/digits (see SearchCore.Pipeline), so the produced
tsquery string contains no operators to escape and is safe to pass as a bound
parameter to to_tsquery('simple', ?).
Summary
Functions
Space-joined stemmed tokens to store in a search_text column for indexing.
Build a tsquery string from a user query.
Functions
@spec searchable_text(String.t(), Stemmers.language(), [SearchCore.Pipeline.opt()]) :: String.t()
Space-joined stemmed tokens to store in a search_text column for indexing.
iex> SearchCore.Tsvector.searchable_text("Les chevaux mangent", :french)
"cheval mangent"
@spec tsquery(String.t(), Stemmers.language(), keyword()) :: String.t()
Build a tsquery string from a user query.
Options (in addition to SearchCore.Pipeline options):
:combinator—:and(default) requires all terms,:orrequires any:prefix— whentrue, append:*to each term for prefix matching
Returns "" when the query has no usable tokens; to_tsquery('simple', '') simply
matches nothing.
iex> SearchCore.Tsvector.tsquery("chevaux mangent", :french)
"cheval & mangent"
iex> SearchCore.Tsvector.tsquery("chev", :french, prefix: true, combinator: :or)
"chev:*"