Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 146d31d

Browse files
author
Alexander Korotkov
committed
Some comments to tsquery indexing
It would be good to write proper documentation for that. But it's not possible for me now due to lack of time. Thus, few comments are still slighly better than nothing.
1 parent 7386406 commit 146d31d

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

src/rumtsquery.c

+29-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
#include "rum.h"
2222

23+
/*
24+
* A "wrapper" over tsquery item. More suitable representation for pocessing.
25+
*/
2326
typedef struct QueryItemWrap
2427
{
2528
QueryItemType type;
@@ -33,8 +36,11 @@ typedef struct QueryItemWrap
3336
int num;
3437
} QueryItemWrap;
3538

39+
/*
40+
* Add child to tsquery item wrap.
41+
*/
3642
static QueryItemWrap *
37-
add_child(QueryItemWrap * parent)
43+
add_child(QueryItemWrap *parent)
3844
{
3945
QueryItemWrap *result;
4046

@@ -48,8 +54,11 @@ add_child(QueryItemWrap * parent)
4854
return result;
4955
}
5056

57+
/*
58+
* Make wrapper over tsquery item. Flattern tree if needed.
59+
*/
5160
static QueryItemWrap *
52-
make_query_item_wrap(QueryItem *item, QueryItemWrap * parent, bool not)
61+
make_query_item_wrap(QueryItem *item, QueryItemWrap *parent, bool not)
5362
{
5463
if (item->type == QI_VAL)
5564
{
@@ -107,8 +116,11 @@ make_query_item_wrap(QueryItem *item, QueryItemWrap * parent, bool not)
107116
return NULL;
108117
}
109118

119+
/*
120+
* Recursively calculate "sum" for tsquery item wraps.
121+
*/
110122
static int
111-
calc_wraps(QueryItemWrap * wrap, int *num)
123+
calc_wraps(QueryItemWrap *wrap, int *num)
112124
{
113125
int notCount = 0,
114126
result;
@@ -145,6 +157,10 @@ calc_wraps(QueryItemWrap * wrap, int *num)
145157
return result;
146158
}
147159

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+
*/
148164
static bool
149165
check_allnegative(QueryItemWrap * wrap)
150166
{
@@ -186,6 +202,7 @@ check_allnegative(QueryItemWrap * wrap)
186202

187203
}
188204

205+
/* Max length of variable-length encoded 32-bit integer */
189206
#define MAX_ENCODED_LEN 5
190207

191208
/*
@@ -253,16 +270,19 @@ typedef struct
253270
char *operand;
254271
} ExtractContext;
255272

273+
/*
274+
* Recursively extract entries from tsquery wraps. Encode paths into addInfos.
275+
*/
256276
static void
257-
extract_wraps(QueryItemWrap * wrap, ExtractContext * context, int level)
277+
extract_wraps(QueryItemWrap *wrap, ExtractContext *context, int level)
258278
{
259279
if (wrap->type == QI_VAL)
260280
{
261281
bytea *addinfo;
262282
unsigned char *ptr;
263283
int index;
264284

265-
285+
/* Check if given lexeme was already extracted */
266286
for (index = 0; index < context->index; index++)
267287
{
268288
text *entry;
@@ -273,6 +293,7 @@ extract_wraps(QueryItemWrap * wrap, ExtractContext * context, int level)
273293
break;
274294
}
275295

296+
/* Either allocate new addInfo or extend existing addInfo */
276297
if (index >= context->index)
277298
{
278299
index = context->index;
@@ -292,6 +313,7 @@ extract_wraps(QueryItemWrap * wrap, ExtractContext * context, int level)
292313
ptr = (unsigned char *) VARDATA(addinfo) + VARSIZE_ANY_EXHDR(addinfo);
293314
}
294315

316+
/* Encode path into addInfo */
295317
while (wrap->parent)
296318
{
297319
QueryItemWrap *parent = wrap->parent;
@@ -471,6 +493,7 @@ ruminv_tsvector_consistent(PG_FUNCTION_ARGS)
471493
if (addInfoIsNull[i])
472494
elog(ERROR, "Unexpected addInfoIsNull");
473495

496+
/* Iterate path making corresponding calculation */
474497
ptr = (unsigned char *) VARDATA_ANY(DatumGetPointer(addInfo[i]));
475498
size = VARSIZE_ANY_EXHDR(DatumGetPointer(addInfo[i]));
476499

@@ -528,6 +551,7 @@ ruminv_tsvector_consistent(PG_FUNCTION_ARGS)
528551
}
529552
}
530553

554+
/* Iterate over nodes */
531555
if (allFalse && check[nkeys - 1])
532556
{
533557
res = true;

0 commit comments

Comments
 (0)