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

Commitdf95c1e

Browse files
committed
Fix parsing of ignored operators in websearch_to_tsquery().
The manual says clearly that punctuation in the input ofwebsearch_to_tsquery() is ignored, except for the special casesof dashes and quotes. However, this failed for cases like"(foo bar) or something", or in general an ISOPERATOR characterin front of the "or". We'd switch back to WAITOPERAND state,then ignore the operator character while remaining in that state,and then reach the "or" in WAITOPERAND state which (intentionally)makes us treat it as data.The fix is simple enough: if we see an ISOPERATOR character while inWAITOPERATOR state, we have to skip it while staying in that state.(We don't need to worry about other punctuation characters: those willbe consumed as though they were words, but then rejected by lexizing.)In v14 and up (since commiteb08605) we can simplify the code a bitmore too, because there is no longer a reason for the WAITOPERANDstate to distinguish between quoted and unquoted operands.Per bug #18479 from Manos Emmanouilidis. Back-patch to all supportedbranches.Discussion:https://postgr.es/m/18479-d9b46e2fc242c33e@postgresql.org
1 parent37c5e5f commitdf95c1e

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

‎src/backend/utils/adt/tsquery.c‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ gettoken_query_websearch(TSQueryParserState state, int8 *operator,
420420
}
421421
elseif (ISOPERATOR(state->buf))
422422
{
423-
/*or else gettoken_tsvector() will raise an error */
423+
/*ignore, else gettoken_tsvector() will raise an error */
424424
state->buf++;
425425
state->state=WAITOPERAND;
426426
continue;
@@ -452,31 +452,27 @@ gettoken_query_websearch(TSQueryParserState state, int8 *operator,
452452
break;
453453

454454
caseWAITOPERATOR:
455-
if (t_iseq(state->buf,'"'))
455+
if (*state->buf=='\0')
456456
{
457-
/*
458-
* put implicit AND after an operand and handle this quote
459-
* in WAITOPERAND
460-
*/
461-
state->state=WAITOPERAND;
462-
*operator=OP_AND;
463-
returnPT_OPR;
457+
returnPT_END;
464458
}
465459
elseif (parse_or_operator(state))
466460
{
467461
state->state=WAITOPERAND;
468462
*operator=OP_OR;
469463
returnPT_OPR;
470464
}
471-
elseif (*state->buf=='\0')
465+
elseif (ISOPERATOR(state->buf))
472466
{
473-
returnPT_END;
467+
/* ignore other operators in this state too */
468+
state->buf++;
469+
continue;
474470
}
475471
elseif (!t_isspace(state->buf))
476472
{
477-
/* put implicit AND after an operand */
478-
*operator=OP_AND;
473+
/* insert implicit AND between operands */
479474
state->state=WAITOPERAND;
475+
*operator=OP_AND;
480476
returnPT_OPR;
481477
}
482478
break;

‎src/test/regress/expected/tsearch.out‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,12 +2549,19 @@ select websearch_to_tsquery('simple', 'abc <-> def');
25492549
'abc' & 'def'
25502550
(1 row)
25512551

2552+
-- parens are ignored, too
25522553
select websearch_to_tsquery('simple', 'abc (pg or class)');
25532554
websearch_to_tsquery
25542555
------------------------
25552556
'abc' & 'pg' | 'class'
25562557
(1 row)
25572558

2559+
select websearch_to_tsquery('simple', '(foo bar) or (ding dong)');
2560+
websearch_to_tsquery
2561+
---------------------------------
2562+
'foo' & 'bar' | 'ding' & 'dong'
2563+
(1 row)
2564+
25582565
-- NOT is ignored in quotes
25592566
select websearch_to_tsquery('english', 'My brand new smartphone');
25602567
websearch_to_tsquery

‎src/test/regress/sql/tsearch.sql‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,10 @@ select websearch_to_tsquery('simple', ':');
741741
select websearch_to_tsquery('simple','abc & def');
742742
select websearch_to_tsquery('simple','abc | def');
743743
select websearch_to_tsquery('simple','abc <-> def');
744+
745+
-- parens are ignored, too
744746
select websearch_to_tsquery('simple','abc (pg or class)');
747+
select websearch_to_tsquery('simple','(foo bar) or (ding dong)');
745748

746749
-- NOT is ignored in quotes
747750
select websearch_to_tsquery('english','My brand new smartphone');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp