Skip to content

Commit db89f0e

Browse files
committed
Fix YA text phrase search bug.
checkcondition_str() failed to report multiple matches for a prefix pattern correctly: it would dutifully merge the match positions, but then after exiting that loop, if the last prefix-matching word had had no suitable positions, it would report there were no matches. The upshot would be failing to recognize a match that the query should match. It looks like you need all of these conditions to see the bug: * a phrase search (else we don't ask for match position details) * a prefix search item (else we don't get to this code) * a weight restriction (else checkclass_str won't fail) Noted while investigating a problem report from Pavel Borisov, though this is distinct from the issue he was on about. Back-patch to 9.6 where phrase search was added.
1 parent b2fd8eb commit db89f0e

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/backend/utils/adt/tsvector_op.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,12 +1276,13 @@ checkcondition_str(void *checkval, QueryOperand *val, ExecPhraseData *data)
12761276
WordEntry *StopLow = chkval->arrb;
12771277
WordEntry *StopHigh = chkval->arre;
12781278
WordEntry *StopMiddle = StopHigh;
1279-
int difference = -1;
12801279
bool res = false;
12811280

12821281
/* Loop invariant: StopLow <= val < StopHigh */
12831282
while (StopLow < StopHigh)
12841283
{
1284+
int difference;
1285+
12851286
StopMiddle = StopLow + (StopHigh - StopLow) / 2;
12861287
difference = tsCompareString(chkval->operand + val->distance,
12871288
val->length,
@@ -1347,6 +1348,11 @@ checkcondition_str(void *checkval, QueryOperand *val, ExecPhraseData *data)
13471348
memcpy(allpos + npos, data->pos, sizeof(WordEntryPos) * data->npos);
13481349
npos += data->npos;
13491350
}
1351+
else
1352+
{
1353+
/* at loop exit, res must be true if we found matches */
1354+
res = (npos > 0);
1355+
}
13501356
}
13511357
else
13521358
{

src/test/regress/expected/tstypes.out

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,24 @@ SELECT 'a b:89 ca:23A,64c cb:80b d:34c'::tsvector @@ 'd:AC & c:*B' as "true";
533533
t
534534
(1 row)
535535

536+
SELECT 'wa:1D wb:2A'::tsvector @@ 'w:*D & w:*A'::tsquery as "true";
537+
true
538+
------
539+
t
540+
(1 row)
541+
542+
SELECT 'wa:1D wb:2A'::tsvector @@ 'w:*D <-> w:*A'::tsquery as "true";
543+
true
544+
------
545+
t
546+
(1 row)
547+
548+
SELECT 'wa:1A wb:2D'::tsvector @@ 'w:*D <-> w:*A'::tsquery as "false";
549+
false
550+
-------
551+
f
552+
(1 row)
553+
536554
SELECT 'supernova'::tsvector @@ 'super'::tsquery AS "false";
537555
false
538556
-------

src/test/regress/sql/tstypes.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ SELECT 'a b:89 ca:23A,64b d:34c'::tsvector @@ 'd:AC & c:*CB' as "true";
101101
SELECT 'a b:89 ca:23A,64b cb:80c d:34c'::tsvector @@ 'd:AC & c:*C' as "true";
102102
SELECT 'a b:89 ca:23A,64c cb:80b d:34c'::tsvector @@ 'd:AC & c:*C' as "true";
103103
SELECT 'a b:89 ca:23A,64c cb:80b d:34c'::tsvector @@ 'd:AC & c:*B' as "true";
104+
SELECT 'wa:1D wb:2A'::tsvector @@ 'w:*D & w:*A'::tsquery as "true";
105+
SELECT 'wa:1D wb:2A'::tsvector @@ 'w:*D <-> w:*A'::tsquery as "true";
106+
SELECT 'wa:1A wb:2D'::tsvector @@ 'w:*D <-> w:*A'::tsquery as "false";
104107

105108
SELECT 'supernova'::tsvector @@ 'super'::tsquery AS "false";
106109
SELECT 'supeanova supernova'::tsvector @@ 'super'::tsquery AS "false";

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy