So, I’m on Django 3.2 and Postgres 12, and trying to use SearchQuery with
According to the documentation, this example shows that parentheses should be relevant in a “websearch” query, and implies that the “raw” and “websearch” queries are identical:
>>> SearchQuery("'tomato' & ('red' | 'green')", search_type='raw') >>> SearchQuery("'tomato' ('red' OR 'green')", search_type='websearch')
I am interpreting both examples as “tomato AND (red OR green)”, which expands in plain language to “give me results that include both tomato and red, and results that include both tomato and green”.
However, when I attempted this query, I receive results that are different in “websearch” than in “raw”. The “raw” search_type returns the results I expect. However, the “websearch” search_type becomes translated to a raw query of
'tomato' & 'red' | 'green', dropping the parentheses grouping entirely. This means you will receive results that include “green” but not “tomato.”
Am I misunderstanding the documentation or implementing websearch incorrectly? It appears to me that
"tomato' ('red' OR 'green')" should be different from
"tomato' 'red' OR 'green'" but in practice there is no difference in results at all.
I would appreciate any help on this! Thank you.