Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cIgbr-0002zH-3K for pgsql-bugs@arkaria.postgresql.org; Sun, 18 Dec 2016 18:54:59 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cIgbp-0003dM-WE for pgsql-bugs@arkaria.postgresql.org; Sun, 18 Dec 2016 18:54:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cIgbA-0002u8-Ds for pgsql-bugs@postgreSQL.org; Sun, 18 Dec 2016 18:54:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cIgb7-0000ld-DZ for pgsql-bugs@postgreSQL.org; Sun, 18 Dec 2016 18:54:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id uBIIsASI026707 for ; Sun, 18 Dec 2016 13:54:10 -0500 From: Tom Lane To: pgsql-bugs@postgreSQL.org Subject: Mishandling of right-associated phrase operators in FTS MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <26705.1482087250.1@sss.pgh.pa.us> Date: Sun, 18 Dec 2016 13:54:10 -0500 Message-ID: <26706.1482087250@sss.pgh.pa.us> X-Pg-Spam-Score: -5.0 (-----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org What do you think a tsquery like 'x <-> (y <-> z)' should mean? I find it hard to assign it any meaning other than the same thing as '(x <-> y) <-> z', ie, it should match a 3-lexeme sequence 'x y z'. Right now, the execution engine gets this wrong: regression=# select to_tsvector('x y z') @@ to_tsquery('x <-> y <-> z'); ?column? ---------- t -- okay (1 row) regression=# select to_tsvector('x y z') @@ to_tsquery('x <-> (y <-> z)'); ?column? ---------- f -- not so okay (1 row) This happens because the lower (righthand) <-> operator returns the position of its righthand-side input ('z'), but that's two away from where the 'x' is, so the upper phrase operator doesn't think there is a match. I considered trying to fix this by forcing right-associated cases into left-associated form during tsquery parsing, but that has all the same problems that I pointed out with respect to normalize_phrase_tree(). Really it'd be best to fix this by making the executor cope properly. I think what we want is to pass down a flag telling recursive invocations of TS_phrase_execute whether to return the position of the left-side or right-side argument of a phrase match, which we would set according to whether we are within the right or left argument of the most closely nested upper phrase operator. I propose to incorporate that fix into the TS_phrase_execute rewrite I'm working on. A related problem appears in clean_fakeval_intree()'s attempts to adjust phrase-operator distances when it removes a stopword. For example, 'a' is a stopword, so we get: regression=# select to_tsquery('(b <-> a) <-> c'); to_tsquery ------------- 'b' <2> 'c' (1 row) That's fine, but I don't think this answer is right: regression=# select to_tsquery('b <-> (a <-> c)'); to_tsquery ------------- 'b' <-> 'c' (1 row) It should be 'b <2> c', same as the other one. I haven't worked this out in detail, but I think a similar solution would work for clean_fakeval_intree: pass down a flag indicating if we're within the left or right argument of a <-> op, and return the appropriate adjustment distance based on that. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs