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

Commit455ed7d

Browse files
author
Aleksandr Parfenov
committed
FTS: Add ability to mix comma-separated syntax with other constructions
1 parent5721101 commit455ed7d

File tree

5 files changed

+65
-40
lines changed

5 files changed

+65
-40
lines changed

‎src/backend/parser/gram.y

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,9 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
589589

590590
%type<ival>dictionary_map_set_expr_operator
591591
%type<dmapelem>dictionary_map_dictdictionary_map_command_expr_paren
592-
dictionary_map_set_exprdictionary_map_case
592+
dictionary_configdictionary_map_case
593593
dictionary_map_actionopt_dictionary_map_case_else
594-
dictionary_configdictionary_config_comma
594+
dictionary_config_comma
595595

596596
%type<node>merge_when_clauseopt_and_condition
597597
%type<list>merge_when_list
@@ -10456,23 +10456,6 @@ dictionary_config_comma:
1045610456
}
1045710457
;
1045810458

10459-
dictionary_config:
10460-
dictionary_map_set_expr {$$ =$1; }
10461-
|dictionary_map_dict','dictionary_config_comma
10462-
{
10463-
DictMapExprElem *n = makeNode(DictMapExprElem);
10464-
DictMapElem *r = makeNode(DictMapElem);
10465-
10466-
n->left =$1;
10467-
n->oper = TSMAP_OP_COMMA;
10468-
n->right =$3;
10469-
10470-
r->kind = DICT_MAP_EXPRESSION;
10471-
r->data = n;
10472-
$$ = r;
10473-
}
10474-
;
10475-
1047610459
dictionary_map_action:
1047710460
KEEP
1047810461
{
@@ -10481,16 +10464,16 @@ dictionary_map_action:
1048110464
n->data =NULL;
1048210465
$$ = n;
1048310466
}
10484-
|dictionary_map_set_expr {$$ =$1; }
10467+
|dictionary_config {$$ =$1; }
1048510468
;
1048610469

1048710470
opt_dictionary_map_case_else:
10488-
ELSEdictionary_map_set_expr {$$ =$2; }
10471+
ELSEdictionary_config {$$ =$2; }
1048910472
| {$$ =NULL; }
1049010473
;
1049110474

