@@ -96,6 +96,7 @@ typedef struct
96
96
} key ;
97
97
} data ;
98
98
uint8 wclass ;
99
+ float4 idf ;
99
100
int32 pos ;
100
101
} DocRepresentation ;
101
102
@@ -106,20 +107,13 @@ typedef struct
106
107
}
107
108
QueryRepresentationOperand ;
108
109
109
- typedef struct
110
- {
111
- float4 idf ;
112
- bool idfloaded ;
113
- } QueryRepresentationIDF ;
114
-
115
110
typedef struct
116
111
{
117
112
TSQuery query ;
118
113
/* Used in rum_tsquery_distance() */
119
114
int * map_item_operand ;
120
115
121
116
QueryRepresentationOperand * operandData ;
122
- QueryRepresentationIDF * operandIdf ;
123
117
int length ;
124
118
} QueryRepresentation ;
125
119
@@ -1098,7 +1092,7 @@ find_wordentry(TSVector t, TSQuery q, QueryOperand *item, int32 *nitem)
1098
1092
}
1099
1093
1100
1094
static DocRepresentation *
1101
- get_docrep (TSVector txt , QueryRepresentation * qr , uint32 * doclen )
1095
+ get_docrep (TSVector txt , QueryRepresentation * qr , uint32 * doclen , bool load_idf )
1102
1096
{
1103
1097
QueryItem * item = GETQUERY (qr -> query );
1104
1098
WordEntry * entry ,
@@ -1134,6 +1128,8 @@ get_docrep(TSVector txt, QueryRepresentation *qr, uint32 *doclen)
1134
1128
1135
1129
while (entry - firstentry < nitem )
1136
1130
{
1131
+ float4 idf ;
1132
+
1137
1133
if (entry -> haspos )
1138
1134
{
1139
1135
dimt = POSDATALEN (txt , entry );
@@ -1187,12 +1183,18 @@ get_docrep(TSVector txt, QueryRepresentation *qr, uint32 *doclen)
1187
1183
1188
1184
}
1189
1185
}
1186
+
1187
+ if (load_idf )
1188
+ idf = estimate_idf (STRPTR (txt ) + entry -> pos , entry -> len );
1189
+ else
1190
+ idf = 1.0f ;
1190
1191
}
1191
1192
else
1192
1193
{
1193
1194
doc [cur ].data .item .nitem = doc [cur - 1 ].data .item .nitem ;
1194
1195
doc [cur ].data .item .item = doc [cur - 1 ].data .item .item ;
1195
1196
}
1197
+ doc [cur ].idf = idf ;
1196
1198
doc [cur ].pos = WEP_GETPOS (post [j ]);
1197
1199
doc [cur ].wclass = WEP_GETWEIGHT (post [j ]);
1198
1200
cur ++ ;
@@ -1256,6 +1258,7 @@ calc_score_docr(float4 *arrdata, DocRepresentation *doc, uint32 doclen,
1256
1258
/* For rum_tsquery_distance() */
1257
1259
else
1258
1260
new_cover_key += (int )(uintptr_t )ptr -> data .key .item_first ;
1261
+ Idf += ptr -> idf ;
1259
1262
ptr ++ ;
1260
1263
}
1261
1264
@@ -1287,43 +1290,16 @@ calc_score_docr(float4 *arrdata, DocRepresentation *doc, uint32 doclen,
1287
1290
1288
1291
/* Compute the number of query terms in the cover */
1289
1292
for (i = 0 ; i < qr -> length ; i ++ )
1290
- {
1291
1293
if (qr -> operandData [i ].operandexist )
1292
- {
1293
- if (method & RANK_NORM_IDF )
1294
- {
1295
- if (!qr -> operandIdf [i ].idfloaded )
1296
- {
1297
- QueryOperand * oper = (QueryOperand * ) (GETQUERY (qr -> query ) + i );
1298
- qr -> operandIdf [i ].idf =
1299
- estimate_idf (
1300
- GETOPERAND (qr -> query ) + oper -> distance ,
1301
- oper -> length
1302
- );
1303
- qr -> operandIdf [i ].idfloaded = true;
1304
- }
1305
-
1306
- Idf += qr -> operandIdf [i ].idf ;
1307
- }
1308
- else
1309
- {
1310
- nitems ++ ;
1311
- }
1312
- }
1313
- }
1294
+ nitems ++ ;
1314
1295
1315
1296
Cpos = ((double ) (ext .end - ext .begin + 1 )) / InvSum ;
1316
1297
1298
+ if (nitems > 0 )
1299
+ Cpos *= nitems ;
1300
+
1317
1301
if (method & RANK_NORM_IDF )
1318
- {
1319
- if (Idf >= 1.0 )
1320
- Cpos *= Idf ;
1321
- }
1322
- else
1323
- {
1324
- if (nitems > 0 )
1325
- Cpos *= nitems ;
1326
- }
1302
+ Cpos *= Idf ;
1327
1303
1328
1304
/*
1329
1305
* if doc are big enough then ext.q may be equal to ext.p due to limit
@@ -1408,11 +1384,9 @@ calc_score(float4 *arrdata, TSVector txt, TSQuery query, int method)
1408
1384
qr .query = query ;
1409
1385
qr .map_item_operand = NULL ;
1410
1386
qr .operandData = palloc0 (sizeof (qr .operandData [0 ]) * query -> size );
1411
- if (method & RANK_NORM_IDF )
1412
- qr .operandIdf = palloc0 (sizeof (qr .operandIdf [0 ]) * query -> size );
1413
1387
qr .length = query -> size ;
1414
1388
1415
- doc = get_docrep (txt , & qr , & doclen );
1389
+ doc = get_docrep (txt , & qr , & doclen , ( method & RANK_NORM_IDF ) ? true : false );
1416
1390
if (!doc )
1417
1391
{
1418
1392
pfree (qr .operandData );
0 commit comments