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

Commitc7de5a6

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 parent1fa46db commitc7de5a6

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ gettoken_query_websearch(TSQueryParserState state, int8 *operator,
433433
}
434434
elseif (ISOPERATOR(state->buf))
435435
{
436-
/*or else gettoken_tsvector() will raise an error */
436+
/*ignore, else gettoken_tsvector() will raise an error */
437437
state->buf++;
438438
state->state=WAITOPERAND;
439439
continue;
@@ -492,6 +492,12 @@ gettoken_query_websearch(TSQueryParserState state, int8 *operator,
492492
*operator=OP_OR;
493493
returnPT_OPR;
494494
}
495+
elseif (ISOPERATOR(state->buf))
496+
{
497+
/* ignore other operators in this state too */
498+
state->buf++;
499+
continue;
500+
}
495501
elseif (*state->buf=='\0')
496502
{
497503
returnPT_END;

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

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

2542+
-- parens are ignored, too
25422543
select websearch_to_tsquery('simple', 'abc (pg or class)');
25432544
websearch_to_tsquery
25442545
------------------------
25452546
'abc' & 'pg' | 'class'
25462547
(1 row)
25472548

2549+
select websearch_to_tsquery('simple', '(foo bar) or (ding dong)');
2550+
websearch_to_tsquery
2551+
---------------------------------
2552+
'foo' & 'bar' | 'ding' & 'dong'
2553+
(1 row)
2554+
25482555
-- NOT is ignored in quotes
25492556
select websearch_to_tsquery('english', 'My brand new smartphone');
25502557
websearch_to_tsquery

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,10 @@ select websearch_to_tsquery('simple', ':');
727727
select websearch_to_tsquery('simple','abc & def');
728728
select websearch_to_tsquery('simple','abc | def');
729729
select websearch_to_tsquery('simple','abc <-> def');
730+
731+
-- parens are ignored, too
730732
select websearch_to_tsquery('simple','abc (pg or class)');
733+
select websearch_to_tsquery('simple','(foo bar) or (ding dong)');
731734

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp