Skip to content

Commit 0b9a234

Browse files
committed
Rename tsvector delete() to ts_delete(), and filter() to ts_filter().
The similarity of the original names to SQL keywords seems like a bad idea. Rename them before we're stuck with 'em forever. In passing, minor code and docs cleanup. Discussion: <4875.1462210058@sss.pgh.pa.us>
1 parent 2f38b98 commit 0b9a234

File tree

7 files changed

+128
-128
lines changed

7 files changed

+128
-128
lines changed

doc/src/sgml/func.sgml

Lines changed: 65 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -9177,6 +9177,18 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
91779177
</row>
91789178
</thead>
91799179
<tbody>
9180+
<row>
9181+
<entry>
9182+
<indexterm>
9183+
<primary>array_to_tsvector</primary>
9184+
</indexterm>
9185+
<literal><function>array_to_tsvector(<type>text[]</>)</function></literal>
9186+
</entry>
9187+
<entry><type>tsvector</type></entry>
9188+
<entry>convert array of lexemes to <type>tsvector</type></entry>
9189+
<entry><literal>array_to_tsvector('{fat,cat,rat}'::text[])</literal></entry>
9190+
<entry><literal>'fat' 'cat' 'rat'</literal></entry>
9191+
</row>
91809192
<row>
91819193
<entry>
91829194
<indexterm>
@@ -9267,10 +9279,10 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
92679279
<primary>setweight</primary>
92689280
<secondary>setweight for specific lexeme(s)</secondary>
92699281
</indexterm>
9270-
<literal><function>setweight(<replaceable class="PARAMETER">vector</replaceable> <type>tsvector</>, <replaceable class="PARAMETER">weight</replaceable> <type>"char"</>, <replaceable class="PARAMETER">lexemes</replaceable> <type>"text"[]</>)</function></literal>
9282+
<literal><function>setweight(<replaceable class="PARAMETER">vector</replaceable> <type>tsvector</>, <replaceable class="PARAMETER">weight</replaceable> <type>"char"</>, <replaceable class="PARAMETER">lexemes</replaceable> <type>text[]</>)</function></literal>
92719283
</entry>
92729284
<entry><type>tsvector</type></entry>
9273-
<entry>assign <replaceable class="PARAMETER">weight</replaceable> to elements of <replaceable class="PARAMETER">vector</replaceable> that are listed in <replaceable class="PARAMETER">lexemes</replaceable> array</entry>
9285+
<entry>assign <replaceable class="PARAMETER">weight</replaceable> to elements of <replaceable class="PARAMETER">vector</replaceable> that are listed in <replaceable class="PARAMETER">lexemes</replaceable></entry>
92749286
<entry><literal>setweight('fat:2,4 cat:3 rat:5B'::tsvector, 'A', '{cat,rat}')</literal></entry>
92759287
<entry><literal>'cat':3A 'fat':2,4 'rat':5A</literal></entry>
92769288
</row>
@@ -9289,100 +9301,61 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
92899301
<row>
92909302
<entry>
92919303
<indexterm>
9292-
<primary>delete</primary>
9293-
<secondary>delete lexeme(s) from tsvector</secondary>
9304+
<primary>to_tsquery</primary>
92949305
</indexterm>
9295-
<literal><function>delete(<replaceable class="PARAMETER">vector</replaceable> <type>tsvector</>, <replaceable class="PARAMETER">lexeme</replaceable> <type>text</>)</function></literal>
9296-
</entry>
9297-
<entry><type>tsvector</type></entry>
9298-
<entry>remove given <replaceable class="PARAMETER">lexeme</replaceable> from <replaceable class="PARAMETER">vector</replaceable></entry>
9299-
<entry><literal>delete('fat:2,4 cat:3 rat:5A'::tsvector, 'fat')</literal></entry>
9300-
<entry><literal>'cat':3 'rat':5A</literal></entry>
9301-
</row>
9302-
<row>
9303-
<entry>
9304-
<!-- previous indexterm entry covers this too -->
9305-
<literal><function>delete(<replaceable class="PARAMETER">vector</replaceable> <type>tsvector</>, <replaceable class="PARAMETER">lexemes</replaceable> <type>text[]</>)</function></literal>
9306+
<literal><function>to_tsquery(<optional> <replaceable class="PARAMETER">config</> <type>regconfig</> , </optional> <replaceable class="PARAMETER">query</> <type>text</type>)</function></literal>
93069307
</entry>
9307-
<entry><type>tsvector</type></entry>
9308-
<entry>remove any occurrence of lexemes in <replaceable class="PARAMETER">lexemes</replaceable> array from <replaceable class="PARAMETER">vector</replaceable></entry>
9309-
<entry><literal>delete('fat:2,4 cat:3 rat:5A'::tsvector, ARRAY['fat','rat'])</literal></entry>
9310-
<entry><literal>'cat':3</literal></entry>
9308+
<entry><type>tsquery</type></entry>
9309+
<entry>normalize words and convert to <type>tsquery</></entry>
9310+
<entry><literal>to_tsquery('english', 'The &amp; Fat &amp; Rats')</literal></entry>
9311+
<entry><literal>'fat' &amp; 'rat'</literal></entry>
93119312
</row>
93129313
<row>
93139314
<entry>
93149315
<indexterm>
9315-
<primary>unnest</primary>
9316-
<secondary>for tsvector</secondary>
9316+
<primary>to_tsvector</primary>
93179317
</indexterm>
9318-
<literal><function>unnest(<type>tsvector</>, OUT <replaceable class="PARAMETER">lexeme</> <type>text</>, OUT <replaceable class="PARAMETER">positions</> <type>smallint[]</>, OUT <replaceable class="PARAMETER">weights</> <type>text</>)</function></literal>
9318+
<literal><function>to_tsvector(<optional> <replaceable class="PARAMETER">config</> <type>regconfig</> , </optional> <replaceable class="PARAMETER">document</> <type>text</type>)</function></literal>
93199319
</entry>
9320-
<entry><type>setof record</type></entry>
9321-
<entry>expand a tsvector to a set of rows</entry>
9322-
<entry><literal>unnest('fat:2,4 cat:3 rat:5A'::tsvector)</literal></entry>
9323-
<entry><literal>(cat,{3},{D}) ...</literal></entry>
9320+
<entry><type>tsvector</type></entry>
9321+
<entry>reduce document text to <type>tsvector</></entry>
9322+
<entry><literal>to_tsvector('english', 'The Fat Rats')</literal></entry>
9323+
<entry><literal>'fat':2 'rat':3</literal></entry>
93249324
</row>
93259325
<row>
93269326
<entry>
93279327
<indexterm>
9328-
<primary>tsvector_to_array</primary>
9328+
<primary>ts_delete</primary>
93299329
</indexterm>
9330-
<literal><function>tsvector_to_array(<type>tsvector</>)</function></literal>
9330+
<literal><function>ts_delete(<replaceable class="PARAMETER">vector</replaceable> <type>tsvector</>, <replaceable class="PARAMETER">lexeme</replaceable> <type>text</>)</function></literal>
93319331
</entry>
9332-
<entry><type>text[]</type></entry>
9333-
<entry>convert <type>tsvector</> to array of lexemes</entry>
9334-
<entry><literal>tsvector_to_array('fat:2,4 cat:3 rat:5A'::tsvector)</literal></entry>
9335-
<entry><literal>{cat,fat,rat}</literal></entry>
9332+
<entry><type>tsvector</type></entry>
9333+
<entry>remove given <replaceable class="PARAMETER">lexeme</replaceable> from <replaceable class="PARAMETER">vector</replaceable></entry>
9334+
<entry><literal>ts_delete('fat:2,4 cat:3 rat:5A'::tsvector, 'fat')</literal></entry>
9335+
<entry><literal>'cat':3 'rat':5A</literal></entry>
93369336
</row>
93379337
<row>
93389338
<entry>
9339-
<indexterm>
9340-
<primary>array_to_tsvector</primary>
9341-
</indexterm>
9342-
<literal><function>array_to_tsvector(<type>text[]</>)</function></literal>
9339+
<!-- previous indexterm entry covers this too -->
9340+
<literal><function>ts_delete(<replaceable class="PARAMETER">vector</replaceable> <type>tsvector</>, <replaceable class="PARAMETER">lexemes</replaceable> <type>text[]</>)</function></literal>
93439341
</entry>
93449342
<entry><type>tsvector</type></entry>
9345-
<entry>convert array of lexemes to <type>tsvector</type></entry>
9346-
<entry><literal>array_to_tsvector('{fat,cat,rat}'::text[])</literal></entry>
9347-
<entry><literal>'fat' 'cat' 'rat'</literal></entry>
9343+
<entry>remove any occurrence of lexemes in <replaceable class="PARAMETER">lexemes</replaceable> from <replaceable class="PARAMETER">vector</replaceable></entry>
9344+
<entry><literal>ts_delete('fat:2,4 cat:3 rat:5A'::tsvector, ARRAY['fat','rat'])</literal></entry>
9345+
<entry><literal>'cat':3</literal></entry>
93489346
</row>
93499347
<row>
93509348
<entry>
93519349
<indexterm>
9352-
<primary>filter</primary>
9353-
<secondary>for tsvector</secondary>
9350+
<primary>ts_filter</primary>
93549351
</indexterm>
9355-
<literal><function>filter(<replaceable class="PARAMETER">vector</replaceable> <type>tsvector</>, <replaceable class="PARAMETER">weights</replaceable> <type>"char"[]</>)</function></literal>
9352+
<literal><function>ts_filter(<replaceable class="PARAMETER">vector</replaceable> <type>tsvector</>, <replaceable class="PARAMETER">weights</replaceable> <type>"char"[]</>)</function></literal>
93569353
</entry>
93579354
<entry><type>tsvector</type></entry>
93589355
<entry>Select only elements with given <replaceable class="PARAMETER">weights</replaceable> from <replaceable class="PARAMETER">vector</replaceable></entry>
9359-
<entry><literal>filter('fat:2,4 cat:3b rat:5A'::tsvector, '{a,b}')</literal></entry>
9356+
<entry><literal>ts_filter('fat:2,4 cat:3b rat:5A'::tsvector, '{a,b}')</literal></entry>
93609357
<entry><literal>'cat':3B 'rat':5A</literal></entry>
93619358
</row>
9362-
<row>
9363-
<entry>
9364-
<indexterm>
9365-
<primary>to_tsquery</primary>
9366-
</indexterm>
9367-
<literal><function>to_tsquery(<optional> <replaceable class="PARAMETER">config</> <type>regconfig</> , </optional> <replaceable class="PARAMETER">query</> <type>text</type>)</function></literal>
9368-
</entry>
9369-
<entry><type>tsquery</type></entry>
9370-
<entry>normalize words and convert to <type>tsquery</></entry>
9371-
<entry><literal>to_tsquery('english', 'The &amp; Fat &amp; Rats')</literal></entry>
9372-
<entry><literal>'fat' &amp; 'rat'</literal></entry>
9373-
</row>
9374-
<row>
9375-
<entry>
9376-
<indexterm>
9377-
<primary>to_tsvector</primary>
9378-
</indexterm>
9379-
<literal><function>to_tsvector(<optional> <replaceable class="PARAMETER">config</> <type>regconfig</> , </optional> <replaceable class="PARAMETER">document</> <type>text</type>)</function></literal>
9380-
</entry>
9381-
<entry><type>tsvector</type></entry>
9382-
<entry>reduce document text to <type>tsvector</></entry>
9383-
<entry><literal>to_tsvector('english', 'The Fat Rats')</literal></entry>
9384-
<entry><literal>'fat':2 'rat':3</literal></entry>
9385-
</row>
93869359
<row>
93879360
<entry>
93889361
<indexterm>
@@ -9459,6 +9432,18 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
94599432
<entry><literal>tsquery_phrase(to_tsquery('fat'), to_tsquery('cat'), 10)</literal></entry>
94609433
<entry><literal>'fat' &lt;10&gt; 'cat'</literal></entry>
94619434
</row>
9435+
<row>
9436+
<entry>
9437+
<indexterm>
9438+
<primary>tsvector_to_array</primary>
9439+
</indexterm>
9440+
<literal><function>tsvector_to_array(<type>tsvector</>)</function></literal>
9441+
</entry>
9442+
<entry><type>text[]</type></entry>
9443+
<entry>convert <type>tsvector</> to array of lexemes</entry>
9444+
<entry><literal>tsvector_to_array('fat:2,4 cat:3 rat:5A'::tsvector)</literal></entry>
9445+
<entry><literal>{cat,fat,rat}</literal></entry>
9446+
</row>
94629447
<row>
94639448
<entry>
94649449
<indexterm>
@@ -9483,6 +9468,19 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
94839468
<entry><literal>CREATE TRIGGER ... tsvector_update_trigger_column(tsvcol, configcol, title, body)</literal></entry>
94849469
<entry><literal></literal></entry>
94859470
</row>
9471+
<row>
9472+
<entry>
9473+
<indexterm>
9474+
<primary>unnest</primary>
9475+
<secondary>for tsvector</secondary>
9476+
</indexterm>
9477+
<literal><function>unnest(<type>tsvector</>, OUT <replaceable class="PARAMETER">lexeme</> <type>text</>, OUT <replaceable class="PARAMETER">positions</> <type>smallint[]</>, OUT <replaceable class="PARAMETER">weights</> <type>text</>)</function></literal>
9478+
</entry>
9479+
<entry><type>setof record</type></entry>
9480+
<entry>expand a tsvector to a set of rows</entry>
9481+
<entry><literal>unnest('fat:2,4 cat:3 rat:5A'::tsvector)</literal></entry>
9482+
<entry><literal>(cat,{3},{D}) ...</literal></entry>
9483+
</row>
94869484
</tbody>
94879485
</tgroup>
94889486
</table>

