@@ -490,6 +490,14 @@ SortAndUniqItems(TSQuery q, int *size)
490
490
return res ;
491
491
}
492
492
493
+ /*
494
+ * Extracting tsvector lexems.
495
+ */
496
+
497
+ /*
498
+ * Extracts tsvector lexemes from **vector**. Uses **build_tsvector_entry**
499
+ * callback to extract entry.
500
+ */
493
501
static Datum *
494
502
rum_extract_tsvector_internal (TSVector vector ,
495
503
int32 * nentries ,
@@ -515,6 +523,7 @@ rum_extract_tsvector_internal(TSVector vector,
515
523
bytea * posData ;
516
524
int posDataSize ;
517
525
526
+ /* Extract entry using specified method */
518
527
entries [i ] = build_tsvector_entry (vector , we );
519
528
520
529
if (we -> haspos )
@@ -540,6 +549,10 @@ rum_extract_tsvector_internal(TSVector vector,
540
549
return entries ;
541
550
}
542
551
552
+ /*
553
+ * Used as callback for rum_extract_tsvector_internal().
554
+ * Just extract entry from tsvector.
555
+ */
543
556
static Datum
544
557
build_tsvector_entry (TSVector vector , WordEntry * we )
545
558
{
@@ -549,6 +562,10 @@ build_tsvector_entry(TSVector vector, WordEntry *we)
549
562
return PointerGetDatum (txt );
550
563
}
551
564
565
+ /*
566
+ * Used as callback for rum_extract_tsvector_internal.
567
+ * Returns hashed entry from tsvector.
568
+ */
552
569
static Datum
553
570
build_tsvector_hash_entry (TSVector vector , WordEntry * we )
554
571
{
@@ -559,6 +576,9 @@ build_tsvector_hash_entry(TSVector vector, WordEntry *we)
559
576
return Int32GetDatum (hash_value );
560
577
}
561
578
579
+ /*
580
+ * Extracts lexemes from tsvector with additional information.
581
+ */
562
582
Datum
563
583
rum_extract_tsvector (PG_FUNCTION_ARGS )
564
584
{
@@ -575,6 +595,9 @@ rum_extract_tsvector(PG_FUNCTION_ARGS)
575
595
PG_RETURN_POINTER (entries );
576
596
}
577
597
598
+ /*
599
+ * Extracts hashed lexemes from tsvector with additional information.
600
+ */
578
601
Datum
579
602
rum_extract_tsvector_hash (PG_FUNCTION_ARGS )
580
603
{
@@ -592,6 +615,14 @@ rum_extract_tsvector_hash(PG_FUNCTION_ARGS)
592
615
PG_RETURN_POINTER (entries );
593
616
}
594
617
618
+ /*
619
+ * Extracting tsquery lexemes.
620
+ */
621
+
622
+ /*
623
+ * Extracts tsquery lexemes from **query**. Uses **build_tsquery_entry**
624
+ * callback to extract lexeme.
625
+ */
595
626
static Datum *
596
627
rum_extract_tsquery_internal (TSQuery query ,
597
628
int32 * nentries ,
@@ -640,11 +671,6 @@ rum_extract_tsquery_internal(TSQuery query,
640
671
641
672
for (i = 0 ; i < (* nentries ); i ++ )
642
673
{
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 );
648
674
entries [i ] = build_tsquery_entry (query , operands [i ]);
649
675
partialmatch [i ] = operands [i ]-> prefix ;
650
676
(* extra_data )[i ] = (Pointer ) map_item_operand ;
@@ -679,6 +705,9 @@ rum_extract_tsquery_internal(TSQuery query,
679
705
return entries ;
680
706
}
681
707
708
+ /*
709
+ * Extract lexeme from tsquery.
710
+ */
682
711
static Datum
683
712
build_tsquery_entry (TSQuery query , QueryOperand * operand )
684
713
{
@@ -689,6 +718,9 @@ build_tsquery_entry(TSQuery query, QueryOperand *operand)
689
718
return PointerGetDatum (txt );
690
719
}
691
720
721
+ /*
722
+ * Extract hashed lexeme from tsquery.
723
+ */
692
724
static Datum
693
725
build_tsquery_hash_entry (TSQuery query , QueryOperand * operand )
694
726
{
@@ -700,6 +732,9 @@ build_tsquery_hash_entry(TSQuery query, QueryOperand *operand)
700
732
return hash_value ;
701
733
}
702
734
735
+ /*
736
+ * Extracts lexemes from tsquery with information about prefix search syntax.
737
+ */
703
738
Datum
704
739
rum_extract_tsquery (PG_FUNCTION_ARGS )
705
740
{
@@ -723,6 +758,10 @@ rum_extract_tsquery(PG_FUNCTION_ARGS)
723
758
PG_RETURN_POINTER (entries );
724
759
}
725
760
761
+ /*
762
+ * Extracts hashed lexemes from tsquery with information about prefix search
763
+ * syntax.
764
+ */
726
765
Datum
727
766
rum_extract_tsquery_hash (PG_FUNCTION_ARGS )
728
767
{
@@ -746,6 +785,10 @@ rum_extract_tsquery_hash(PG_FUNCTION_ARGS)
746
785
PG_RETURN_POINTER (entries );
747
786
}
748
787
788
+ /*
789
+ * Functions used for ranking.
790
+ */
791
+
749
792
static int
750
793
compareDocR (const void * va , const void * vb )
751
794
{
@@ -1297,6 +1340,10 @@ calc_score(float4 *arrdata, TSVector txt, TSQuery query, int method)
1297
1340
return (float4 ) Wdoc ;
1298
1341
}
1299
1342
1343
+ /*
1344
+ * Calculates distance inside index. Uses additional information with lexemes
1345
+ * positions.
1346
+ */
1300
1347
Datum
1301
1348
rum_tsquery_distance (PG_FUNCTION_ARGS )
1302
1349
{
@@ -1320,6 +1367,9 @@ rum_tsquery_distance(PG_FUNCTION_ARGS)
1320
1367
PG_RETURN_FLOAT8 (1.0 / res );
1321
1368
}
1322
1369
1370
+ /*
1371
+ * Implementation of <=> operator. Uses default normalization method.
1372
+ */
1323
1373
Datum
1324
1374
rum_ts_distance_tt (PG_FUNCTION_ARGS )
1325
1375
{
@@ -1337,6 +1387,9 @@ rum_ts_distance_tt(PG_FUNCTION_ARGS)
1337
1387
PG_RETURN_FLOAT4 (1.0 / res );
1338
1388
}
1339
1389
1390
+ /*
1391
+ * Implementation of <=> operator. Uses specified normalization method.
1392
+ */
1340
1393
Datum
1341
1394
rum_ts_distance_ttf (PG_FUNCTION_ARGS )
1342
1395
{
@@ -1355,6 +1408,9 @@ rum_ts_distance_ttf(PG_FUNCTION_ARGS)
1355
1408
PG_RETURN_FLOAT4 (1.0 / res );
1356
1409
}
1357
1410
1411
+ /*
1412
+ * Implementation of <=> operator. Uses specified normalization method.
1413
+ */
1358
1414
Datum
1359
1415
rum_ts_distance_td (PG_FUNCTION_ARGS )
1360
1416
{
@@ -1401,6 +1457,9 @@ rum_ts_distance_td(PG_FUNCTION_ARGS)
1401
1457
PG_RETURN_FLOAT4 (1.0 / res );
1402
1458
}
1403
1459
1460
+ /*
1461
+ * Casts tsquery to rum_distance_query type.
1462
+ */
1404
1463
Datum
1405
1464
tsquery_to_distance_query (PG_FUNCTION_ARGS )
1406
1465
{
@@ -1426,6 +1485,9 @@ tsquery_to_distance_query(PG_FUNCTION_ARGS)
1426
1485
PG_RETURN_DATUM (HeapTupleGetDatum (htup ));
1427
1486
}
1428
1487
1488
+ /*
1489
+ * Specifies additional information type for operator class.
1490
+ */
1429
1491
Datum
1430
1492
rum_tsvector_config (PG_FUNCTION_ARGS )
1431
1493
{
0 commit comments