@@ -1360,7 +1360,7 @@ checkcondition_str(void *checkval, QueryOperand *val, ExecPhraseData *data)
13601360 */
13611361static bool
13621362TS_phrase_execute (QueryItem * curitem ,
1363- void * checkval , bool calcnot , ExecPhraseData * data ,
1363+ void * checkval , uint32 flags , ExecPhraseData * data ,
13641364 bool (* chkcond ) (void * , QueryOperand * , ExecPhraseData * ))
13651365{
13661366 /* since this function recurses, it could be driven to stack overflow */
@@ -1382,18 +1382,19 @@ TS_phrase_execute(QueryItem *curitem,
13821382 Assert (curitem -> qoperator .oper == OP_PHRASE );
13831383
13841384 if (!TS_phrase_execute (curitem + curitem -> qoperator .left ,
1385- checkval , calcnot , & Ldata , chkcond ))
1385+ checkval , flags , & Ldata , chkcond ))
13861386 return false;
13871387
1388- if (!TS_phrase_execute (curitem + 1 , checkval , calcnot , & Rdata , chkcond ))
1388+ if (!TS_phrase_execute (curitem + 1 , checkval , flags , & Rdata , chkcond ))
13891389 return false;
13901390
13911391 /*
13921392 * 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
13941395 */
13951396 if (Ldata .npos == 0 || Rdata .npos == 0 )
1396- return true;
1397+ return ( flags & TS_EXEC_PHRASE_AS_AND ) ? true : false ;
13971398
13981399 /*
13991400 * Result of the operation is a list of the corresponding positions of
@@ -1498,13 +1499,11 @@ TS_phrase_execute(QueryItem *curitem,
14981499 * chkcond is a callback function used to evaluate each VAL node in the query.
14991500 * checkval can be used to pass information to the callback. TS_execute doesn't
15001501 * do anything with it.
1501- * if calcnot is false, NOT expressions are always evaluated to be true. This
1502- * is used in ranking.
15031502 * It believes that ordinary operators are always closier to root than phrase
15041503 * operator, so, TS_execute() may not take care of lexeme's position at all.
15051504 */
15061505bool
1507- TS_execute (QueryItem * curitem , void * checkval , bool calcnot ,
1506+ TS_execute (QueryItem * curitem , void * checkval , uint32 flags ,
15081507 bool (* chkcond ) (void * checkval , QueryOperand * val , ExecPhraseData * data ))
15091508{
15101509 /* since this function recurses, it could be driven to stack overflow */
@@ -1517,25 +1516,29 @@ TS_execute(QueryItem *curitem, void *checkval, bool calcnot,
15171516 switch (curitem -> qoperator .oper )
15181517 {
15191518 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 );
15221521 else
15231522 return true;
15241523
15251524 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 );
15281527 else
15291528 return false;
15301529
15311530 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 ))
15331532 return true;
15341533 else
1535- return TS_execute (curitem + 1 , checkval , calcnot , chkcond );
1534+ return TS_execute (curitem + 1 , checkval , flags , chkcond );
15361535
15371536 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 );
15391542
15401543 default :
15411544 elog (ERROR , "unrecognized operator: %d" , curitem -> qoperator .oper );
@@ -1633,7 +1636,7 @@ ts_match_vq(PG_FUNCTION_ARGS)
16331636 result = TS_execute (
16341637 GETQUERY (query ),
16351638 & chkval ,
1636- true ,
1639+ TS_EXEC_CALC_NOT ,
16371640 checkcondition_str
16381641 );
16391642
0 commit comments