PostgreSQL Source Code  git master
to_tsany.c File Reference
#include "postgres.h"
#include "common/jsonapi.h"
#include "tsearch/ts_cache.h"
#include "tsearch/ts_utils.h"
#include "utils/builtins.h"
#include "utils/jsonfuncs.h"
Include dependency graph for to_tsany.c:

Go to the source code of this file.

Data Structures

struct  MorphOpaque
 
struct  TSVectorBuildState
 

Typedefs

typedef struct MorphOpaque MorphOpaque
 
typedef struct TSVectorBuildState TSVectorBuildState
 

Functions

static void add_to_tsvector (void *_state, char *elem_value, int elem_len)
 
Datum get_current_ts_config (PG_FUNCTION_ARGS)
 
static int compareWORD (const void *a, const void *b)
 
static int uniqueWORD (ParsedWord *a, int32 l)
 
TSVector make_tsvector (ParsedText *prs)
 
Datum to_tsvector_byid (PG_FUNCTION_ARGS)
 
Datum to_tsvector (PG_FUNCTION_ARGS)
 
static TSVector jsonb_to_tsvector_worker (Oid cfgId, Jsonb *jb, uint32 flags)
 
Datum jsonb_string_to_tsvector_byid (PG_FUNCTION_ARGS)
 
Datum jsonb_string_to_tsvector (PG_FUNCTION_ARGS)
 
Datum jsonb_to_tsvector_byid (PG_FUNCTION_ARGS)
 
Datum jsonb_to_tsvector (PG_FUNCTION_ARGS)
 
static TSVector json_to_tsvector_worker (Oid cfgId, text *json, uint32 flags)
 
Datum json_string_to_tsvector_byid (PG_FUNCTION_ARGS)
 
Datum json_string_to_tsvector (PG_FUNCTION_ARGS)
 
Datum json_to_tsvector_byid (PG_FUNCTION_ARGS)
 
Datum json_to_tsvector (PG_FUNCTION_ARGS)
 
static void pushval_morph (Datum opaque, TSQueryParserState state, char *strval, int lenval, int16 weight, bool prefix)
 
Datum to_tsquery_byid (PG_FUNCTION_ARGS)
 
Datum to_tsquery (PG_FUNCTION_ARGS)
 
Datum plainto_tsquery_byid (PG_FUNCTION_ARGS)
 
Datum plainto_tsquery (PG_FUNCTION_ARGS)
 
Datum phraseto_tsquery_byid (PG_FUNCTION_ARGS)
 
Datum phraseto_tsquery (PG_FUNCTION_ARGS)
 
Datum websearch_to_tsquery_byid (PG_FUNCTION_ARGS)
 
Datum websearch_to_tsquery (PG_FUNCTION_ARGS)
 

Typedef Documentation

◆ MorphOpaque

typedef struct MorphOpaque MorphOpaque

◆ TSVectorBuildState

Function Documentation

◆ add_to_tsvector()

static void add_to_tsvector ( void *  _state,
char *  elem_value,
int  elem_len 
)
static

Definition at line 442 of file to_tsany.c.

References TSVectorBuildState::cfgId, ParsedText::curwords, ParsedText::lenwords, palloc(), parsetext(), ParsedText::pos, TSVectorBuildState::prs, and ParsedText::words.

Referenced by json_to_tsvector_worker(), and jsonb_to_tsvector_worker().

443 {
445  ParsedText *prs = state->prs;
446  int32 prevwords;
447 
448  if (prs->words == NULL)
449  {
450  /*
451  * First time through: initialize words array to a reasonable size.
452  * (parsetext() will realloc it bigger as needed.)
453  */
454  prs->lenwords = 16;
455  prs->words = (ParsedWord *) palloc(sizeof(ParsedWord) * prs->lenwords);
456  prs->curwords = 0;
457  prs->pos = 0;
458  }
459 
460  prevwords = prs->curwords;
461 
462  parsetext(state->cfgId, prs, elem_value, elem_len);
463 
464  /*
465  * If we extracted any words from this JSON element, advance pos to create
466  * an artificial break between elements. This is because we don't want
467  * phrase searches to think that the last word in this element is adjacent
468  * to the first word in the next one.
469  */
470  if (prs->curwords > prevwords)
471  prs->pos += 1;
472 }
int32 lenwords
Definition: ts_utils.h:101
int32 curwords
Definition: ts_utils.h:102
signed int int32
Definition: c.h:429
void parsetext(Oid cfgId, ParsedText *prs, char *buf, int buflen)
Definition: ts_parse.c:354
ParsedWord * words
Definition: ts_utils.h:100
ParsedText * prs
Definition: to_tsany.c:41
Definition: regguts.h:317
int32 pos
Definition: ts_utils.h:103
void * palloc(Size size)
Definition: mcxt.c:950

◆ compareWORD()

static int compareWORD ( const void *  a,
const void *  b 
)
static

Definition at line 58 of file to_tsany.c.

References tsCompareString(), and word().

Referenced by uniqueWORD().

59 {
60  int res;
61 
62  res = tsCompareString(((const ParsedWord *) a)->word, ((const ParsedWord *) a)->len,
63  ((const ParsedWord *) b)->word, ((const ParsedWord *) b)->len,
64  false);
65 
66  if (res == 0)
67  {
68  if (((const ParsedWord *) a)->pos.pos == ((const ParsedWord *) b)->pos.pos)
69  return 0;
70 
71  res = (((const ParsedWord *) a)->pos.pos > ((const ParsedWord *) b)->pos.pos) ? 1 : -1;
72  }
73 
74  return res;
75 }
int32 tsCompareString(char *a, int lena, char *b, int lenb, bool prefix)
Definition: tsvector_op.c:1147
static void word(struct vars *, int, struct state *, struct state *)
Definition: regcomp.c:1394

◆ get_current_ts_config()

Datum get_current_ts_config ( PG_FUNCTION_ARGS  )

Definition at line 49 of file to_tsany.c.

References getTSCurrentConfig(), and PG_RETURN_OID.

50 {
52 }
Oid getTSCurrentConfig(bool emitError)
Definition: ts_cache.c:556
#define PG_RETURN_OID(x)
Definition: fmgr.h:360

◆ json_string_to_tsvector()

Datum json_string_to_tsvector ( PG_FUNCTION_ARGS  )

Definition at line 392 of file to_tsany.c.

References getTSCurrentConfig(), json_to_tsvector_worker(), jtiString, PG_FREE_IF_COPY, PG_GETARG_TEXT_P, and PG_RETURN_TSVECTOR.

393 {
394  text *json = PG_GETARG_TEXT_P(0);
395  Oid cfgId;
396  TSVector result;
397 
398  cfgId = getTSCurrentConfig(true);
399  result = json_to_tsvector_worker(cfgId, json, jtiString);
400  PG_FREE_IF_COPY(json, 0);
401 
402  PG_RETURN_TSVECTOR(result);
403 }
Oid getTSCurrentConfig(bool emitError)
Definition: ts_cache.c:556
#define PG_RETURN_TSVECTOR(x)
Definition: ts_type.h:122
unsigned int Oid
Definition: postgres_ext.h:31
static TSVector json_to_tsvector_worker(Oid cfgId, text *json, uint32 flags)
Definition: to_tsany.c:363
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
#define PG_GETARG_TEXT_P(n)
Definition: fmgr.h:336
Definition: c.h:621

◆ json_string_to_tsvector_byid()

Datum json_string_to_tsvector_byid ( PG_FUNCTION_ARGS  )

Definition at line 379 of file to_tsany.c.

References json_to_tsvector_worker(), jtiString, PG_FREE_IF_COPY, PG_GETARG_OID, PG_GETARG_TEXT_P, and PG_RETURN_TSVECTOR.

380 {
381  Oid cfgId = PG_GETARG_OID(0);
382  text *json = PG_GETARG_TEXT_P(1);
383  TSVector result;
384 
385  result = json_to_tsvector_worker(cfgId, json, jtiString);
386  PG_FREE_IF_COPY(json, 1);
387 
388  PG_RETURN_TSVECTOR(result);
389 }
#define PG_RETURN_TSVECTOR(x)
Definition: ts_type.h:122
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
static TSVector json_to_tsvector_worker(Oid cfgId, text *json, uint32 flags)
Definition: to_tsany.c:363
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
#define PG_GETARG_TEXT_P(n)
Definition: fmgr.h:336
Definition: c.h:621

◆ json_to_tsvector()

Datum json_to_tsvector ( PG_FUNCTION_ARGS  )

Definition at line 422 of file to_tsany.c.

References getTSCurrentConfig(), json_to_tsvector_worker(), parse_jsonb_index_flags(), PG_FREE_IF_COPY, PG_GETARG_JSONB_P, PG_GETARG_TEXT_P, and PG_RETURN_TSVECTOR.

423 {
424  text *json = PG_GETARG_TEXT_P(0);
425  Jsonb *jbFlags = PG_GETARG_JSONB_P(1);
426  Oid cfgId;
427  TSVector result;
428  uint32 flags = parse_jsonb_index_flags(jbFlags);
429 
430  cfgId = getTSCurrentConfig(true);
431  result = json_to_tsvector_worker(cfgId, json, flags);
432  PG_FREE_IF_COPY(json, 0);
433  PG_FREE_IF_COPY(jbFlags, 1);
434 
435  PG_RETURN_TSVECTOR(result);
436 }
Definition: jsonb.h:220
Oid getTSCurrentConfig(bool emitError)
Definition: ts_cache.c:556
#define PG_RETURN_TSVECTOR(x)
Definition: ts_type.h:122
unsigned int Oid
Definition: postgres_ext.h:31
uint32 parse_jsonb_index_flags(Jsonb *jb)
Definition: jsonfuncs.c:5286
unsigned int uint32
Definition: c.h:441
static TSVector json_to_tsvector_worker(Oid cfgId, text *json, uint32 flags)
Definition: to_tsany.c:363
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
#define PG_GETARG_TEXT_P(n)
Definition: fmgr.h:336
Definition: c.h:621
#define PG_GETARG_JSONB_P(x)
Definition: jsonb.h:74

◆ json_to_tsvector_byid()

Datum json_to_tsvector_byid ( PG_FUNCTION_ARGS  )

Definition at line 406 of file to_tsany.c.

References json_to_tsvector_worker(), parse_jsonb_index_flags(), PG_FREE_IF_COPY, PG_GETARG_JSONB_P, PG_GETARG_OID, PG_GETARG_TEXT_P, and PG_RETURN_TSVECTOR.

407 {
408  Oid cfgId = PG_GETARG_OID(0);
409  text *json = PG_GETARG_TEXT_P(1);
410  Jsonb *jbFlags = PG_GETARG_JSONB_P(2);
411  TSVector result;
412  uint32 flags = parse_jsonb_index_flags(jbFlags);
413 
414  result = json_to_tsvector_worker(cfgId, json, flags);
415  PG_FREE_IF_COPY(json, 1);
416  PG_FREE_IF_COPY(jbFlags, 2);
417 
418  PG_RETURN_TSVECTOR(result);
419 }
Definition: jsonb.h:220
#define PG_RETURN_TSVECTOR(x)
Definition: ts_type.h:122
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
uint32 parse_jsonb_index_flags(Jsonb *jb)
Definition: jsonfuncs.c:5286
unsigned int uint32
Definition: c.h:441
static TSVector json_to_tsvector_worker(Oid cfgId, text *json, uint32 flags)
Definition: to_tsany.c:363
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
#define PG_GETARG_TEXT_P(n)
Definition: fmgr.h:336
Definition: c.h:621
#define PG_GETARG_JSONB_P(x)
Definition: jsonb.h:74

◆ json_to_tsvector_worker()

static TSVector json_to_tsvector_worker ( Oid  cfgId,
text json,
uint32  flags 
)
static

Definition at line 363 of file to_tsany.c.

