2

How does precedence work in websearch_to_tsquery? I have below example query:

websearch_to_tsquery('exp1 exp2 OR "multi word expression" -weak')

The issue I have is that the results include text containing 'weak' because they match 'exp1 exp2'.

However when I remove OR "multi word expression eg query being

websearch_to_tsquery('exp1 exp2 -weak')

then it works as expected and weak is not present in results.

I suspect the initial query is interpreted as

(exp1 and exp2) OR ("multi word expression" and not weak)

instead of my intention of (exp1 and exp2) OR ("multi word expression") and not weak

So how would I write the later query using `websearch_to_tsquery?

asked Jun 29, 2020 at 7:13

1 Answer 1

3

This is how PostgreSQL interprets your query:

SELECT websearch_to_tsquery('english', 'exp1 exp2 OR "multi word expression" -weak');
 websearch_to_tsquery 
--------------------------------------------------------------
 'exp1' & 'exp2' | 'multi' <-> 'word' <-> 'express' & !'weak'
(1 row)

Since & ties stronger than |, your suspicion is correct.

I don't think that there is a simpler way to express what you want with websearch_to_tsquery than

exp1 exp2 -weak OR "multi word expression" -weak
answered Jun 29, 2020 at 9:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.