doc/src/sgml/textsearch.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,8 @@ FROM (SELECT id, body, q, ts_rank_cd(ti, q) AS rank
14121412
</variablelist>
14131413

14141414
<para>
1415-
Full list of <type>tsvector</>-related functions available in <xref linkend="textsearch-functions-table">.
1415+
A full list of <type>tsvector</>-related functions is available
1416+
in <xref linkend="textsearch-functions-table">.
14161417
</para>
14171418

14181419
</sect2>

src/backend/utils/adt/tsvector_op.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ tsvector_delete_by_indices(TSVector tsv, int *indices_to_delete,
506506

507507
/*
508508
* Delete given lexeme from tsvector.
509-
* Implementation of user-level delete(tsvector, text).
509+
* Implementation of user-level ts_delete(tsvector, text).
510510
*/
511511
Datum
512512
tsvector_delete_str(PG_FUNCTION_ARGS)
@@ -530,7 +530,7 @@ tsvector_delete_str(PG_FUNCTION_ARGS)
530530

531531
/*
532532
* Delete given array of lexemes from tsvector.
533-
* Implementation of user-level delete(tsvector, text[]).
533+
* Implementation of user-level ts_delete(tsvector, text[]).
534534
*/
535535
Datum
536536
tsvector_delete_arr(PG_FUNCTION_ARGS)
@@ -757,7 +757,7 @@ array_to_tsvector(PG_FUNCTION_ARGS)
757757
}
758758

759759
/*
760-
* Leave only elements with given weights from tsvector.
760+
* ts_filter(): keep only lexemes with given weights in tsvector.
761761
*/
762762
Datum
763763
tsvector_filter(PG_FUNCTION_ARGS)
@@ -771,15 +771,15 @@ tsvector_filter(PG_FUNCTION_ARGS)
771771
*dataout;
772772
Datum *dweights;
773773
bool *nulls;
774-
int nweigths;
774+
int nweights;
775775
int i, j;
776776
int cur_pos = 0;
777777
char mask = 0;
778778

779779
deconstruct_array(weights, CHAROID, 1, true, 'c',
780-
&dweights, &nulls, &nweigths);
780+
&dweights, &nulls, &nweights);
781781