References add_to_tsvector(), TSVectorBuildState::cfgId, ParsedText::curwords, iterate_json_values(), make_tsvector(), TSVectorBuildState::prs, and ParsedText::words.

Referenced by json_string_to_tsvector(), json_string_to_tsvector_byid(), json_to_tsvector(), and json_to_tsvector_byid().

364 {
366  ParsedText prs;
367 
368  prs.words = NULL;
369  prs.curwords = 0;
370  state.prs = &prs;
371  state.cfgId = cfgId;
372 
373  iterate_json_values(json, flags, &state, add_to_tsvector);
374 
375  return make_tsvector(&prs);
376 }
TSVector make_tsvector(ParsedText *prs)
Definition: to_tsany.c:166
static void add_to_tsvector(void *_state, char *elem_value, int elem_len)
Definition: to_tsany.c:442
int32 curwords
Definition: ts_utils.h:102
ParsedWord * words
Definition: ts_utils.h:100
ParsedText * prs
Definition: to_tsany.c:41
void iterate_json_values(text *json, uint32 flags, void *action_state, JsonIterateStringValuesAction action)
Definition: jsonfuncs.c:5422
Definition: regguts.h:317

◆ jsonb_string_to_tsvector()

Datum jsonb_string_to_tsvector ( PG_FUNCTION_ARGS  )

Definition at line 313 of file to_tsany.c.

References getTSCurrentConfig(), jsonb_to_tsvector_worker(), jtiString, PG_FREE_IF_COPY, PG_GETARG_JSONB_P, and PG_RETURN_TSVECTOR.

314 {
315  Jsonb *jb = PG_GETARG_JSONB_P(0);
316  Oid cfgId;
317  TSVector result;
318 
319  cfgId = getTSCurrentConfig(true);
320  result = jsonb_to_tsvector_worker(cfgId, jb, jtiString);
321  PG_FREE_IF_COPY(jb, 0);
322 
323  PG_RETURN_TSVECTOR(result);
324 }
Definition: jsonb.h:220
Oid getTSCurrentConfig(bool emitError)
Definition: ts_cache.c:556
#define PG_RETURN_TSVECTOR(x)
Definition: ts_type.h:122
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
static TSVector jsonb_to_tsvector_worker(Oid cfgId, Jsonb *jb, uint32 flags)
Definition: to_tsany.c:284
#define PG_GETARG_JSONB_P(x)
Definition: jsonb.h:74

◆ jsonb_string_to_tsvector_byid()

Datum jsonb_string_to_tsvector_byid ( PG_FUNCTION_ARGS  )

Definition at line 300 of file to_tsany.c.

References jsonb_to_tsvector_worker(), jtiString, PG_FREE_IF_COPY, PG_GETARG_JSONB_P, PG_GETARG_OID, and PG_RETURN_TSVECTOR.

301 {
302  Oid cfgId = PG_GETARG_OID(0);
303  Jsonb *jb = PG_GETARG_JSONB_P(1);
304  TSVector result;
305 
306  result = jsonb_to_tsvector_worker(cfgId, jb, jtiString);
307  PG_FREE_IF_COPY(jb, 1);
308 
309  PG_RETURN_TSVECTOR(result);
310 }
Definition: jsonb.h:220
#define PG_RETURN_TSVECTOR(x)
Definition: ts_type.h:122
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
static TSVector jsonb_to_tsvector_worker(Oid cfgId, Jsonb *jb, uint32 flags)
Definition: to_tsany.c:284
#define PG_GETARG_JSONB_P(x)
Definition: jsonb.h:74

◆ jsonb_to_tsvector()

Datum jsonb_to_tsvector ( PG_FUNCTION_ARGS  )

Definition at line 343 of file to_tsany.c.

References getTSCurrentConfig(), jsonb_to_tsvector_worker(), parse_jsonb_index_flags(), PG_FREE_IF_COPY, PG_GETARG_JSONB_P, and PG_RETURN_TSVECTOR.

344 {
345  Jsonb *jb = PG_GETARG_JSONB_P(0);
346  Jsonb *jbFlags = PG_GETARG_JSONB_P(1);
347  Oid cfgId;
348  TSVector result;
349  uint32 flags = parse_jsonb_index_flags(jbFlags);
350 
351  cfgId = getTSCurrentConfig(true);
352  result = jsonb_to_tsvector_worker(cfgId, jb, flags);
353  PG_FREE_IF_COPY(jb, 0);
354  PG_FREE_IF_COPY(jbFlags, 1);
355 
356  PG_RETURN_TSVECTOR(result);
357 }
Definition: jsonb.h:220
Oid getTSCurrentConfig(bool emitError)
Definition: ts_cache.c:556
#define PG_RETURN_TSVECTOR(x)
Definition: ts_type.h:122
unsigned int Oid
Definition: postgres_ext.h:31
uint32 parse_jsonb_index_flags(Jsonb *jb)
Definition: jsonfuncs.c:5286
unsigned int uint32
Definition: c.h:441
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
static TSVector jsonb_to_tsvector_worker(Oid cfgId, Jsonb *jb, uint32 flags)
Definition: to_tsany.c:284
#define PG_GETARG_JSONB_P(x)
Definition: jsonb.h:74

◆ jsonb_to_tsvector_byid()

Datum jsonb_to_tsvector_byid ( PG_FUNCTION_ARGS  )

Definition at line 327 of file to_tsany.c.

References jsonb_to_tsvector_worker(), parse_jsonb_index_flags(), PG_FREE_IF_COPY, PG_GETARG_JSONB_P, PG_GETARG_OID, and PG_RETURN_TSVECTOR.

328 {
329  Oid cfgId = PG_GETARG_OID(0);
330  Jsonb *jb = PG_GETARG_JSONB_P(1);
331  Jsonb *jbFlags = PG_GETARG_JSONB_P(2);
332  TSVector result;
333  uint32 flags = parse_jsonb_index_flags(jbFlags);
334 
335  result = jsonb_to_tsvector_worker(cfgId, jb, flags);
336  PG_FREE_IF_COPY(jb, 1);
337  PG_FREE_IF_COPY(jbFlags, 2);
338 
339  PG_RETURN_TSVECTOR(result);
340 }
Definition: jsonb.h:220
#define PG_RETURN_TSVECTOR(x)
Definition: ts_type.h:122
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
uint32 parse_jsonb_index_flags(Jsonb *jb)
Definition: jsonfuncs.c:5286
unsigned int uint32
Definition: c.h:441
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
static TSVector jsonb_to_tsvector_worker(Oid cfgId, Jsonb *jb, uint32 flags)
Definition: to_tsany.c:284
#define PG_GETARG_JSONB_P(x)
Definition: jsonb.h:74

◆ jsonb_to_tsvector_worker()

static TSVector jsonb_to_tsvector_worker ( Oid  cfgId,
Jsonb jb,
uint32  flags 
)
static

Definition at line 284 of file to_tsany.c.

References add_to_tsvector(), TSVectorBuildState::cfgId, ParsedText::curwords, iterate_jsonb_values(), make_tsvector(), TSVectorBuildState::prs, and ParsedText::words.

Referenced by jsonb_string_to_tsvector(), jsonb_string_to_tsvector_byid(), jsonb_to_tsvector(), and jsonb_to_tsvector_byid().

285 {
287  ParsedText prs;
288 
289  prs.words = NULL;
290  prs.curwords = 0;
291  state.prs = &prs;
292  state.cfgId = cfgId;
293 
294  iterate_jsonb_values(jb, flags, &state, add_to_tsvector);
295 
296  return make_tsvector(&prs);
297 }
TSVector make_tsvector(ParsedText *prs)
Definition: to_tsany.c:166
static void add_to_tsvector(void *_state, char *elem_value, int elem_len)
Definition: to_tsany.c:442
void iterate_jsonb_values(Jsonb *jb, uint32 flags, void *state, JsonIterateStringValuesAction action)
Definition: jsonfuncs.c:5354
int32 curwords
Definition: ts_utils.h:102
ParsedWord * words
Definition: ts_utils.h:100
ParsedText * prs
Definition: to_tsany.c:41
Definition: regguts.h:317

◆ make_tsvector()

TSVector make_tsvector ( ParsedText prs)

Definition at line 166 of file to_tsany.c.

References ParsedWord::alen, ARRPTR, CALCDATASIZE, ParsedText::curwords, elog, ereport, errcode(), errmsg(), ERROR, WordEntry::haspos, i, WordEntry::len, ParsedWord::len, MAXSTRPOS, palloc0(), pfree(), WordEntry::pos, ParsedWord::pos, POSDATAPTR, SET_VARSIZE, SHORTALIGN, TSVectorData::size, generate_unaccent_rules::str, STRPTR, uniqueWORD(), WEP_SETPOS, WEP_SETWEIGHT, ParsedWord::word, and ParsedText::words.

Referenced by json_to_tsvector_worker(), jsonb_to_tsvector_worker(), to_tsvector_byid(), and tsvector_update_trigger().

167 {
168  int i,
169  j,
170  lenstr = 0,
171  totallen;
172  TSVector in;
173  WordEntry *ptr;
174  char *str;
175  int stroff;
176 
177  /* Merge duplicate words */
178  if (prs->curwords > 0)
179  prs->curwords = uniqueWORD(prs->words, prs->curwords);
180 
181  /* Determine space needed */
182  for (i = 0; i < prs->curwords; i++)
183  {
184  lenstr += prs->words[i].len;
185  if (prs->words[i].alen)
186  {
187  lenstr = SHORTALIGN(lenstr);
188  lenstr += sizeof(uint16) + prs->words[i].pos.apos[0] * sizeof(WordEntryPos);
189  }
190  }
191 
192  if (lenstr > MAXSTRPOS)
193  ereport(ERROR,
194  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
195  errmsg("string is too long for tsvector (%d bytes, max %d bytes)", lenstr, MAXSTRPOS)));
196 
197  totallen = CALCDATASIZE(prs->curwords, lenstr);
198  in = (TSVector) palloc0(totallen);
199  SET_VARSIZE(in, totallen);
200  in->size = prs->curwords;
201 
202  ptr = ARRPTR(in);
203  str = STRPTR(in);
204  stroff = 0;
205  for (i = 0; i < prs->curwords; i++)
206  {
207  ptr->len = prs->words[i].len;
208  ptr->pos = stroff;
209  memcpy(str + stroff, prs->words[i].word, prs->words[i].len);
210  stroff += prs->words[i].len;
211  pfree(prs->words[i].word);
212  if (prs->words[i].alen)
213  {
214  int k = prs->words[i].pos.apos[0];
215  WordEntryPos *wptr;
216 
217  if (k > 0xFFFF)
218  elog(ERROR, "positions array too long");
219 
220  ptr->haspos = 1;
221  stroff = SHORTALIGN(stroff);
222  *(uint16 *) (str + stroff) = (uint16) k;
223  wptr = POSDATAPTR(in, ptr);
224  for (j = 0; j < k; j++)
225  {
226  WEP_SETWEIGHT(wptr[j], 0);
227  WEP_SETPOS(wptr[j], prs->words[i].pos.apos[j + 1]);
228  }
229  stroff += sizeof(uint16) + k * sizeof(WordEntryPos);
230  pfree(prs->words[i].pos.apos);
231  }
232  else
233  ptr->haspos = 0;
234  ptr++;
235  }
236 
237  if (prs->words)
238  pfree(prs->words);
239 
240  return in;
241 }
uint16 WordEntryPos
Definition: ts_type.h:63
uint32 len
Definition: ts_type.h:44
int errcode(int sqlerrcode)
Definition: elog.c:694
#define MAXSTRPOS
Definition: ts_type.h:50
#define WEP_SETPOS(x, v)
Definition: ts_type.h:83
int32 curwords
Definition: ts_utils.h:102
#define POSDATAPTR(x, e)
Definition: ts_type.h:111
unsigned short uint16
Definition: c.h:440
void pfree(void *pointer)
Definition: mcxt.c:1057
#define ERROR
Definition: elog.h:45
#define WEP_SETWEIGHT(x, v)
Definition: ts_type.h:82
int32 size
Definition: ts_type.h:93
ParsedWord * words
Definition: ts_utils.h:100
uint16 pos
Definition: ts_utils.h:84
uint32 haspos
Definition: ts_type.h:44
#define CALCDATASIZE(x, lenstr)
Definition: hstore.h:72
void * palloc0(Size size)
Definition: mcxt.c:981
TSVectorData * TSVector
Definition: ts_type.h:98
#define ereport(elevel,...)
Definition: elog.h:155
uint16 len
Definition: ts_utils.h:80
uint32 pos
Definition: ts_type.h:44
uint32 alen
Definition: ts_utils.h:95
int errmsg(const char *fmt,...)
Definition: elog.c:905
#define STRPTR(x)
Definition: hstore.h:76
#define elog(elevel,...)
Definition: elog.h:227
int i
static int uniqueWORD(ParsedWord *a, int32 l)
Definition: to_tsany.c:78
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
#define ARRPTR(x)
Definition: cube.c:24
#define SHORTALIGN(LEN)
Definition: c.h:753
char * word
Definition: ts_utils.h:94

◆ phraseto_tsquery()

Datum phraseto_tsquery ( PG_FUNCTION_ARGS  )

Definition at line 677 of file to_tsany.c.

References DirectFunctionCall2, getTSCurrentConfig(), ObjectIdGetDatum, PG_GETARG_TEXT_PP, PG_RETURN_DATUM, phraseto_tsquery_byid(), and PointerGetDatum.

678 {
679  text *in = PG_GETARG_TEXT_PP(0);
680  Oid cfgId;
681 
682  cfgId = getTSCurrentConfig(true);
684  ObjectIdGetDatum(cfgId),
685  PointerGetDatum(in)));
686 }
Oid getTSCurrentConfig(bool emitError)
Definition: ts_cache.c:556
#define PointerGetDatum(X)
Definition: postgres.h:556
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
Definition: c.h:621
Datum phraseto_tsquery_byid(PG_FUNCTION_ARGS)
Definition: to_tsany.c:653
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:628

◆ phraseto_tsquery_byid()

Datum phraseto_tsquery_byid ( PG_FUNCTION_ARGS  )

Definition at line 653 of file to_tsany.c.

References MorphOpaque::cfg_id, OP_PHRASE, P_TSQ_PLAIN, parse_tsquery(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_TSQUERY, PointerGetDatum, pushval_morph(), MorphOpaque::qoperator, and text_to_cstring().

Referenced by phraseto_tsquery().

654 {
655  text *in = PG_GETARG_TEXT_PP(1);
656  TSQuery query;
657  MorphOpaque data;
658 
659  data.cfg_id = PG_GETARG_OID(0);
660 
661  /*
662  * parse_tsquery() with P_TSQ_PLAIN flag takes the whole input text as a
663  * single morph. Passing OP_PHRASE as a qoperator makes tsquery require
664  * matching of word positions.
665  */
666  data.qoperator = OP_PHRASE;
667 
668  query = parse_tsquery(text_to_cstring(in),
670  PointerGetDatum(&data),
671  P_TSQ_PLAIN);
672 
673  PG_RETURN_TSQUERY(query);
674 }
#define PointerGetDatum(X)
Definition: postgres.h:556
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_RETURN_TSQUERY(x)
Definition: ts_type.h:240
int qoperator
Definition: to_tsany.c:36
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define P_TSQ_PLAIN
Definition: ts_utils.h:61
#define OP_PHRASE
Definition: ts_type.h:169
Oid cfg_id
Definition: to_tsany.c:28
TSQuery parse_tsquery(char *buf, PushFunction pushval, Datum opaque, int flags)
Definition: tsquery.c:817
char * text_to_cstring(const text *t)
Definition: varlena.c:222
Definition: c.h:621
static void pushval_morph(Datum opaque, TSQueryParserState state, char *strval, int lenval, int16 weight, bool prefix)
Definition: to_tsany.c:491

◆ plainto_tsquery()

Datum plainto_tsquery ( PG_FUNCTION_ARGS  )

Definition at line 640 of file to_tsany.c.

References DirectFunctionCall2, getTSCurrentConfig(), ObjectIdGetDatum, PG_GETARG_TEXT_PP, PG_RETURN_DATUM, plainto_tsquery_byid(), and PointerGetDatum.

Referenced by ts_match_tt().

641 {
642  text *in = PG_GETARG_TEXT_PP(0);
643  Oid cfgId;
644 
645  cfgId = getTSCurrentConfig(true);
647  ObjectIdGetDatum(cfgId),
648  PointerGetDatum(in)));
649 }
Datum plainto_tsquery_byid(PG_FUNCTION_ARGS)
Definition: to_tsany.c:616
Oid getTSCurrentConfig(bool emitError)
Definition: ts_cache.c:556
#define PointerGetDatum(X)
Definition: postgres.h:556
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
Definition: c.h:621
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:628

◆ plainto_tsquery_byid()

Datum plainto_tsquery_byid ( PG_FUNCTION_ARGS  )

Definition at line 616 of file to_tsany.c.

References MorphOpaque::cfg_id, OP_AND, P_TSQ_PLAIN, parse_tsquery(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_POINTER, PointerGetDatum, pushval_morph(), MorphOpaque::qoperator, and text_to_cstring().

Referenced by plainto_tsquery().

617 {
618  text *in = PG_GETARG_TEXT_PP(1);
619  TSQuery query;
620  MorphOpaque data;
621 
622  data.cfg_id = PG_GETARG_OID(0);
623 
624  /*
625  * parse_tsquery() with P_TSQ_PLAIN flag takes the whole input text as a
626  * single morph. Passing OP_PHRASE as a qoperator makes tsquery require
627  * matching of all words independently on their positions.
628  */
629  data.qoperator = OP_AND;
630 
631  query = parse_tsquery(text_to_cstring(in),
633  PointerGetDatum(&data),
634  P_TSQ_PLAIN);
635 
636  PG_RETURN_POINTER(query);
637 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
#define PointerGetDatum(X)
Definition: postgres.h:556
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define OP_AND
Definition: ts_type.h:167
int qoperator
Definition: to_tsany.c:36
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define P_TSQ_PLAIN
Definition: ts_utils.h:61
Oid cfg_id
Definition: to_tsany.c:28
TSQuery parse_tsquery(char *buf, PushFunction pushval, Datum opaque, int flags)
Definition: tsquery.c:817
char * text_to_cstring(const text *t)
Definition: varlena.c:222
Definition: c.h:621
static void pushval_morph(Datum opaque, TSQueryParserState state, char *strval, int lenval, int16 weight, bool prefix)
Definition: to_tsany.c:491

◆ pushval_morph()

static void pushval_morph ( Datum  opaque,
TSQueryParserState  state,
char *  strval,
int  lenval,
int16  weight,
bool  prefix 
)
static

Definition at line 491 of file to_tsany.c.

References MorphOpaque::cfg_id, ParsedText::curwords, DatumGetPointer, ParsedWord::flags, ParsedWord::len, ParsedText::lenwords, ParsedWord::nvariant, OP_AND, OP_OR, palloc(), parsetext(), pfree(), ParsedWord::pos, ParsedText::pos, pushOperator(), pushStop(), pushValue(), MorphOpaque::qoperator, TSL_PREFIX, ParsedWord::word, and ParsedText::words.

Referenced by phraseto_tsquery_byid(), plainto_tsquery_byid(), to_tsquery_byid(), and websearch_to_tsquery_byid().

492 {
493  int32 count = 0;
494  ParsedText prs;
495  uint32 variant,
496  pos = 0,
497  cntvar = 0,
498  cntpos = 0,
499  cnt = 0;
500  MorphOpaque *data = (MorphOpaque *) DatumGetPointer(opaque);
501 
502  prs.lenwords = 4;
503  prs.curwords = 0;
504  prs.pos = 0;
505  prs.words = (ParsedWord *) palloc(sizeof(ParsedWord) * prs.lenwords);
506 
507  parsetext(data->cfg_id, &prs, strval, lenval);
508 
509  if (prs.curwords > 0)
510  {
511  while (count < prs.curwords)
512  {
513  /*
514  * Were any stop words removed? If so, fill empty positions with
515  * placeholders linked by an appropriate operator.
516  */
517  if (pos > 0 && pos + 1 < prs.words[count].pos.pos)
518  {
519  while (pos + 1 < prs.words[count].pos.pos)
520  {
521  /* put placeholders for each missing stop word */
522  pushStop(state);
523  if (cntpos)
524  pushOperator(state, data->qoperator, 1);
525  cntpos++;
526  pos++;
527  }
528  }
529 
530  /* save current word's position */
531  pos = prs.words[count].pos.pos;
532 
533  /* Go through all variants obtained from this token */
534  cntvar = 0;
535  while (count < prs.curwords && pos == prs.words[count].pos.pos)
536  {
537  variant = prs.words[count].nvariant;
538 
539  /* Push all words belonging to the same variant */
540  cnt = 0;
541  while (count < prs.curwords &&
542  pos == prs.words[count].pos.pos &&
543  variant == prs.words[count].nvariant)
544  {
545  pushValue(state,
546  prs.words[count].word,
547  prs.words[count].len,
548  weight,
549  ((prs.words[count].flags & TSL_PREFIX) || prefix));
550  pfree(prs.words[count].word);
551  if (cnt)
552  pushOperator(state, OP_AND, 0);
553  cnt++;
554  count++;
555  }
556 
557  if (cntvar)
558  pushOperator(state, OP_OR, 0);
559  cntvar++;
560  }
561 
562  if (cntpos)
563  {
564  /* distance may be useful */
565  pushOperator(state, data->qoperator, 1);
566  }
567 
568  cntpos++;
569  }
570 
571  pfree(prs.words);
572 
573  }
574  else
575  pushStop(state);
576 }
#define TSL_PREFIX
Definition: ts_public.h:116
uint16 nvariant
Definition: ts_utils.h:81
int32 lenwords
Definition: ts_utils.h:101
#define OP_OR
Definition: ts_type.h:168
int32 curwords
Definition: ts_utils.h:102
signed int int32
Definition: c.h:429
#define OP_AND
Definition: ts_type.h:167
void pfree(void *pointer)
Definition: mcxt.c:1057
void parsetext(Oid cfgId, ParsedText *prs, char *buf, int buflen)
Definition: ts_parse.c:354
int qoperator
Definition: to_tsany.c:36
void pushStop(TSQueryParserState state)
Definition: tsquery.c:630
void pushValue(TSQueryParserState state, char *strval, int lenval, int16 weight, bool prefix)
Definition: tsquery.c:594
unsigned int uint32
Definition: c.h:441
ParsedWord * words
Definition: ts_utils.h:100
uint16 pos
Definition: ts_utils.h:84
void pushOperator(TSQueryParserState state, int8 oper, int16 distance)
Definition: tsquery.c:545
uint16 len
Definition: ts_utils.h:80
int32 pos
Definition: ts_utils.h:103
Oid cfg_id
Definition: to_tsany.c:28
#define DatumGetPointer(X)
Definition: postgres.h:549
uint16 flags
Definition: ts_utils.h:93
void * palloc(Size size)
Definition: mcxt.c:950
char * word
Definition: ts_utils.h:94

◆ to_tsquery()

Datum to_tsquery ( PG_FUNCTION_ARGS  )

Definition at line 604 of file to_tsany.c.

References DirectFunctionCall2, getTSCurrentConfig(), ObjectIdGetDatum, PG_GETARG_TEXT_PP, PG_RETURN_DATUM, PointerGetDatum, and to_tsquery_byid().

605 {
606  text *in = PG_GETARG_TEXT_PP(0);
607  Oid cfgId;
608 
609  cfgId = getTSCurrentConfig(true);
611  ObjectIdGetDatum(cfgId),
612  PointerGetDatum(in)));
613 }
Oid getTSCurrentConfig(bool emitError)
Definition: ts_cache.c:556
#define PointerGetDatum(X)
Definition: postgres.h:556
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
Datum to_tsquery_byid(PG_FUNCTION_ARGS)
Definition: to_tsany.c:579
Definition: c.h:621
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:628

◆ to_tsquery_byid()

Datum to_tsquery_byid ( PG_FUNCTION_ARGS  )

Definition at line 579 of file to_tsany.c.

References MorphOpaque::cfg_id, OP_PHRASE, parse_tsquery(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_TSQUERY, PointerGetDatum, pushval_morph(), MorphOpaque::qoperator, and text_to_cstring().

Referenced by to_tsquery().

580 {
581  text *in = PG_GETARG_TEXT_PP(1);
582  TSQuery query;
583  MorphOpaque data;
584 
585  data.cfg_id = PG_GETARG_OID(0);
586 
587  /*
588  * Passing OP_PHRASE as a qoperator makes tsquery require matching of word
589  * positions of a complex morph exactly match the tsvector. Also, when
590  * the complex morphs are connected with OP_PHRASE operator, we connect
591  * all their words into the OP_PHRASE sequence.
592  */
593  data.qoperator = OP_PHRASE;
594 
595  query = parse_tsquery(text_to_cstring(in),
597  PointerGetDatum(&data),
598  0);
599 
600  PG_RETURN_TSQUERY(query);
601 }
#define PointerGetDatum(X)
Definition: postgres.h:556
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_RETURN_TSQUERY(x)
Definition: ts_type.h:240
int qoperator
Definition: to_tsany.c:36
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define OP_PHRASE
Definition: ts_type.h:169
Oid cfg_id
Definition: to_tsany.c:28
TSQuery parse_tsquery(char *buf, PushFunction pushval, Datum opaque, int flags)
Definition: tsquery.c:817
char * text_to_cstring(const text *t)
Definition: varlena.c:222
Definition: c.h:621
static void pushval_morph(Datum opaque, TSQueryParserState state, char *strval, int lenval, int16 weight, bool prefix)
Definition: to_tsany.c:491

◆ to_tsvector()

Datum to_tsvector ( PG_FUNCTION_ARGS  )

Definition at line 269 of file to_tsany.c.

References DirectFunctionCall2, getTSCurrentConfig(), ObjectIdGetDatum, PG_GETARG_TEXT_PP, PG_RETURN_DATUM, PointerGetDatum, and to_tsvector_byid().

Referenced by ts_match_tq(), and ts_match_tt().

270 {
271  text *in = PG_GETARG_TEXT_PP(0);
272  Oid cfgId;
273 
274  cfgId = getTSCurrentConfig(true);
276  ObjectIdGetDatum(cfgId),
277  PointerGetDatum(in)));
278 }
Oid getTSCurrentConfig(bool emitError)
Definition: ts_cache.c:556
#define PointerGetDatum(X)
Definition: postgres.h:556
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
Datum to_tsvector_byid(PG_FUNCTION_ARGS)
Definition: to_tsany.c:244
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
Definition: c.h:621
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:628

◆ to_tsvector_byid()

Datum to_tsvector_byid ( PG_FUNCTION_ARGS  )

Definition at line 244 of file to_tsany.c.

References ParsedText::curwords, ParsedText::lenwords, make_tsvector(), palloc(), parsetext(), PG_FREE_IF_COPY, PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_TSVECTOR, ParsedText::pos, VARDATA_ANY, VARSIZE_ANY_EXHDR, and ParsedText::words.

Referenced by to_tsvector().

245 {
246  Oid cfgId = PG_GETARG_OID(0);
247  text *in = PG_GETARG_TEXT_PP(1);
248  ParsedText prs;
249  TSVector out;
250 
251  prs.lenwords = VARSIZE_ANY_EXHDR(in) / 6; /* just estimation of word's
252  * number */
253  if (prs.lenwords < 2)
254  prs.lenwords = 2;
255  prs.curwords = 0;
256  prs.pos = 0;
257  prs.words = (ParsedWord *) palloc(sizeof(ParsedWord) * prs.lenwords);
258 
259  parsetext(cfgId, &prs, VARDATA_ANY(in), VARSIZE_ANY_EXHDR(in));
260 
261  PG_FREE_IF_COPY(in, 1);
262 
263  out = make_tsvector(&prs);
264 
265  PG_RETURN_TSVECTOR(out);
266 }
TSVector make_tsvector(ParsedText *prs)
Definition: to_tsany.c:166
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
#define PG_RETURN_TSVECTOR(x)
Definition: ts_type.h:122
int32 lenwords
Definition: ts_utils.h:101
unsigned int Oid
Definition: postgres_ext.h:31
int32 curwords
Definition: ts_utils.h:102
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
void parsetext(Oid cfgId, ParsedText *prs, char *buf, int buflen)
Definition: ts_parse.c:354
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
ParsedWord * words
Definition: ts_utils.h:100
int32 pos
Definition: ts_utils.h:103
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
void * palloc(Size size)
Definition: mcxt.c:950
Definition: c.h:621

◆ uniqueWORD()

static int uniqueWORD ( ParsedWord a,
int32  l 
)
static

Definition at line 78 of file to_tsany.c.

References ParsedWord::alen, compareWORD(), ParsedWord::len, LIMITPOS, MAXENTRYPOS, MAXNUMPOS, palloc(), pfree(), ParsedWord::pos, qsort, repalloc(), and ParsedWord::word.

Referenced by make_tsvector().

79 {
80  ParsedWord *ptr,
81  *res;
82  int tmppos;
83 
84  if (l == 1)
85  {
86  tmppos = LIMITPOS(a->pos.pos);
87  a->alen = 2;
88  a->pos.apos = (uint16 *) palloc(sizeof(uint16) * a->alen);
89  a->pos.apos[0] = 1;
90  a->pos.apos[1] = tmppos;
91  return l;
92  }
93 
94  res = a;
95  ptr = a + 1;
96 
97  /*
98  * Sort words with its positions
99  */
100  qsort((void *) a, l, sizeof(ParsedWord), compareWORD);
101 
102  /*
103  * Initialize first word and its first position
104  */
105  tmppos = LIMITPOS(a->pos.pos);
106  a->alen = 2;
107  a->pos.apos = (uint16 *) palloc(sizeof(uint16) * a->alen);
108  a->pos.apos[0] = 1;
109  a->pos.apos[1] = tmppos;
110 
111  /*
112  * Summarize position information for each word
113  */
114  while (ptr - a < l)
115  {
116  if (!(ptr->len == res->len &&
117  strncmp(ptr->word, res->word, res->len) == 0))
118  {
119  /*
120  * Got a new word, so put it in result
121  */
122  res++;
123  res->len = ptr->len;
124  res->word = ptr->word;
125  tmppos = LIMITPOS(ptr->pos.pos);
126  res->alen = 2;
127  res->pos.apos = (uint16 *) palloc(sizeof(uint16) * res->alen);
128  res->pos.apos[0] = 1;
129  res->pos.apos[1] = tmppos;
130  }
131  else
132  {
133  /*
134  * The word already exists, so adjust position information. But
135  * before we should check size of position's array, max allowed
136  * value for position and uniqueness of position
137  */
138  pfree(ptr->word);
139  if (res->pos.apos[0] < MAXNUMPOS - 1 && res->pos.apos[res->pos.apos[0]] != MAXENTRYPOS - 1 &&
140  res->pos.apos[res->pos.apos[0]] != LIMITPOS(ptr->pos.pos))
141  {
142  if (res->pos.apos[0] + 1 >= res->alen)
143  {
144  res->alen *= 2;
145  res->pos.apos = (uint16 *) repalloc(res->pos.apos, sizeof(uint16) * res->alen);
146  }
147  if (res->pos.apos[0] == 0 || res->pos.apos[res->pos.apos[0]] != LIMITPOS(ptr->pos.pos))
148  {
149  res->pos.apos[res->pos.apos[0] + 1] = LIMITPOS(ptr->pos.pos);
150  res->pos.apos[0]++;
151  }
152  }
153  }
154  ptr++;
155  }
156 
157  return res + 1 - a;
158 }
unsigned short uint16
Definition: c.h:440
void pfree(void *pointer)
Definition: mcxt.c:1057
#define MAXNUMPOS
Definition: ts_type.h:86
uint16 pos
Definition: ts_utils.h:84
static int compareWORD(const void *a, const void *b)
Definition: to_tsany.c:58
uint16 len
Definition: ts_utils.h:80
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1070
uint32 alen
Definition: ts_utils.h:95
void * palloc(Size size)
Definition: mcxt.c:950
#define LIMITPOS(x)
Definition: ts_type.h:87
#define qsort(a, b, c, d)
Definition: port.h:504
#define MAXENTRYPOS
Definition: ts_type.h:85
char * word
Definition: ts_utils.h:94

◆ websearch_to_tsquery()

Datum websearch_to_tsquery ( PG_FUNCTION_ARGS  )

Definition at line 714 of file to_tsany.c.

References DirectFunctionCall2, getTSCurrentConfig(), ObjectIdGetDatum, PG_GETARG_TEXT_PP, PG_RETURN_DATUM, PointerGetDatum, and websearch_to_tsquery_byid().

715 {
716  text *in = PG_GETARG_TEXT_PP(0);
717  Oid cfgId;
718 
719  cfgId = getTSCurrentConfig(true);
721  ObjectIdGetDatum(cfgId),
722  PointerGetDatum(in)));
723 
724 }
Oid getTSCurrentConfig(bool emitError)
Definition: ts_cache.c:556
#define PointerGetDatum(X)
Definition: postgres.h:556
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
Definition: c.h:621
Datum websearch_to_tsquery_byid(PG_FUNCTION_ARGS)
Definition: to_tsany.c:689
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:628

◆ websearch_to_tsquery_byid()

Datum websearch_to_tsquery_byid ( PG_FUNCTION_ARGS  )

Definition at line 689 of file to_tsany.c.

References MorphOpaque::cfg_id, OP_PHRASE, P_TSQ_WEB, parse_tsquery(), PG_GETARG_OID, PG_GETARG_TEXT_PP, PG_RETURN_TSQUERY, PointerGetDatum, pushval_morph(), MorphOpaque::qoperator, and text_to_cstring().

Referenced by websearch_to_tsquery().

690 {
691  text *in = PG_GETARG_TEXT_PP(1);
692  MorphOpaque data;
693  TSQuery query = NULL;
694 
695  data.cfg_id = PG_GETARG_OID(0);
696 
697  /*
698  * Passing OP_PHRASE as a qoperator makes tsquery require matching of word
699  * positions of a complex morph exactly match the tsvector. Also, when
700  * the complex morphs are given in quotes, we connect all their words into
701  * the OP_PHRASE sequence.
702  */
703  data.qoperator = OP_PHRASE;
704 
705  query = parse_tsquery(text_to_cstring(in),
707  PointerGetDatum(&data),
708  P_TSQ_WEB);
709 
710  PG_RETURN_TSQUERY(query);
711 }
#define PointerGetDatum(X)
Definition: postgres.h:556
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_RETURN_TSQUERY(x)
Definition: ts_type.h:240
int qoperator
Definition: to_tsany.c:36
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define OP_PHRASE
Definition: ts_type.h:169
Oid cfg_id
Definition: to_tsany.c:28
#define P_TSQ_WEB
Definition: ts_utils.h:62
TSQuery parse_tsquery(char *buf, PushFunction pushval, Datum opaque, int flags)
Definition: tsquery.c:817
char * text_to_cstring(const text *t)
Definition: varlena.c:222
Definition: c.h:621
static void pushval_morph(Datum opaque, TSQueryParserState state, char *strval, int lenval, int16 weight, bool prefix)
Definition: to_tsany.c:491