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

Commite1d70ba

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 parent2eea494 commite1d70ba

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
@@ -1325,12 +1325,13 @@ checkcondition_str(void *checkval, QueryOperand *val, ExecPhraseData *data)
13251325
WordEntry*StopLow=chkval->arrb;
13261326
WordEntry*StopHigh=chkval->arre;
13271327
WordEntry*StopMiddle=StopHigh;
1328-
intdifference=-1;
13291328
boolres= false;
13301329

13311330
/* Loop invariant: StopLow <= val < StopHigh */
13321331
while (StopLow<StopHigh)
13331332
{
1333+
intdifference;
1334+
13341335
StopMiddle=StopLow+ (StopHigh-StopLow) /2;
13351336
difference=tsCompareString(chkval->operand+val->distance,
13361337
val->length,
@@ -1396,6 +1397,11 @@ checkcondition_str(void *checkval, QueryOperand *val, ExecPhraseData *data)
13961397
memcpy(allpos+npos,data->pos,sizeof(WordEntryPos)*data->npos);
13971398
npos+=data->npos;
13981399
}
1400+
else
1401+
{
1402+
/* at loop exit, res must be true if we found matches */
1403+
res= (npos>0);
1404+
}
13991405
}
14001406
else
14011407
{

‎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