782-
for (i = 0; i < nweigths; i++)
782+
for (i = 0; i < nweights; i++)
783783
{
784784
char char_weight;
785785

@@ -804,8 +804,9 @@ tsvector_filter(PG_FUNCTION_ARGS)
804804
mask = mask | 1;
805805
break;
806806
default:
807-
/* internal error */
808-
elog(ERROR, "unrecognized weight: %c", char_weight);
807+
ereport(ERROR,
808+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
809+
errmsg("unrecognized weight: \"%c\"", char_weight)));
809810
}
810811
}
811812

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 201605031
56+
#define CATALOG_VERSION_NO 201605051
5757

5858
#endif

src/include/catalog/pg_proc.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4539,18 +4539,18 @@ DESCR("set given weight for whole tsvector");
45394539
DATA(insert OID = 3320 ( setweight PGNSP PGUID 12 1 0 0 0 f f f f t f i s 3 0 3614 "3614 18 1009" _null_ _null_ _null_ _null_ _null_ tsvector_setweight_by_filter _null_ _null_ _null_ ));
45404540
DESCR("set given weight for given lexemes");
45414541
DATA(insert OID = 3625 ( tsvector_concat PGNSP PGUID 12 1 0 0 0 f f f f t f i s 2 0 3614 "3614 3614" _null_ _null_ _null_ _null_ _null_ tsvector_concat _null_ _null_ _null_ ));
4542-
DATA(insert OID = 3321 ( delete PGNSP PGUID 12 1 0 0 0 f f f f t f i s 2 0 3614 "3614 25" _null_ _null_ _null_ _null_ _null_ tsvector_delete_str _null_ _null_ _null_ ));
4542+
DATA(insert OID = 3321 ( ts_delete PGNSP PGUID 12 1 0 0 0 f f f f t f i s 2 0 3614 "3614 25" _null_ _null_ _null_ _null_ _null_ tsvector_delete_str _null_ _null_ _null_ ));
45434543
DESCR("delete lexeme");
4544-
DATA(insert OID = 3323 ( delete PGNSP PGUID 12 1 0 0 0 f f f f t f i s 2 0 3614 "3614 1009" _null_ _null_ _null_ _null_ _null_ tsvector_delete_arr _null_ _null_ _null_ ));
4544+
DATA(insert OID = 3323 ( ts_delete PGNSP PGUID 12 1 0 0 0 f f f f t f i s 2 0 3614 "3614 1009" _null_ _null_ _null_ _null_ _null_ tsvector_delete_arr _null_ _null_ _null_ ));
45454545
DESCR("delete given lexemes");
45464546
DATA(insert OID = 3322 ( unnest PGNSP PGUID 12 1 10 0 0 f f f f t t i s 1 0 2249 "3614" "{3614,25,1005,1009}" "{i,o,o,o}" "{tsvector,lexeme,positions,weights}" _null_ _null_ tsvector_unnest _null_ _null_ _null_ ));
45474547
DESCR("expand tsvector to set of rows");
45484548
DATA(insert OID = 3326 ( tsvector_to_array PGNSP PGUID 12 1 0 0 0 f f f f t f i s 1 0 1009 "3614" _null_ _null_ _null_ _null_ _null_ tsvector_to_array _null_ _null_ _null_ ));
4549-
DESCR("convert to lexeme's array");
4549+
DESCR("convert tsvector to array of lexemes");
45504550
DATA(insert OID = 3327 ( array_to_tsvector PGNSP PGUID 12 1 0 0 0 f f f f t f i s 1 0 3614 "1009" _null_ _null_ _null_ _null_ _null_ array_to_tsvector _null_ _null_ _null_ ));
4551-
DESCR("build tsvector from lexeme's array");
4552-
DATA(insert OID = 3319 ( filter PGNSP PGUID 12 1 0 0 0 f f f f t f i s 2 0 3614 "3614 1002" _null_ _null_ _null_ _null_ _null_ tsvector_filter _null_ _null_ _null_ ));
4553-
DESCR("returns tsvector that contain only postings with given weights");
4551+
DESCR("build tsvector from array of lexemes");
4552+
DATA(insert OID = 3319 ( ts_filter PGNSP PGUID 12 1 0 0 0 f f f f t f i s 2 0 3614 "3614 1002" _null_ _null_ _null_ _null_ _null_ tsvector_filter _null_ _null_ _null_ ));
4553+
DESCR("delete lexemes that do not have one of the given weights");
45544554

45554555
DATA(insert OID = 3634 ( ts_match_vq PGNSP PGUID 12 1 0 0 0 f f f f t f i s 2 0 16 "3614 3615" _null_ _null_ _null_ _null_ _null_ ts_match_vq _null_ _null_ _null_ ));
45564556
DATA(insert OID = 3635 ( ts_match_qv PGNSP PGUID 12 1 0 0 0 f f f f t f i s 2 0 16 "3615 3614" _null_ _null_ _null_ _null_ _null_ ts_match_qv _null_ _null_ _null_ ));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy