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

Commit6943a94

Browse files
committed
Tsvector editing functions
Adds several tsvector editting function: convert tsvector to/from text array,set weight for given lexemes, delete lexeme(s), unnest, filter lexemeswith given weightsAuthor: Stas Kelvich with some editorization by meReviewers: Tomas Vondram, Teodor Sigaev
1 parent49635d7 commit6943a94

File tree

7 files changed

+933
-18
lines changed

7 files changed

+933
-18
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9211,13 +9211,26 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
92119211
<indexterm>
92129212
<primary>setweight</primary>
92139213
</indexterm>
9214-
<literal><function>setweight(<type>tsvector</>, <type>"char"</>)</function></literal>
9214+
<literal><function>setweight(<replaceable class="PARAMETER">vector</replaceable> <type>tsvector</>, <replaceable class="PARAMETER">weight</replaceable> <type>"char"</>)</function></literal>
92159215
</entry>
92169216
<entry><type>tsvector</type></entry>
9217-
<entry>assign weight to each element of <type>tsvector</></entry>
9217+
<entry>assign<replaceable class="PARAMETER">weight</replaceable> to each element of <replaceable class="PARAMETER">vector</replaceable></entry>
92189218
<entry><literal>setweight('fat:2,4 cat:3 rat:5B'::tsvector, 'A')</literal></entry>
92199219
<entry><literal>'cat':3A 'fat':2A,4A 'rat':5A</literal></entry>
92209220
</row>
9221+
<row>
9222+
<entry>
9223+
<indexterm>
9224+
<primary>setweight</primary>
9225+
<secondary>setweight by filter</secondary>
9226+
</indexterm>
9227+
<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>
9228+
</entry>
9229+
<entry><type>tsvector</type></entry>
9230+
<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>
9231+
<entry><literal>setweight('fat:2,4 cat:3 rat:5B'::tsvector, 'A', '{cat,rat}')</literal></entry>
9232+
<entry><literal>'cat':3A 'fat':2,4 'rat':5A</literal></entry>
9233+
</row>
92219234
<row>
92229235
<entry>
92239236
<indexterm>
@@ -9230,6 +9243,80 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
92309243
<entry><literal>strip('fat:2,4 cat:3 rat:5A'::tsvector)</literal></entry>
92319244
<entry><literal>'cat' 'fat' 'rat'</literal></entry>
92329245
</row>
9246+
<row>
9247+
<entry>
9248+
<indexterm>
9249+
<primary>delete</primary>
9250+
<secondary>delete lemexeme</secondary>
9251+
</indexterm>
9252+
<literal><function>delete(<replaceable class="PARAMETER">vector</replaceable> <type>tsvector</>, <replaceable class="PARAMETER">lexeme</replaceable> <type>text</>)</function></literal>
9253+
</entry>
9254+
<entry><type>tsvector</type></entry>
9255+
<entry>remove given <replaceable class="PARAMETER">lexeme</replaceable> from <replaceable class="PARAMETER">vector</replaceable></entry>
9256+
<entry><literal>delete('fat:2,4 cat:3 rat:5A'::tsvector, 'fat')</literal></entry>
9257+
<entry><literal>'cat':3 'rat':5A</literal></entry>
9258+
</row>
9259+
<row>
9260+
<entry>
9261+
<indexterm>
9262+
<primary>delete</primary>
9263+
<secondary>delete lemexemes array</secondary>
9264+
</indexterm>
9265+
<literal><function>delete(<replaceable class="PARAMETER">vector</replaceable> <type>tsvector</>, <replaceable class="PARAMETER">lexemes</replaceable> <type>text[]</>)</function></literal>
9266+
</entry>
9267+
<entry><type>tsvector</type></entry>
9268+
<entry>remove any occurrence of lexemes in <replaceable class="PARAMETER">lexemes</replaceable> array from <replaceable class="PARAMETER">vector</replaceable></entry>
9269+
<entry><literal>delete('fat:2,4 cat:3 rat:5A'::tsvector, ARRAY['fat','rat'])</literal></entry>
9270+
<entry><literal>'cat':3</literal></entry>
9271+
</row>
9272+
<row>
9273+
<entry>
9274+
<indexterm>
9275+
<primary>unnest</primary>
9276+
</indexterm>
9277+
<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>
9278+
</entry>
9279+
<entry><type>setof record</type></entry>
9280+
<entry>expand a tsvector to a set of rows</entry>
9281+
<entry><literal>unnest('fat:2,4 cat:3 rat:5A'::tsvector)</literal></entry>
9282+
<entry><literal>(cat,{3},{D}) ...</literal></entry>
9283+
</row>
9284+
<row>
9285+
<entry>
9286+
<indexterm>
9287+
<primary>tsvector_to_array</primary>
9288+
</indexterm>
9289+
<literal><function>tsvector_to_array(<type>tsvector</>)</function></literal>
9290+
</entry>
9291+
<entry><type>text[]</type></entry>
9292+
<entry>convert <type>tsvector</> to array of lexemes</entry>
9293+
<entry><literal>tsvector_to_array('fat:2,4 cat:3 rat:5A'::tsvector)</literal></entry>
9294+
<entry><literal>{cat,fat,rat}</literal></entry>
9295+
</row>
9296+
<row>
9297+
<entry>
9298+
<indexterm>
9299+
<primary>array_to_tsvector</primary>
9300+
</indexterm>
9301+
<literal><function>array_to_tsvector(<type>text[]</>)</function></literal>
9302+
</entry>
9303+
<entry><type>tsvector</type></entry>
9304+
<entry>convert array of lexemes to <type>tsvector</type></entry>
9305+
<entry><literal>array_to_tsvector('{fat,cat,rat}'::text[])</literal></entry>
9306+
<entry><literal>'fat' 'cat' 'rat'</literal></entry>
9307+
</row>
9308+
<row>
9309+
<entry>
9310+
<indexterm>
9311+
<primary>filter</primary>
9312+
</indexterm>
9313+
<literal><function>filter(<replaceable class="PARAMETER">vector</replaceable> <type>tsvector</>, <replaceable class="PARAMETER">weights</replaceable> <type>"char"[]</>)</function></literal>
9314+
</entry>
9315+
<entry><type>tsvector</type></entry>
9316+
<entry>Select only elements with given <replaceable class="PARAMETER">weights</replaceable> from <replaceable class="PARAMETER">vector</replaceable></entry>
9317+
<entry><literal>filter('fat:2,4 cat:3b rat:5A'::tsvector, '{a,b}')</literal></entry>
9318+
<entry><literal>'cat':3B 'rat':5A</literal></entry>
9319+
</row>
92339320
<row>
92349321
<entry>
92359322
<indexterm>

‎doc/src/sgml/textsearch.sgml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,10 @@ FROM (SELECT id, body, q, ts_rank_cd(ti, q) AS rank
13261326

13271327
</variablelist>
13281328

1329+
<para>
1330+
Full list of <type>tsvector</>-related functions available in <xref linkend="textsearch-functions-table">.
1331+
</para>
1332+
13291333
</sect2>
13301334

13311335
<sect2 id="textsearch-manipulate-tsquery">

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp