How to create text search configuration but only when it doesn't exists? For instance, like the other create statements:
CREATE TEXT SEARCH CONFIGURATION IF NOT EXISTS text_without_accent (COPY = simple);
When performing a full-text searches on a PostgreSQL database, you must implement the to_tsvector() and to_tsquery() functions together with a match operator @@. The match operator returns a boolean value (either t or f) when you run a keyword search (tsquery) against a tsvector document.
A FTS configuration specifies all of the equipment necessary to transform a document into a tsvector: the parser that breaks its text into tokens, and the dictionaries, which then transform each token into a lexeme. Every call to to_tsvector() , to_tsquery() uses a configuration to perform its processing.
Yes, You Can Keep Full-Text Search in Postgres You can get even deeper and make your Postgres full-text search even more robust, by implementing features such as highlighting results, or writing your own custom dictionaries or functions.
tsvector. A tsvector value is a sorted list of distinct lexemes, which are words that have been normalized to merge different variants of the same word (see Chapter 12 for details).
Use a DO
statement and capture errors:
DO
$$BEGIN
CREATE TEXT SEARCH CONFIGURATION ...
EXCEPTION
WHEN unique_violation THEN
NULL; -- ignore error
END;$$;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With