Commit 00f304ce authored by Teodor Sigaev's avatar Teodor Sigaev

Fix parsing NOT sequence in tsquery

Digging around bug #14245 I found that commit
6734a1ca missed that NOT operation is
right associative in opposite to all other. This miss is resposible for
tsquery parser fail on sequence of NOT operations
parent 19d29015
...@@ -455,7 +455,9 @@ cleanOpStack(TSQueryParserState state, ...@@ -455,7 +455,9 @@ cleanOpStack(TSQueryParserState state,
while(*lenstack) while(*lenstack)
{ {
if (opPriority > OP_PRIORITY(stack[*lenstack - 1].op)) /* NOT is right associative unlike to others */
if ((op != OP_NOT && opPriority > OP_PRIORITY(stack[*lenstack - 1].op)) ||
(op == OP_NOT && opPriority >= OP_PRIORITY(stack[*lenstack - 1].op)))
break; break;
(*lenstack)--; (*lenstack)--;
......
...@@ -330,6 +330,42 @@ SELECT 'a:* & nbb:*ac | doo:a* | goo'::tsquery; ...@@ -330,6 +330,42 @@ SELECT 'a:* & nbb:*ac | doo:a* | goo'::tsquery;
'a':* & 'nbb':*AC | 'doo':*A | 'goo' 'a':* & 'nbb':*AC | 'doo':*A | 'goo'
(1 row) (1 row)
SELECT '!!b'::tsquery;
tsquery
---------
!!'b'
(1 row)
SELECT '!!!b'::tsquery;
tsquery
---------
!!!'b'
(1 row)
SELECT '!(!b)'::tsquery;
tsquery
---------
!!'b'
(1 row)
SELECT 'a & !!b'::tsquery;
tsquery
-------------
'a' & !!'b'
(1 row)
SELECT '!!a & b'::tsquery;
tsquery
-------------
!!'a' & 'b'
(1 row)
SELECT '!!a & !!b'::tsquery;
tsquery
---------------
!!'a' & !!'b'
(1 row)
-- phrase transformation -- phrase transformation
SELECT 'a <-> (b|c)'::tsquery; SELECT 'a <-> (b|c)'::tsquery;
tsquery tsquery
......
...@@ -57,6 +57,12 @@ SELECT '1&(2&(4&(5|!6)))'::tsquery; ...@@ -57,6 +57,12 @@ SELECT '1&(2&(4&(5|!6)))'::tsquery;
SELECT E'1&(''2''&('' 4''&(\\|5 | ''6 \\'' !|&'')))'::tsquery; SELECT E'1&(''2''&('' 4''&(\\|5 | ''6 \\'' !|&'')))'::tsquery;
SELECT $$'\\as'$$::tsquery; SELECT $$'\\as'$$::tsquery;
SELECT 'a:* & nbb:*ac | doo:a* | goo'::tsquery; SELECT 'a:* & nbb:*ac | doo:a* | goo'::tsquery;
SELECT '!!b'::tsquery;
SELECT '!!!b'::tsquery;
SELECT '!(!b)'::tsquery;
SELECT 'a & !!b'::tsquery;
SELECT '!!a & b'::tsquery;
SELECT '!!a & !!b'::tsquery;
-- phrase transformation -- phrase transformation
SELECT 'a <-> (b|c)'::tsquery; SELECT 'a <-> (b|c)'::tsquery;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment