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

Commit146d31d

Browse files
author
Alexander Korotkov
committed
Some comments to tsquery indexing
It would be good to write proper documentation for that. But it's notpossible for me now due to lack of time. Thus, few comments are still slighlybetter than nothing.
1 parent7386406 commit146d31d

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

‎src/rumtsquery.c

Lines changed: 29 additions & 5 deletions
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
typedefstructQueryItemWrap
2427
{
2528
QueryItemTypetype;
@@ -33,8 +36,11 @@ typedef struct QueryItemWrap
3336
intnum;
3437
}QueryItemWrap;
3538

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

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

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

119+
/*
120+
* Recursively calculate "sum" for tsquery item wraps.
121+
*/
110122
staticint
111-
calc_wraps(QueryItemWrap*wrap,int*num)
123+
calc_wraps(QueryItemWrap*wrap,int*num)
112124
{
113125
intnotCount=0,
114126
result;
@@ -145,6 +157,10 @@ calc_wraps(QueryItemWrap * wrap, int *num)
145157
returnresult;
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
staticbool
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
#defineMAX_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
staticvoid
257-
extract_wraps(QueryItemWrap*wrap,ExtractContext*context,intlevel)
277+
extract_wraps(QueryItemWrap*wrap,ExtractContext*context,intlevel)
258278
{
259279
if (wrap->type==QI_VAL)
260280
{
261281
bytea*addinfo;
262282
unsignedchar*ptr;
263283
intindex;
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= (unsignedchar*)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= (unsignedchar*)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)

[8]ページ先頭

©2009-2025 Movatter.jp