Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdb89f0e

Browse files
committed
Fix YA text phrase search bug.
checkcondition_str() failed to report multiple matches for a prefixpattern correctly: it would dutifully merge the match positions, butthen after exiting that loop, if the last prefix-matching word hadhad no suitable positions, it would report there were no matches.The upshot would be failing to recognize a match that the queryshould 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 parentb2fd8eb commitdb89f0e

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-
intdifference=-1;
12801279
boolres= false;
12811280

12821281
/* Loop invariant: StopLow <= val < StopHigh */
12831282
while (StopLow<StopHigh)
12841283
{
1284+
intdifference;
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'::tsqueryas"true";
105+
SELECT'wa:1D wb:2A'::tsvector @@'w:*D <-> w:*A'::tsqueryas"true";
106+
SELECT'wa:1A wb:2D'::tsvector @@'w:*D <-> w:*A'::tsqueryas"false";
104107

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp