]> granicus.if.org Git - postgresql/commit
Fix handling of phrase operator removal while removing tsquery stopwords.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 19 Dec 2016 18:49:45 +0000 (13:49 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 19 Dec 2016 18:49:50 +0000 (13:49 -0500)
commit2604438472c897fbbd1568b1a8ee177ba8cdb6e3
treea837676b4885a47de9a1c4034635a14a0d7a8a40
parentdd728826c538f000220af98de025c00114ad0631
Fix handling of phrase operator removal while removing tsquery stopwords.

The distance of a removed phrase operator should propagate up to a
parent phrase operator if there is one, but this only worked correctly
in left-deep trees.  Throwing in a few parentheses confused it completely,
as indeed was illustrated by bizarre results in existing regression test
cases.

To fix, track unaccounted-for distances that should propagate to the left
and to the right of the current node, rather than trying to make it work
with only one returned distance.

Also make some adjustments to behave as well as we can for cases of
intermixed phrase and regular (AND/OR) operators.  I don't think it's
possible to be 100% correct for that without a rethinking of the tsquery
representation; for example, maybe we should just not drop stopword nodes
at all underneath phrase operators.  But this is better than it was,
and changing tsquery representation wouldn't be safely back-patchable.

While at it, I simplified the API of the clean_fakeval_intree function
a bit by getting rid of the "char *result" output parameter; that wasn't
doing anything that wasn't redundant with whether the result node is
NULL or not, and testing for NULL seems a lot clearer/safer.

This is part of a larger project to fix various infelicities in the
phrase-search implementation, but this part seems comittable on its own.

Back-patch to 9.6 where phrase operators were introduced.

Discussion: https://postgr.es/m/28215.1481999808@sss.pgh.pa.us
Discussion: https://postgr.es/m/26706.1482087250@sss.pgh.pa.us
src/backend/utils/adt/tsquery_cleanup.c
src/test/regress/expected/tsearch.out