1049210475
dictionary_map_case:
10493-
CASEdictionary_map_set_exprWHENopt_dictionary_map_noMATCHTHENdictionary_map_actionopt_dictionary_map_case_elseEND_P
10476+
CASEdictionary_configWHENopt_dictionary_map_noMATCHTHENdictionary_map_actionopt_dictionary_map_case_elseEND_P
1049410477
{
1049510478
DictMapCase *n = makeNode(DictMapCase);
1049610479
DictMapElem *r = makeNode(DictMapElem);
@@ -10513,9 +10496,9 @@ dictionary_map_set_expr_operator:
1051310496
|MAP {$$ = TSMAP_OP_MAP; }
1051410497
;
1051510498

10516-
dictionary_map_set_expr:
10499+
dictionary_config:
1051710500
dictionary_map_command_expr_paren {$$ =$1; }
10518-
|dictionary_map_set_exprdictionary_map_set_expr_operatordictionary_map_command_expr_paren
10501+
|dictionary_configdictionary_map_set_expr_operatordictionary_map_command_expr_paren
1051910502
{
1052010503
DictMapExprElem *n = makeNode(DictMapExprElem);
1052110504
DictMapElem *r = makeNode(DictMapElem);
@@ -10531,9 +10514,9 @@ dictionary_map_set_expr:
1053110514
;
1053210515

1053310516
dictionary_map_command_expr_paren:
10534-
'('dictionary_map_set_expr')'{$$ =$2; }
10535-
|dictionary_map_dict{$$ =$1; }
10517+
'('dictionary_config')'{$$ =$2; }
1053610518
|dictionary_map_case{$$ =$1; }
10519+
|dictionary_config_comma{$$ =$1; }
1053710520
;
1053810521

1053910522
dictionary_map_dict:

‎src/backend/tsearch/ts_configmap.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,18 @@ static void
150150
TSMapPrintExpression(TSMapExpression*expression,StringInforesult)
151151
{
152152

153-
if (expression->left)
154-
TSMapPrintElement(expression->left,result);
153+
Assert(expression->left);
154+
if (expression->left->type==TSMAP_EXPRESSION&&
155+
expression->left->value.objectExpression->operator!=expression->operator)
156+
{
157+
appendStringInfoChar(result,'(');
158+
}
159+
TSMapPrintElement(expression->left,result);
160+
if (expression->left->type==TSMAP_EXPRESSION&&
161+
expression->left->value.objectExpression->operator!=expression->operator)
162+
{
163+
appendStringInfoChar(result,')');
164+
}
155165

156166
switch (expression->operator)
157167
{
@@ -178,8 +188,18 @@ TSMapPrintExpression(TSMapExpression *expression, StringInfo result)
178188
break;
179189
}
180190

181-
if (expression->right)
182-
TSMapPrintElement(expression->right,result);
191+
Assert(expression->right);
192+
if (expression->right->type==TSMAP_EXPRESSION&&
193+
expression->right->value.objectExpression->operator!=expression->operator)
194+
{
195+
appendStringInfoChar(result,'(');
196+
}
197+
TSMapPrintElement(expression->right,result);
198+
if (expression->right->type==TSMAP_EXPRESSION&&
199+
expression->right->value.objectExpression->operator!=expression->operator)
200+
{
201+
appendStringInfoChar(result,')');
202+
}
183203
}
184204

185205
/*

‎src/include/catalog/pg_ts_config_map.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ CATALOG(pg_ts_config_map,3603) BKI_WITHOUT_OIDS
4141
{
4242
Oidmapcfg;/* OID of configuration owning this entry */
4343
int32maptokentype;/* token type from parser */
44+
45+
/*
46+
* mapdicts is the only one variable-length field so it is safe to use
47+
* it directly, without hiding from C interface.
48+
*/
4449
jsonbmapdicts;/* dictionary map Jsonb representation */
4550
}FormData_pg_ts_config_map;
4651

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -679,13 +679,6 @@ SELECT to_tsvector('thesaurus_tst', 'Booking tickets is looking like a booking a
679679
'card':3,10 'invit':2,9 'like':6 'look':5 'order':1,8
680680
(1 row)
681681

682-
ALTER TEXT SEARCH CONFIGURATION thesaurus_tst ALTER MAPPING FOR asciiword WITH english_stem UNION simple;
683-
SELECT to_tsvector('thesaurus_tst', 'The Mysterious Rings of Supernova 1987A');
684-
to_tsvector
685-
--------------------------------------------------------------------------------------
686-
'1987a':6 'mysteri':2 'mysterious':2 'of':4 'ring':3 'rings':3 'supernova':5 'the':1
687-
(1 row)
688-
689682
ALTER TEXT SEARCH CONFIGURATION thesaurus_tst ALTER MAPPING FOR asciiword WITH CASE
690683
thesaurus WHEN MATCH THEN KEEP ELSE english_stem
691684
END;
@@ -826,6 +819,23 @@ SELECT to_tsvector('thesaurus_tst', 'one two books');
826819
'12':1 'book':2
827820
(1 row)
828821

822+
CREATE TEXT SEARCH CONFIGURATION operators_tst (
823+
COPY=thesaurus_tst
824+
);
825+
ALTER TEXT SEARCH CONFIGURATION operators_tst ALTER MAPPING FOR asciiword WITH english_stem UNION simple;
826+
SELECT to_tsvector('operators_tst', 'The Mysterious Rings of Supernova 1987A');
827+
to_tsvector
828+
--------------------------------------------------------------------------------------
829+
'1987a':6 'mysteri':2 'mysterious':2 'of':4 'ring':3 'rings':3 'supernova':5 'the':1
830+
(1 row)
831+
832+
ALTER TEXT SEARCH CONFIGURATION operators_tst ALTER MAPPING FOR asciiword WITH english_stem UNION (synonym, simple);
833+
SELECT to_tsvector('operators_tst', 'The Mysterious Rings of Supernova 1987A Postgres');
834+
to_tsvector
835+
-----------------------------------------------------------------------------------------------------------
836+
'1987a':6 'mysteri':2 'mysterious':2 'of':4 'pgsql':7 'postgr':7 'ring':3 'rings':3 'supernova':5 'the':1
837+
(1 row)
838+
829839
-- invalid: non-lowercase quoted identifiers
830840
CREATE TEXT SEARCH DICTIONARY tsdict_case
831841
(

‎src/test/regress/sql/tsdicts.sql

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,6 @@ SELECT to_tsvector('thesaurus_tst', 'one postgres one two one two three one');
240240
SELECT to_tsvector('thesaurus_tst','Supernovae star is very new star and usually called supernovae (abbreviation SN)');
241241
SELECT to_tsvector('thesaurus_tst','Booking tickets is looking like a booking a tickets');
242242

243-
ALTERTEXT SEARCH CONFIGURATION thesaurus_tst ALTER MAPPING FOR asciiword WITH english_stemUNION simple;
244-
SELECT to_tsvector('thesaurus_tst','The Mysterious Rings of Supernova 1987A');
245-
246243
ALTERTEXT SEARCH CONFIGURATION thesaurus_tst ALTER MAPPING FOR asciiword WITH CASE
247244
thesaurus WHEN MATCH THEN KEEP ELSE english_stem
248245
END;
@@ -277,6 +274,16 @@ SELECT to_tsvector('thesaurus_tst', 'one two');
277274
SELECT to_tsvector('thesaurus_tst','one two three');
278275
SELECT to_tsvector('thesaurus_tst','one two books');
279276

277+
CREATETEXT SEARCH CONFIGURATION operators_tst (
278+
COPY=thesaurus_tst
279+
);
280+
281+
ALTERTEXT SEARCH CONFIGURATION operators_tst ALTER MAPPING FOR asciiword WITH english_stemUNION simple;
282+
SELECT to_tsvector('operators_tst','The Mysterious Rings of Supernova 1987A');
283+
284+
ALTERTEXT SEARCH CONFIGURATION operators_tst ALTER MAPPING FOR asciiword WITH english_stemUNION (synonym, simple);
285+
SELECT to_tsvector('operators_tst','The Mysterious Rings of Supernova 1987A Postgres');
286+
280287
-- invalid: non-lowercase quoted identifiers
281288
CREATETEXT SEARCH DICTIONARY tsdict_case
282289
(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp