How to exclude specific words?

0208

To exclude specific words in a full-text search using PostgreSQL, you can use the NOT operator in your to_tsquery. Here’s how you can do it:

SELECT title, content 
FROM articles 
WHERE search_vector @@ to_tsquery('english', 'word1 & !word2');

In this example:

  • word1 is the word you want to include in your search.
  • !word2 indicates that you want to exclude word2 from the results.

This query will return articles that contain word1 but do not contain word2. You can combine this with other operators as needed for more complex queries.

0 Comments

no data
Be the first to share your comment!