@@ -99,14 +99,21 @@ typedef struct
99
99
int32 pos ;
100
100
} DocRepresentation ;
101
101
102
+ typedef struct
103
+ {
104
+ bool operandexist ;
105
+ WordEntryPos pos ;
106
+ }
107
+ QueryRepresentationOperand ;
108
+
102
109
typedef struct
103
110
{
104
111
TSQuery query ;
105
112
/* Used in rum_tsquery_distance() */
106
113
int * map_item_operand ;
107
114
108
- bool * operandexist ;
109
- int lenght ;
115
+ QueryRepresentationOperand * operandData ;
116
+ int length ;
110
117
} QueryRepresentation ;
111
118
112
119
typedef struct
@@ -135,8 +142,8 @@ static WordEntryPosVector POSNULL = {
135
142
#define RANK_NORM_RDIVRPLUS1 0x20
136
143
#define DEF_NORM_METHOD RANK_NO_NORM
137
144
138
- #define QR_GET_OPERAND_EXISTS (q , v ) ( (q)->operandexist[ ((QueryItem*)(v)) - GETQUERY((q)->query) ] )
139
- #define QR_SET_OPERAND_EXISTS ( q , v ) QR_GET_OPERAND_EXISTS(q,v) = true
145
+ #define QR_GET_OPERAND (q , v ) \
146
+ (&((q)->operandData[ ((QueryItem*)(v)) - GETQUERY((q)->query) ]))
140
147
141
148
static bool
142
149
pre_checkcondition_rum (void * checkval , QueryOperand * val , ExecPhraseData * data )
@@ -826,15 +833,23 @@ checkcondition_QueryOperand(void *checkval, QueryOperand *val,
826
833
ExecPhraseData * data )
827
834
{
828
835
QueryRepresentation * qr = (QueryRepresentation * ) checkval ;
836
+ QueryRepresentationOperand * qro ;
829
837
830
838
/* Check for rum_tsquery_distance() */
831
839
if (qr -> map_item_operand != NULL )
840
+ qro = qr -> operandData +
841
+ qr -> map_item_operand [(QueryItem * ) val - GETQUERY (qr -> query )];
842
+ else
843
+ qro = QR_GET_OPERAND (qr , val );
844
+
845
+ if (data && qro -> operandexist )
832
846
{
833
- int i = (QueryItem * ) val - GETQUERY (qr -> query );
834
- return qr -> operandexist [qr -> map_item_operand [i ]];
847
+ data -> npos = 1 ;
848
+ data -> pos = & qro -> pos ;
849
+ data -> allocated = false;
835
850
}
836
851
837
- return QR_GET_OPERAND_EXISTS ( qr , val ) ;
852
+ return qro -> operandexist ;
838
853
}
839
854
840
855
static bool
@@ -850,7 +865,7 @@ Cover(DocRepresentation *doc, uint32 len, QueryRepresentation *qr,
850
865
lastpos = ext -> pos ;
851
866
found = false;
852
867
853
- memset (qr -> operandexist , 0 , sizeof (bool ) * qr -> lenght );
868
+ memset (qr -> operandData , 0 , sizeof (qr -> operandData [ 0 ] ) * qr -> length );
854
869
855
870
ext -> p = 0x7fffffff ;
856
871
ext -> q = 0 ;
@@ -859,16 +874,28 @@ Cover(DocRepresentation *doc, uint32 len, QueryRepresentation *qr,
859
874
/* find upper bound of cover from current position, move up */
860
875
while (ptr - doc < len )
861
876
{
877
+ QueryRepresentationOperand * qro ;
878
+
862
879
if (qr -> map_item_operand != NULL )
863
880
{
864
- qr -> operandexist [ptr -> data .key .keyn ] = true;
881
+ qro = qr -> operandData + ptr -> data .key .keyn ;
882
+ qro -> operandexist = true;
883
+ WEP_SETPOS (qro -> pos , ptr -> pos );
884
+ WEP_SETWEIGHT (qro -> pos , ptr -> wclass );
865
885
}
866
886
else
867
887
{
868
888
for (i = 0 ; i < ptr -> data .item .nitem ; i ++ )
869
- QR_SET_OPERAND_EXISTS (qr , ptr -> data .item .item [i ]);
889
+ {
890
+ qro = QR_GET_OPERAND (qr , ptr -> data .item .item [i ]);
891
+ qro -> operandexist = true;
892
+ WEP_SETPOS (qro -> pos , ptr -> pos );
893
+ WEP_SETWEIGHT (qro -> pos , ptr -> wclass );
894
+ }
870
895
}
871
- if (TS_execute (GETQUERY (qr -> query ), (void * ) qr , false,
896
+
897
+
898
+ if (TS_execute (GETQUERY (qr -> query ), (void * ) qr , TS_EXEC_EMPTY ,
872
899
checkcondition_QueryOperand ))
873
900
{
874
901
if (ptr -> pos > ext -> q )
@@ -886,7 +913,7 @@ Cover(DocRepresentation *doc, uint32 len, QueryRepresentation *qr,
886
913
if (!found )
887
914
return false;
888
915
889
- memset (qr -> operandexist , 0 , sizeof (bool ) * qr -> lenght );
916
+ memset (qr -> operandData , 0 , sizeof (qr -> operandData [ 0 ] ) * qr -> length );
890
917
891
918
ptr = doc + lastpos ;
892
919
@@ -895,14 +922,21 @@ Cover(DocRepresentation *doc, uint32 len, QueryRepresentation *qr,
895
922
{
896
923
if (qr -> map_item_operand != NULL )
897
924
{
898
- qr -> operandexist [ptr -> data .key .keyn ] = true;
925
+ qr -> operandData [ptr -> data .key .keyn ]. operandexist = true;
899
926
}
900
927
else
901
928
{
902
929
for (i = 0 ; i < ptr -> data .item .nitem ; i ++ )
903
- QR_SET_OPERAND_EXISTS (qr , ptr -> data .item .item [i ]);
930
+ {
931
+ QueryRepresentationOperand * qro =
932
+ QR_GET_OPERAND (qr , ptr -> data .item .item [i ]);
933
+
934
+ qro -> operandexist = true;
935
+ WEP_SETPOS (qro -> pos , ptr -> pos );
936
+ WEP_SETWEIGHT (qro -> pos , ptr -> wclass );
937
+ }
904
938
}
905
- if (TS_execute (GETQUERY (qr -> query ), (void * ) qr , true ,
939
+ if (TS_execute (GETQUERY (qr -> query ), (void * ) qr , TS_EXEC_CALC_NOT ,
906
940
checkcondition_QueryOperand ))
907
941
{
908
942
if (ptr -> pos < ext -> p )
@@ -1083,7 +1117,7 @@ get_docrep(TSVector txt, QueryRepresentation *qr, uint32 *doclen)
1083
1117
1084
1118
curoperand = & item [i ].qoperand ;
1085
1119
1086
- if (QR_GET_OPERAND_EXISTS (qr , & item [i ]))
1120
+ if (QR_GET_OPERAND (qr , & item [i ])-> operandexist )
1087
1121
continue ;
1088
1122
1089
1123
firstentry = entry = find_wordentry (txt , qr -> query , curoperand , & nitem );
@@ -1128,14 +1162,21 @@ get_docrep(TSVector txt, QueryRepresentation *qr, uint32 *doclen)
1128
1162
(item [k ].type == QI_VAL &&
1129
1163
compareQueryOperand (& kptr , & iptr , operand ) == 0 ))
1130
1164
{
1165
+ QueryRepresentationOperand * qro ;
1166
+
1131
1167
/*
1132
1168
* if k == i, we've already checked above that
1133
1169
* it's type == Q_VAL
1134
1170
*/
1135
1171
doc [cur ].data .item .item [doc [cur ].data .item .nitem ] =
1136
1172
item + k ;
1137
1173
doc [cur ].data .item .nitem ++ ;
1138
- QR_SET_OPERAND_EXISTS (qr , item + k );
1174
+
1175
+ qro = QR_GET_OPERAND (qr , item + k );
1176
+
1177
+ qro -> operandexist = true;
1178
+ qro -> pos = post [j ];
1179
+
1139
1180
}
1140
1181
}
1141
1182
}
@@ -1236,8 +1277,8 @@ calc_score_docr(float4 *arrdata, DocRepresentation *doc, uint32 doclen,
1236
1277
cover_keys [new_cover_idx ] = new_cover_key ;
1237
1278
1238
1279
/* Compute the number of query terms in the cover */
1239
- for (i = 0 ; i < qr -> lenght ; i ++ )
1240
- if (qr -> operandexist [i ])
1280
+ for (i = 0 ; i < qr -> length ; i ++ )
1281
+ if (qr -> operandData [i ]. operandexist )
1241
1282
nitems ++ ;
1242
1283
1243
1284
Cpos = ((double ) (ext .end - ext .begin + 1 )) / InvSum ;
@@ -1298,20 +1339,20 @@ calc_score_addinfo(float4 *arrdata, bool *check, TSQuery query,
1298
1339
1299
1340
qr .query = query ;
1300
1341
qr .map_item_operand = map_item_operand ;
1301
- qr .operandexist = ( bool * ) palloc0 (sizeof (bool ) * nkeys );
1302
- qr .lenght = nkeys ;
1342
+ qr .operandData = palloc0 (sizeof (qr . operandData [ 0 ] ) * nkeys );
1343
+ qr .length = nkeys ;
1303
1344
1304
1345
doc = get_docrep_addinfo (check , & qr , addInfo , addInfoIsNull , & doclen );
1305
1346
if (!doc )
1306
1347
{
1307
- pfree (qr .operandexist );
1348
+ pfree (qr .operandData );
1308
1349
return 0.0 ;
1309
1350
}
1310
1351
1311
1352
Wdoc = calc_score_docr (arrdata , doc , doclen , & qr , DEF_NORM_METHOD );
1312
1353
1313
1354
pfree (doc );
1314
- pfree (qr .operandexist );
1355
+ pfree (qr .operandData );
1315
1356
1316
1357
return (float4 ) Wdoc ;
1317
1358
}
@@ -1327,13 +1368,13 @@ calc_score(float4 *arrdata, TSVector txt, TSQuery query, int method)
1327
1368
1328
1369
qr .query = query ;
1329
1370
qr .map_item_operand = NULL ;
1330
- qr .operandexist = ( bool * ) palloc0 (sizeof (bool ) * query -> size );
1331
- qr .lenght = query -> size ;
1371
+ qr .operandData = palloc0 (sizeof (qr . operandData [ 0 ] ) * query -> size );
1372
+ qr .length = query -> size ;
1332
1373
1333
1374
doc = get_docrep (txt , & qr , & doclen );
1334
1375
if (!doc )
1335
1376
{
1336
- pfree (qr .operandexist );
1377
+ pfree (qr .operandData );
1337
1378
return 0.0 ;
1338
1379
}
1339
1380
@@ -1356,7 +1397,7 @@ calc_score(float4 *arrdata, TSVector txt, TSQuery query, int method)
1356
1397
Wdoc /= log ((double ) (txt -> size + 1 )) / log (2.0 );
1357
1398
1358
1399
pfree (doc );
1359
- pfree (qr .operandexist );
1400
+ pfree (qr .operandData );
1360
1401
1361
1402
return (float4 ) Wdoc ;
1362
1403
}
0 commit comments