@@ -1360,7 +1360,7 @@ checkcondition_str(void *checkval, QueryOperand *val, ExecPhraseData *data)
1360
1360
*/
1361
1361
static bool
1362
1362
TS_phrase_execute (QueryItem * curitem ,
1363
- void * checkval , bool calcnot , ExecPhraseData * data ,
1363
+ void * checkval , uint32 flags , ExecPhraseData * data ,
1364
1364
bool (* chkcond ) (void * , QueryOperand * , ExecPhraseData * ))
1365
1365
{
1366
1366
/* since this function recurses, it could be driven to stack overflow */
@@ -1382,18 +1382,19 @@ TS_phrase_execute(QueryItem *curitem,
1382
1382
Assert (curitem -> qoperator .oper == OP_PHRASE );
1383
1383
1384
1384
if (!TS_phrase_execute (curitem + curitem -> qoperator .left ,
1385
- checkval , calcnot , & Ldata , chkcond ))
1385
+ checkval , flags , & Ldata , chkcond ))
1386
1386
return false;
1387
1387
1388
- if (!TS_phrase_execute (curitem + 1 , checkval , calcnot , & Rdata , chkcond ))
1388
+ if (!TS_phrase_execute (curitem + 1 , checkval , flags , & Rdata , chkcond ))
1389
1389
return false;
1390
1390
1391
1391
/*
1392
1392
* if at least one of the operands has no position information,
1393
- * fallback to AND operation.
1393
+ * then return false. But if TS_EXEC_PHRASE_AS_AND flag is set then
1394
+ * we return true as it is a AND operation
1394
1395
*/
1395
1396
if (Ldata .npos == 0 || Rdata .npos == 0 )
1396
- return true;
1397
+ return ( flags & TS_EXEC_PHRASE_AS_AND ) ? true : false ;
1397
1398
1398
1399
/*
1399
1400
* Result of the operation is a list of the corresponding positions of
@@ -1498,13 +1499,11 @@ TS_phrase_execute(QueryItem *curitem,
1498
1499
* chkcond is a callback function used to evaluate each VAL node in the query.
1499
1500
* checkval can be used to pass information to the callback. TS_execute doesn't
1500
1501
* do anything with it.
1501
- * if calcnot is false, NOT expressions are always evaluated to be true. This
1502
- * is used in ranking.
1503
1502
* It believes that ordinary operators are always closier to root than phrase
1504
1503
* operator, so, TS_execute() may not take care of lexeme's position at all.
1505
1504
*/
1506
1505
bool
1507
- TS_execute (QueryItem * curitem , void * checkval , bool calcnot ,
1506
+ TS_execute (QueryItem * curitem , void * checkval , uint32 flags ,
1508
1507
bool (* chkcond ) (void * checkval , QueryOperand * val , ExecPhraseData * data ))
1509
1508
{
1510
1509
/* since this function recurses, it could be driven to stack overflow */
@@ -1517,25 +1516,29 @@ TS_execute(QueryItem *curitem, void *checkval, bool calcnot,
1517
1516
switch (curitem -> qoperator .oper )
1518
1517
{
1519
1518
case OP_NOT :
1520
- if (calcnot )
1521
- return !TS_execute (curitem + 1 , checkval , calcnot , chkcond );
1519
+ if (flags & TS_EXEC_CALC_NOT )
1520
+ return !TS_execute (curitem + 1 , checkval , flags , chkcond );
1522
1521
else
1523
1522
return true;
1524
1523
1525
1524
case OP_AND :
1526
- if (TS_execute (curitem + curitem -> qoperator .left , checkval , calcnot , chkcond ))
1527
- return TS_execute (curitem + 1 , checkval , calcnot , chkcond );
1525
+ if (TS_execute (curitem + curitem -> qoperator .left , checkval , flags , chkcond ))
1526
+ return TS_execute (curitem + 1 , checkval , flags , chkcond );
1528
1527
else
1529
1528
return false;
1530
1529
1531
1530
case OP_OR :
1532
- if (TS_execute (curitem + curitem -> qoperator .left , checkval , calcnot , chkcond ))
1531
+ if (TS_execute (curitem + curitem -> qoperator .left , checkval , flags , chkcond ))
1533
1532
return true;
1534
1533
else
1535
- return TS_execute (curitem + 1 , checkval , calcnot , chkcond );
1534
+ return TS_execute (curitem + 1 , checkval , flags , chkcond );
1536
1535
1537
1536
case OP_PHRASE :
1538
- return TS_phrase_execute (curitem , checkval , calcnot , NULL , chkcond );
1537
+ /*
1538
+ * do not check TS_EXEC_PHRASE_AS_AND here because chkcond()
1539
+ * could do something more if it's called from TS_phrase_execute()
1540
+ */
1541
+ return TS_phrase_execute (curitem , checkval , flags , NULL , chkcond );
1539
1542
1540
1543
default :
1541
1544
elog (ERROR , "unrecognized operator: %d" , curitem -> qoperator .oper );
@@ -1633,7 +1636,7 @@ ts_match_vq(PG_FUNCTION_ARGS)
1633
1636
result = TS_execute (
1634
1637
GETQUERY (query ),
1635
1638
& chkval ,
1636
- true ,
1639
+ TS_EXEC_CALC_NOT ,
1637
1640
checkcondition_str
1638
1641
);
1639
1642
0 commit comments