@@ -49,6 +49,7 @@ typedef struct
49
49
{
50
50
QueryItem * * item ;
51
51
int16 nitem ;
52
+ int32 keyn ;
52
53
uint8 wclass ;
53
54
int32 pos ;
54
55
} DocRepresentation ;
@@ -608,9 +609,10 @@ checkcondition_QueryOperand(void *checkval, QueryOperand *val,
608
609
609
610
static bool
610
611
Cover (DocRepresentation * doc , uint32 len , QueryRepresentation * qr ,
611
- Extention * ext )
612
+ int * map_item_operand , Extention * ext )
612
613
{
613
614
DocRepresentation * ptr ;
615
+ QueryItem * item = GETQUERY (qr -> query );
614
616
int lastpos = ext -> pos ;
615
617
int i ;
616
618
bool found = false;
@@ -630,11 +632,17 @@ Cover(DocRepresentation *doc, uint32 len, QueryRepresentation *qr,
630
632
/* find upper bound of cover from current position, move up */
631
633
while (ptr - doc < len )
632
634
{
633
- for ( i = 0 ; i < ptr -> nitem ; i ++ )
635
+ if ( ptr -> item != NULL )
634
636
{
635
- if ( ptr -> item [ i ] -> type == QI_VAL )
637
+ for ( i = 0 ; i < ptr -> nitem ; i ++ )
636
638
QR_SET_OPERAND_EXISTS (qr , ptr -> item [i ]);
637
639
}
640
+ else
641
+ {
642
+ for (i = 0 ; i < qr -> query -> size ; i ++ )
643
+ if (ptr -> keyn == map_item_operand [i ])
644
+ QR_SET_OPERAND_EXISTS (qr , item + i );
645
+ }
638
646
if (TS_execute (GETQUERY (qr -> query ), (void * ) qr , false,
639
647
checkcondition_QueryOperand ))
640
648
{
@@ -660,9 +668,17 @@ Cover(DocRepresentation *doc, uint32 len, QueryRepresentation *qr,
660
668
/* find lower bound of cover from found upper bound, move down */
661
669
while (ptr >= doc + ext -> pos )
662
670
{
663
- for (i = 0 ; i < ptr -> nitem ; i ++ )
664
- if (ptr -> item [i ]-> type == QI_VAL )
671
+ if (ptr -> item != NULL )
672
+ {
673
+ for (i = 0 ; i < ptr -> nitem ; i ++ )
665
674
QR_SET_OPERAND_EXISTS (qr , ptr -> item [i ]);
675
+ }
676
+ else
677
+ {
678
+ for (i = 0 ; i < qr -> query -> size ; i ++ )
679
+ if (ptr -> keyn == map_item_operand [i ])
680
+ QR_SET_OPERAND_EXISTS (qr , item + i );
681
+ }
666
682
if (TS_execute (GETQUERY (qr -> query ), (void * ) qr , true,
667
683
checkcondition_QueryOperand ))
668
684
{
@@ -687,7 +703,7 @@ Cover(DocRepresentation *doc, uint32 len, QueryRepresentation *qr,
687
703
}
688
704
689
705
ext -> pos ++ ;
690
- return Cover (doc , len , qr , ext );
706
+ return Cover (doc , len , qr , map_item_operand , ext );
691
707
}
692
708
693
709
static DocRepresentation *
@@ -745,34 +761,8 @@ get_docrep_addinfo(bool *check, QueryRepresentation *qr, int *map_item_operand,
745
761
else
746
762
ptrt = decompress_pos (ptrt , & post );
747
763
748
- if (j == 0 )
749
- {
750
- int k ;
751
-
752
- doc [cur ].nitem = 0 ;
753
- doc [cur ].item = (QueryItem * * ) palloc (sizeof (QueryItem * ) *
754
- qr -> query -> size );
755
-
756
- for (k = 0 ; k < qr -> query -> size ; k ++ )
757
- {
758
- if (k == i ||
759
- (item [k ].type == QI_VAL && map_item_operand [i ] ==
760
- map_item_operand [k ]))
761
- {
762
- /*
763
- * if k == i, we've already checked above that
764
- * it's type == Q_VAL
765
- */
766
- doc [cur ].item [doc [cur ].nitem ] = item + k ;
767
- doc [cur ].nitem ++ ;
768
- }
769
- }
770
- }
771
- else
772
- {
773
- doc [cur ].nitem = doc [cur - 1 ].nitem ;
774
- doc [cur ].item = doc [cur - 1 ].item ;
775
- }
764
+ doc [cur ].item = NULL ;
765
+ doc [cur ].keyn = keyN ;
776
766
doc [cur ].pos = WEP_GETPOS (post );
777
767
doc [cur ].wclass = WEP_GETWEIGHT (post );
778
768
cur ++ ;
@@ -932,6 +922,7 @@ get_docrep(TSVector txt, QueryRepresentation *qr, uint32 *doclen)
932
922
doc [cur ].nitem = doc [cur - 1 ].nitem ;
933
923
doc [cur ].item = doc [cur - 1 ].item ;
934
924
}
925
+ doc [cur ].keyn = -1 ;
935
926
doc [cur ].pos = WEP_GETPOS (post [j ]);
936
927
doc [cur ].wclass = WEP_GETWEIGHT (post [j ]);
937
928
cur ++ ;
@@ -955,7 +946,7 @@ get_docrep(TSVector txt, QueryRepresentation *qr, uint32 *doclen)
955
946
956
947
static double
957
948
calc_score_docr (float4 * arrdata , DocRepresentation * doc , uint32 doclen ,
958
- QueryRepresentation * qr , int method )
949
+ QueryRepresentation * qr , int * map_item_operand , int method )
959
950
{
960
951
int32 i ;
961
952
Extention ext ;
@@ -972,7 +963,7 @@ calc_score_docr(float4 *arrdata, DocRepresentation *doc, uint32 doclen,
972
963
int ncovers = 0 ;
973
964
974
965
MemSet (& ext , 0 , sizeof (Extention ));
975
- while (Cover (doc , doclen , qr , & ext ))
966
+ while (Cover (doc , doclen , qr , map_item_operand , & ext ))
976
967
{
977
968
double Cpos = 0.0 ;
978
969
double InvSum = 0.0 ;
@@ -1091,7 +1082,8 @@ calc_score_addinfo(float4 *arrdata, bool *check, TSQuery query,
1091
1082
return 0.0 ;
1092
1083
}
1093
1084
1094
- Wdoc = calc_score_docr (arrdata , doc , doclen , & qr , DEF_NORM_METHOD );
1085
+ Wdoc = calc_score_docr (arrdata , doc , doclen , & qr , map_item_operand ,
1086
+ DEF_NORM_METHOD );
1095
1087
1096
1088
pfree (doc );
1097
1089
pfree (qr .operandexist );
@@ -1118,7 +1110,7 @@ calc_score(float4 *arrdata, TSVector txt, TSQuery query, int method)
1118
1110
return 0.0 ;
1119
1111
}
1120
1112
1121
- Wdoc = calc_score_docr (arrdata , doc , doclen , & qr , method );
1113
+ Wdoc = calc_score_docr (arrdata , doc , doclen , & qr , NULL , method );
1122
1114
1123
1115
if ((method & RANK_NORM_LOGLENGTH ) && txt -> size > 0 )
1124
1116
Wdoc /= log ((double ) (count_length (txt ) + 1 ));
0 commit comments