Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 79d6d1a

Browse files
committed
Replace TS_execute's TS_EXEC_CALC_NOT flag with TS_EXEC_SKIP_NOT.
It's fairly silly that ignoring NOT subexpressions is TS_execute's default behavior. It's wrong on its face and it encourages errors of omission. Moreover, the only two remaining callers that aren't specifying CALC_NOT are in ts_headline calculations, and it's very arguable that those are bugs: if you've specified "!foo" in your query, why would you want to get a headline that includes "foo"? Hence, rip that out and change the default behavior to be to calculate NOT accurately. As a concession to the slim chance that there is still somebody somewhere who needs the incorrect behavior, provide a new SKIP_NOT flag to explicitly request that. Back-patch into v13, mainly because it seems better to change this at the same time as the previous commit's rejiggering of TS_execute related APIs. Any outside callers affected by this change are probably also affected by that one. Discussion: https://postgr.es/m/CALT9ZEE-aLotzBg-pOp2GFTesGWVYzXA3=mZKzRDa_OKnLF7Mg@mail.gmail.com
1 parent 2f2007f commit 79d6d1a

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

src/backend/utils/adt/tsginidx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ gin_tsquery_consistent(PG_FUNCTION_ARGS)
248248

249249
res = TS_execute(GETQUERY(query),
250250
&gcv,
251-
TS_EXEC_CALC_NOT | TS_EXEC_PHRASE_NO_POS,
251+
TS_EXEC_PHRASE_NO_POS,
252252
checkcondition_gin);
253253
}
254254

@@ -286,7 +286,7 @@ gin_tsquery_triconsistent(PG_FUNCTION_ARGS)
286286

287287
if (TS_execute(GETQUERY(query),
288288
&gcv,
289-
TS_EXEC_CALC_NOT | TS_EXEC_PHRASE_NO_POS,
289+
TS_EXEC_PHRASE_NO_POS,
290290
checkcondition_gin))
291291
res = recheck ? GIN_MAYBE : GIN_TRUE;
292292
}

src/backend/utils/adt/tsgistidx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ gtsvector_consistent(PG_FUNCTION_ARGS)
348348

349349
PG_RETURN_BOOL(TS_execute(GETQUERY(query),
350350
key,
351-
TS_EXEC_PHRASE_NO_POS | TS_EXEC_CALC_NOT,
351+
TS_EXEC_PHRASE_NO_POS,
352352
checkcondition_bit));
353353
}
354354
else
@@ -359,7 +359,7 @@ gtsvector_consistent(PG_FUNCTION_ARGS)
359359
chkval.arre = chkval.arrb + ARRNELEM(key);
360360
PG_RETURN_BOOL(TS_execute(GETQUERY(query),
361361
(void *) &chkval,
362-
TS_EXEC_PHRASE_NO_POS | TS_EXEC_CALC_NOT,
362+
TS_EXEC_PHRASE_NO_POS,
363363
checkcondition_arr));
364364
}
365365
}

src/backend/utils/adt/tsrank.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ Cover(DocRepresentation *doc, int len, QueryRepresentation *qr, CoverExt *ext)
697697
fillQueryRepresentationData(qr, ptr);
698698

699699
if (TS_execute(GETQUERY(qr->query), (void *) qr,
700-
TS_EXEC_CALC_NOT, checkcondition_QueryOperand))
700+
TS_EXEC_EMPTY, checkcondition_QueryOperand))
701701
{
702702
if (WEP_GETPOS(ptr->pos) < ext->p)
703703
{

src/backend/utils/adt/tsvector_op.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,9 +1627,9 @@ TS_phrase_execute(QueryItem *curitem, void *arg, uint32 flags,
16271627
* We need not touch data->width, since a NOT operation does not
16281628
* change the match width.
16291629
*/
1630-
if (!(flags & TS_EXEC_CALC_NOT))
1630+
if (flags & TS_EXEC_SKIP_NOT)
16311631
{
1632-
/* without CALC_NOT, report NOT as "match everywhere" */
1632+
/* with SKIP_NOT, report NOT as "match everywhere" */
16331633
Assert(data->npos == 0 && !data->negate);
16341634
data->negate = true;
16351635
return TS_YES;
@@ -1875,7 +1875,7 @@ TS_execute_recurse(QueryItem *curitem, void *arg, uint32 flags,
18751875
switch (curitem->qoperator.oper)
18761876
{
18771877
case OP_NOT:
1878-
if (!(flags & TS_EXEC_CALC_NOT))
1878+
if (flags & TS_EXEC_SKIP_NOT)
18791879
return TS_YES;
18801880
switch (TS_execute_recurse(curitem + 1, arg, flags, chkcond))
18811881
{
@@ -2038,7 +2038,7 @@ ts_match_vq(PG_FUNCTION_ARGS)
20382038
chkval.operand = GETOPERAND(query);
20392039
result = TS_execute(GETQUERY(query),
20402040
&chkval,
2041-
TS_EXEC_CALC_NOT,
2041+
TS_EXEC_EMPTY,
20422042
checkcondition_str);
20432043

20442044
PG_FREE_IF_COPY(val, 0);

src/include/tsearch/ts_utils.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,12 @@ typedef TSTernaryValue (*TSExecuteCallback) (void *arg, QueryOperand *val,
183183
*/
184184
#define TS_EXEC_EMPTY (0x00)
185185
/*
186-
* If TS_EXEC_CALC_NOT is not set, then NOT expressions are automatically
187-
* evaluated to be true. Useful in cases where NOT isn't important (ranking).
186+
* If TS_EXEC_SKIP_NOT is set, then NOT sub-expressions are automatically
187+
* evaluated to be true. This was formerly the default behavior. It's now
188+
* deprecated because it tends to give silly answers, but some applications
189+
* might still have a use for it.
188190
*/
189-
#define TS_EXEC_CALC_NOT (0x01)
191+
#define TS_EXEC_SKIP_NOT (0x01)
190192
/*
191193
* If TS_EXEC_PHRASE_NO_POS is set, allow OP_PHRASE to be executed lossily
192194
* in the absence of position information: a true result indicates that the

0 commit comments

Comments
 (0)