Skip to content

Commit a59ed37

Browse files
author
Zakirov Artur
committed
Additional comments and a little fix for rum_extract_tsquery_internal()
1 parent 6e095d3 commit a59ed37

File tree

1 file changed

+67
-5
lines changed

1 file changed

+67
-5
lines changed

src/rum_ts_utils.c

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,14 @@ SortAndUniqItems(TSQuery q, int *size)
490490
return res;
491491
}
492492

493+
/*
494+
* Extracting tsvector lexems.
495+
*/
496+
497+
/*
498+
* Extracts tsvector lexemes from **vector**. Uses **build_tsvector_entry**
499+
* callback to extract entry.
500+
*/
493501
static Datum *
494502
rum_extract_tsvector_internal(TSVector vector,
495503
int32 *nentries,
@@ -515,6 +523,7 @@ rum_extract_tsvector_internal(TSVector vector,
515523
bytea *posData;
516524
int posDataSize;
517525

526+
/* Extract entry using specified method */
518527
entries[i] = build_tsvector_entry(vector, we);
519528

520529
if (we->haspos)
@@ -540,6 +549,10 @@ rum_extract_tsvector_internal(TSVector vector,
540549
return entries;
541550
}
542551

552+
/*
553+
* Used as callback for rum_extract_tsvector_internal().
554+
* Just extract entry from tsvector.
555+
*/
543556
static Datum
544557
build_tsvector_entry(TSVector vector, WordEntry *we)
545558
{
@@ -549,6 +562,10 @@ build_tsvector_entry(TSVector vector, WordEntry *we)
549562
return PointerGetDatum(txt);
550563
}
551564

565+
/*
566+
* Used as callback for rum_extract_tsvector_internal.
567+
* Returns hashed entry from tsvector.
568+
*/
552569
static Datum
553570
build_tsvector_hash_entry(TSVector vector, WordEntry *we)
554571
{
@@ -559,6 +576,9 @@ build_tsvector_hash_entry(TSVector vector, WordEntry *we)
559576
return Int32GetDatum(hash_value);
560577
}
561578

579+
/*
580+
* Extracts lexemes from tsvector with additional information.
581+
*/
562582
Datum
563583
rum_extract_tsvector(PG_FUNCTION_ARGS)
564584
{
@@ -575,6 +595,9 @@ rum_extract_tsvector(PG_FUNCTION_ARGS)
575595
PG_RETURN_POINTER(entries);
576596
}
577597

598+
/*
599+
* Extracts hashed lexemes from tsvector with additional information.
600+
*/
578601
Datum
579602
rum_extract_tsvector_hash(PG_FUNCTION_ARGS)
580603
{
@@ -592,6 +615,14 @@ rum_extract_tsvector_hash(PG_FUNCTION_ARGS)
592615
PG_RETURN_POINTER(entries);
593616
}
594617

618+
/*
619+
* Extracting tsquery lexemes.
620+
*/
621+
622+
/*
623+
* Extracts tsquery lexemes from **query**. Uses **build_tsquery_entry**
624+
* callback to extract lexeme.
625+
*/
595626
static Datum *
596627
rum_extract_tsquery_internal(TSQuery query,
597628
int32 *nentries,
@@ -640,11 +671,6 @@ rum_extract_tsquery_internal(TSQuery query,
640671

641672
for (i = 0; i < (*nentries); i++)
642673
{
643-
text *txt;
644-
645-
txt = cstring_to_text_with_len(GETOPERAND(query) + operands[i]->distance,
646-
operands[i]->length);
647-
entries[i] = PointerGetDatum(txt);
648674
entries[i] = build_tsquery_entry(query, operands[i]);
649675
partialmatch[i] = operands[i]->prefix;
650676
(*extra_data)[i] = (Pointer) map_item_operand;
@@ -679,6 +705,9 @@ rum_extract_tsquery_internal(TSQuery query,
679705
return entries;
680706
}
681707

708+
/*
709+
* Extract lexeme from tsquery.
710+
*/
682711
static Datum
683712
build_tsquery_entry(TSQuery query, QueryOperand *operand)
684713
{
@@ -689,6 +718,9 @@ build_tsquery_entry(TSQuery query, QueryOperand *operand)
689718
return PointerGetDatum(txt);
690719
}
691720

721+
/*
722+
* Extract hashed lexeme from tsquery.
723+
*/
692724
static Datum
693725
build_tsquery_hash_entry(TSQuery query, QueryOperand *operand)
694726
{
@@ -700,6 +732,9 @@ build_tsquery_hash_entry(TSQuery query, QueryOperand *operand)
700732
return hash_value;
701733
}
702734

735+
/*
736+
* Extracts lexemes from tsquery with information about prefix search syntax.
737+
*/
703738
Datum
704739
rum_extract_tsquery(PG_FUNCTION_ARGS)
705740
{
@@ -723,6 +758,10 @@ rum_extract_tsquery(PG_FUNCTION_ARGS)
723758
PG_RETURN_POINTER(entries);
724759
}
725760

761+
/*
762+
* Extracts hashed lexemes from tsquery with information about prefix search
763+
* syntax.
764+
*/
726765
Datum
727766
rum_extract_tsquery_hash(PG_FUNCTION_ARGS)
728767
{
@@ -746,6 +785,10 @@ rum_extract_tsquery_hash(PG_FUNCTION_ARGS)
746785
PG_RETURN_POINTER(entries);
747786
}
748787

788+
/*
789+
* Functions used for ranking.
790+
*/
791+
749792
static int
750793
compareDocR(const void *va, const void *vb)
751794
{
@@ -1297,6 +1340,10 @@ calc_score(float4 *arrdata, TSVector txt, TSQuery query, int method)
12971340
return (float4) Wdoc;
12981341
}
12991342

1343+
/*
1344+
* Calculates distance inside index. Uses additional information with lexemes
1345+
* positions.
1346+
*/
13001347
Datum
13011348
rum_tsquery_distance(PG_FUNCTION_ARGS)
13021349
{
@@ -1320,6 +1367,9 @@ rum_tsquery_distance(PG_FUNCTION_ARGS)
13201367
PG_RETURN_FLOAT8(1.0 / res);
13211368
}
13221369

1370+
/*
1371+
* Implementation of <=> operator. Uses default normalization method.
1372+
*/
13231373
Datum
13241374
rum_ts_distance_tt(PG_FUNCTION_ARGS)
13251375
{
@@ -1337,6 +1387,9 @@ rum_ts_distance_tt(PG_FUNCTION_ARGS)
13371387
PG_RETURN_FLOAT4(1.0 / res);
13381388
}
13391389

1390+
/*
1391+
* Implementation of <=> operator. Uses specified normalization method.
1392+
*/
13401393
Datum
13411394
rum_ts_distance_ttf(PG_FUNCTION_ARGS)
13421395
{
@@ -1355,6 +1408,9 @@ rum_ts_distance_ttf(PG_FUNCTION_ARGS)
13551408
PG_RETURN_FLOAT4(1.0 / res);
13561409
}
13571410

1411+
/*
1412+
* Implementation of <=> operator. Uses specified normalization method.
1413+
*/
13581414
Datum
13591415
rum_ts_distance_td(PG_FUNCTION_ARGS)
13601416
{
@@ -1401,6 +1457,9 @@ rum_ts_distance_td(PG_FUNCTION_ARGS)
14011457
PG_RETURN_FLOAT4(1.0 / res);
14021458
}
14031459

1460+
/*
1461+
* Casts tsquery to rum_distance_query type.
1462+
*/
14041463
Datum
14051464
tsquery_to_distance_query(PG_FUNCTION_ARGS)
14061465
{
@@ -1426,6 +1485,9 @@ tsquery_to_distance_query(PG_FUNCTION_ARGS)
14261485
PG_RETURN_DATUM(HeapTupleGetDatum(htup));
14271486
}
14281487

1488+
/*
1489+
* Specifies additional information type for operator class.
1490+
*/
14291491
Datum
14301492
rum_tsvector_config(PG_FUNCTION_ARGS)
14311493
{

0 commit comments

Comments
 (0)