Can I search for multiple words?

0123

Yes, you can search for multiple words using the to_tsquery function in PostgreSQL. You can combine words with logical operators like AND, OR, and NOT.

Here’s an example of how to search for multiple words:

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

In this example, the query will return articles that contain both word1 and word2.

If you want to search for articles that contain either word1 or word2, you can use the | operator:

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

Feel free to adjust the query based on your specific search needs!

0 Comments

no data
Be the first to share your comment!