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

Commit56a8296

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 parentd872e1b commit56a8296

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
@@ -439,7 +439,7 @@ gettoken_query_websearch(TSQueryParserState state, int8 *operator,
439439
}
440440
elseif (ISOPERATOR(state->buf))
441441
{
442-
/*or else gettoken_tsvector() will raise an error */
442+
/*ignore, else gettoken_tsvector() will raise an error */
443443
state->buf++;
444444
state->state=WAITOPERAND;
445445
continue;
@@ -476,31 +476,27 @@ gettoken_query_websearch(TSQueryParserState state, int8 *operator,
476476
break;
477477

478478
caseWAITOPERATOR:
479-
if (t_iseq(state->buf,'"'))
479+
if (*state->buf=='\0')
480480
{
481-
/*
482-
* put implicit AND after an operand and handle this quote
483-
* in WAITOPERAND
484-
*/
485-
state->state=WAITOPERAND;
486-
*operator=OP_AND;
487-
returnPT_OPR;
481+
returnPT_END;
488482
}
489483
elseif (parse_or_operator(state))
490484
{
491485
state->state=WAITOPERAND;
492486
*operator=OP_OR;
493487
returnPT_OPR;
494488
}
495-
elseif (*state->buf=='\0')
489+
elseif (ISOPERATOR(state->buf))
496490
{
497-
returnPT_END;
491+
/* ignore other operators in this state too */
492+
state->buf++;
493+
continue;
498494
}
499495
elseif (!t_isspace(state->buf))
500496
{
501-
/* put implicit AND after an operand */
502-
*operator=OP_AND;
497+
/* insert implicit AND between operands */
503498
state->state=WAITOPERAND;
499+
*operator=OP_AND;
504500
returnPT_OPR;
505501
}
506502
break;

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

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

2679+
-- parens are ignored, too
26792680
select websearch_to_tsquery('simple', 'abc (pg or class)');
26802681
websearch_to_tsquery
26812682
------------------------
26822683
'abc' & 'pg' | 'class'
26832684
(1 row)
26842685

2686+
select websearch_to_tsquery('simple', '(foo bar) or (ding dong)');
2687+
websearch_to_tsquery
2688+
---------------------------------
2689+
'foo' & 'bar' | 'ding' & 'dong'
2690+
(1 row)
2691+
26852692
-- NOT is ignored in quotes
26862693
select websearch_to_tsquery('english', 'My brand new smartphone');
26872694
websearch_to_tsquery

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,10 @@ select websearch_to_tsquery('simple', ':');
818818
select websearch_to_tsquery('simple','abc & def');
819819
select websearch_to_tsquery('simple','abc | def');
820820
select websearch_to_tsquery('simple','abc <-> def');
821+
822+
-- parens are ignored, too
821823
select websearch_to_tsquery('simple','abc (pg or class)');
824+
select websearch_to_tsquery('simple','(foo bar) or (ding dong)');
822825

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp