PostgreSQL Source Code: src/backend/tsearch/ts_parse.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
16
20
21#define IGNORE_LONGLEXEME 1
22
23
24
25
26
34
40
41typedef struct
42{
50
51
52
53
54
55
59
60static void
62{
65 ld->posDict = 0;
66 ld->towork.head = ld->towork.tail = ld->curSub = NULL;
67 ld->waste.head = ld->waste.tail = NULL;
70}
71
72static void
74{
75 if (list->tail)
76 {
77 list->tail->next = newpl;
78 list->tail = newpl;
79 }
80 else
81 list->head = list->tail = newpl;
83}
84
87{
89
90 if (list->head)
91 list->head = list->head->next;
92
93 if (list->head == NULL)
94 list->tail = NULL;
95
96 return res;
97}
98
99static void
101{
103
105 newpl->lemm = lemm;
106 newpl->lenlemm = lenlemm;
108 ld->curSub = ld->towork.tail;
109}
110
111static void
113{
115
116 ld->posDict = 0;
117}
118
119static void
121{
123 {
125 }
126 else
127 {
129 *ptr = ld->waste.head;
130
131 while (ptr)
132 {
133 tmp = ptr->next;
135 ptr = tmp;
136 }
137 }
138 ld->waste.head = ld->waste.tail = NULL;
139}
140
141static void
143{
144 bool go = true;
145
146 while (ld->towork.head && go)
147 {
148 if (ld->towork.head == stop)
149 {
151 go = false;
152 }
154 }
155}
156
157static void
159{
160 if (ld->tmpRes)
161 {
163
164 for (ptr = ld->tmpRes; ptr->lexeme; ptr++)
167 }
168 ld->tmpRes = res;
169 ld->lastRes = lex;
170}
171
174{
175 int i;
179
181 {
182
183
184
185
186
187 while (ld->towork.head)
188 {
192
193 map = ld->cfg->map + curVal->type;
194
195 if (curVal->type == 0 || curVal->type >= ld->cfg->lenmap || map->len == 0)
196 {
197
199 continue;
200 }
201
202 for (i = ld->posDict; i < map->len; i++)
203 {
205
206 ld->dictState.isend = ld->dictState.getnext = false;
207 ld->dictState.private_state = NULL;
213
214 if (ld->dictState.getnext)
215 {
216
217
218
219
220
224 if (res)
227 }
228
229 if (!res)
230 continue;
231
233 {
236 continue;
237 }
238
241 return res;
242 }
243
245 }
246 }
247 else
248 {
250
251
252
253
254
255 while (ld->curSub)
256 {
258
259 map = ld->cfg->map + curVal->type;
260
261 if (curVal->type != 0)
262 {
264
265 if (curVal->type >= ld->cfg->lenmap || map->len == 0)
266 {
267
269 continue;
270 }
271
272
273
274
275
276
278 if (ld->curDictId == map->dictIds[i])
280
282 {
283
284
285
286
289 }
290 }
291
292 ld->dictState.isend = (curVal->type == 0);
293 ld->dictState.getnext = false;
294
300
301 if (ld->dictState.getnext)
302 {
303
305 if (res)
307 continue;
308 }
309
310 if (res || ld->tmpRes)
311 {
312
313
314
315
316
317 if (res)
318 {
320 }
321 else
322 {
323 res = ld->tmpRes;
325 }
326
327
329 ld->posDict = 0;
333 return res;
334 }
335
336
337
338
339
342 }
343 }
344
347}
348
349
350
351
352
353
354void
356{
358 lenlemm = 0;
359 char *lemm = NULL;
365
368
372
374
375 do
376 {
381
383 {
384#ifdef IGNORE_LONGLEXEME
387 errmsg("word is too long to be indexed"),
388 errdetail("Words longer than %d characters are ignored.",
390 continue;
391#else
394 errmsg("word is too long to be indexed"),
395 errdetail("Words longer than %d characters are ignored.",
397#endif
398 }
399
401
403 {
405
406 prs->pos++;
407
409 {
411 {
414 }
415
417 prs->pos++;
424 ptr++;
426 }
428 }
429 } while (type > 0);
430
432}
433
434
435
436
437
438
439static void
454
455
456
457
458
459
460
461
462
463static void
465{
466 int i;
469
471 {
474 }
475
478 for (i = 0; i < query->size; i++)
479 {
483 {
484 if (word->item)
485 {
490 }
491 else
493 }
494 item++;
495 }
496}
497
498static void
500{
504
506 {
507 if (lexs->type > 0)
509
512 while (ptr && ptr->lexeme)
513 {
517 ptr++;
518 }
519
523 }
524
526 {
529 {
533 ptr++;
534 }
536 }
537}
538
539void
541{
543 lenlemm = 0;
544 char *lemm = NULL;
551
554
558
560
561 do
562 {
567
569 {
570#ifdef IGNORE_LONGLEXEME
573 errmsg("word is too long to be indexed"),
574 errdetail("Words longer than %d characters are ignored.",
576 continue;
577#else
580 errmsg("word is too long to be indexed"),
581 errdetail("Words longer than %d characters are ignored.",
583#endif
584 }
585
587
588 do
589 {
591 {
594 }
595 else
598 } while (type > 0);
599
601}
602
603
604
605
608{
610 char *ptr;
611 int len = 128;
614
616
618 ptr = ((char *) out) + VARHDRSZ;
619
621 {
623 {
624 int dist = ptr - ((char *) out);
625
626 len *= 2;
628 ptr = ((char *) out) + dist;
629 }
630
631 if (wrd->in && ->repeated)
632 {
634 {
635
636
639
641 {
644 }
645 }
646 if (wrd->replace)
647 {
648 *ptr = ' ';
649 ptr++;
650 }
651 else if (->skip)
652 {
653 if (wrd->selected)
654 {
657 }
659 ptr += wrd->len;
660 if (wrd->selected)
661 {
664 }
665 }
666 }
667 else if (->repeated)
668 {
672 }
673
675 }
676
678 return out;
679}
int errcode(int sqlerrcode)
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define ereport(elevel,...)
#define palloc_object(type)
#define FunctionCall4(flinfo, arg1, arg2, arg3, arg4)
#define FunctionCall1(flinfo, arg1)
#define FunctionCall2(flinfo, arg1, arg2)
#define FunctionCall3(flinfo, arg1, arg2, arg3)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
static char buf[DEFAULT_XLOG_SEG_SIZE]
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)
static Datum Int32GetDatum(int32 X)
static int32 DatumGetInt32(Datum X)
static void word(struct vars *v, int dir, struct state *lp, struct state *rp)
HeadlineWordEntry * words
TSConfigCacheEntry * lookup_ts_config_cache(Oid cfgId)
TSParserCacheEntry * lookup_ts_parser_cache(Oid prsId)
TSDictionaryCacheEntry * lookup_ts_dictionary_cache(Oid dictId)
static void hlfinditem(HeadlineParsedText *prs, TSQuery query, int32 pos, char *buf, int buflen)
static void setNewTmpRes(LexizeData *ld, ParsedLex *lex, TSLexeme *res)
text * generateHeadline(HeadlineParsedText *prs)
static void RemoveHead(LexizeData *ld)
static void setCorrLex(LexizeData *ld, ParsedLex **correspondLexem)
void parsetext(Oid cfgId, ParsedText *prs, char *buf, int buflen)
void hlparsetext(Oid cfgId, HeadlineParsedText *prs, TSQuery query, char *buf, int buflen)
static void hladdword(HeadlineParsedText *prs, char *buf, int buflen, int type)
static TSLexeme * LexizeExec(LexizeData *ld, ParsedLex **correspondLexem)
static void LPLAddTail(ListParsedLex *list, ParsedLex *newpl)
static void moveToWaste(LexizeData *ld, ParsedLex *stop)
static ParsedLex * LPLRemoveHead(ListParsedLex *list)
static void addHLParsedLex(HeadlineParsedText *prs, TSQuery query, ParsedLex *lexs, TSLexeme *norms)
static void LexizeAddLemm(LexizeData *ld, int type, char *lemm, int lenlemm)
static void LexizeInit(LexizeData *ld, TSConfigCacheEntry *cfg)
int32 tsCompareString(char *a, int lena, char *b, int lenb, bool prefix)
static void SET_VARSIZE(void *PTR, Size len)