20
20
21
21
#include "rum.h"
22
22
23
+ /*
24
+ * A "wrapper" over tsquery item. More suitable representation for pocessing.
25
+ */
23
26
typedef struct QueryItemWrap
24
27
{
25
28
QueryItemType type ;
@@ -33,8 +36,11 @@ typedef struct QueryItemWrap
33
36
int num ;
34
37
} QueryItemWrap ;
35
38
39
+ /*
40
+ * Add child to tsquery item wrap.
41
+ */
36
42
static QueryItemWrap *
37
- add_child (QueryItemWrap * parent )
43
+ add_child (QueryItemWrap * parent )
38
44
{
39
45
QueryItemWrap * result ;
40
46
@@ -48,8 +54,11 @@ add_child(QueryItemWrap * parent)
48
54
return result ;
49
55
}
50
56
57
+ /*
58
+ * Make wrapper over tsquery item. Flattern tree if needed.
59
+ */
51
60
static QueryItemWrap *
52
- make_query_item_wrap (QueryItem * item , QueryItemWrap * parent , bool not )
61
+ make_query_item_wrap (QueryItem * item , QueryItemWrap * parent , bool not )
53
62
{
54
63
if (item -> type == QI_VAL )
55
64
{
@@ -107,8 +116,11 @@ make_query_item_wrap(QueryItem *item, QueryItemWrap * parent, bool not)
107
116
return NULL ;
108
117
}
109
118
119
+ /*
120
+ * Recursively calculate "sum" for tsquery item wraps.
121
+ */
110
122
static int
111
- calc_wraps (QueryItemWrap * wrap , int * num )
123
+ calc_wraps (QueryItemWrap * wrap , int * num )
112
124
{
113
125
int notCount = 0 ,
114
126
result ;
@@ -145,6 +157,10 @@ calc_wraps(QueryItemWrap * wrap, int *num)
145
157
return result ;
146
158
}
147
159
160
+ /*
161
+ * Check if tsquery doesn't need any positive lexeme occurence for satisfaction.
162
+ * That is this funciton returns true when tsquery maches empty tsvector.
163
+ */
148
164
static bool
149
165
check_allnegative (QueryItemWrap * wrap )
150
166
{
@@ -186,6 +202,7 @@ check_allnegative(QueryItemWrap * wrap)
186
202
187
203
}
188
204
205
+ /* Max length of variable-length encoded 32-bit integer */
189
206
#define MAX_ENCODED_LEN 5
190
207
191
208
/*
@@ -253,16 +270,19 @@ typedef struct
253
270
char * operand ;
254
271
} ExtractContext ;
255
272
273
+ /*
274
+ * Recursively extract entries from tsquery wraps. Encode paths into addInfos.
275
+ */
256
276
static void
257
- extract_wraps (QueryItemWrap * wrap , ExtractContext * context , int level )
277
+ extract_wraps (QueryItemWrap * wrap , ExtractContext * context , int level )
258
278
{
259
279
if (wrap -> type == QI_VAL )
260
280
{
261
281
bytea * addinfo ;
262
282
unsigned char * ptr ;
263
283
int index ;
264
284
265
-
285
+ /* Check if given lexeme was already extracted */
266
286
for (index = 0 ; index < context -> index ; index ++ )
267
287
{
268
288
text * entry ;
@@ -273,6 +293,7 @@ extract_wraps(QueryItemWrap * wrap, ExtractContext * context, int level)
273
293
break ;
274
294
}
275
295
296
+ /* Either allocate new addInfo or extend existing addInfo */
276
297
if (index >= context -> index )
277
298
{
278
299
index = context -> index ;
@@ -292,6 +313,7 @@ extract_wraps(QueryItemWrap * wrap, ExtractContext * context, int level)
292
313
ptr = (unsigned char * ) VARDATA (addinfo ) + VARSIZE_ANY_EXHDR (addinfo );
293
314
}
294
315
316
+ /* Encode path into addInfo */
295
317
while (wrap -> parent )
296
318
{
297
319
QueryItemWrap * parent = wrap -> parent ;
@@ -471,6 +493,7 @@ ruminv_tsvector_consistent(PG_FUNCTION_ARGS)
471
493
if (addInfoIsNull [i ])
472
494
elog (ERROR , "Unexpected addInfoIsNull" );
473
495
496
+ /* Iterate path making corresponding calculation */
474
497
ptr = (unsigned char * ) VARDATA_ANY (DatumGetPointer (addInfo [i ]));
475
498
size = VARSIZE_ANY_EXHDR (DatumGetPointer (addInfo [i ]));
476
499
@@ -528,6 +551,7 @@ ruminv_tsvector_consistent(PG_FUNCTION_ARGS)
528
551
}
529
552
}
530
553
554
+ /* Iterate over nodes */
531
555
if (allFalse && check [nkeys - 1 ])
532
556
{
533
557
res = true;
0 commit comments