@@ -24,6 +24,7 @@ PG_FUNCTION_INFO_V1(rum_extract_tsvector);
24
24
PG_FUNCTION_INFO_V1 (rum_extract_tsquery );
25
25
PG_FUNCTION_INFO_V1 (rum_tsvector_config );
26
26
PG_FUNCTION_INFO_V1 (rum_tsquery_pre_consistent );
27
+ PG_FUNCTION_INFO_V1 (rum_tsquery_consistent );
27
28
PG_FUNCTION_INFO_V1 (rum_tsquery_distance );
28
29
PG_FUNCTION_INFO_V1 (rum_ts_distance );
29
30
@@ -43,23 +44,27 @@ static float calc_rank_pos_or(float *w, Datum *addInfo, bool *addInfoIsNull,
43
44
44
45
static float calc_rank_or (const float * w , TSVector t , TSQuery q );
45
46
static float calc_rank_and (const float * w , TSVector t , TSQuery q );
47
+ static int count_pos (char * ptr , int len );
48
+ static char * decompress_pos (char * ptr , uint16 * pos );
46
49
47
- typedef struct
50
+ typedef struct
48
51
{
49
52
QueryItem * first_item ;
50
- bool * check ;
51
53
int * map_item_operand ;
54
+ bool * check ;
52
55
bool * need_recheck ;
56
+ Datum * addInfo ;
57
+ bool * addInfoIsNull ;
53
58
} RumChkVal ;
54
59
55
60
static bool
56
- checkcondition_rum (void * checkval , QueryOperand * val , ExecPhraseData * data )
61
+ pre_checkcondition_rum (void * checkval , QueryOperand * val , ExecPhraseData * data )
57
62
{
58
63
RumChkVal * gcv = (RumChkVal * ) checkval ;
59
64
int j ;
60
65
61
66
/* if any val requiring a weight is used, set recheck flag */
62
- if (val -> weight != 0 )
67
+ if (val -> weight != 0 || data != NULL )
63
68
* (gcv -> need_recheck ) = true;
64
69
65
70
/* convert item's number to corresponding entry's (operand's) number */
@@ -76,8 +81,8 @@ rum_tsquery_pre_consistent(PG_FUNCTION_ARGS)
76
81
77
82
TSQuery query = PG_GETARG_TSQUERY (2 );
78
83
79
- Pointer * extra_data = (Pointer * ) PG_GETARG_POINTER (4 );
80
- bool recheck ;
84
+ Pointer * extra_data = (Pointer * ) PG_GETARG_POINTER (4 );
85
+ bool recheck ;
81
86
bool res = FALSE;
82
87
83
88
if (query -> size > 0 )
@@ -97,12 +102,95 @@ rum_tsquery_pre_consistent(PG_FUNCTION_ARGS)
97
102
res = TS_execute (GETQUERY (query ),
98
103
& gcv ,
99
104
false,
100
- checkcondition_rum );
105
+ pre_checkcondition_rum );
101
106
}
102
107
103
108
PG_RETURN_BOOL (res );
104
109
}
105
110
111
+ static bool
112
+ checkcondition_rum (void * checkval , QueryOperand * val , ExecPhraseData * data )
113
+ {
114
+ RumChkVal * gcv = (RumChkVal * ) checkval ;
115
+ int j ;
116
+
117
+ /* if any val requiring a weight is used, set recheck flag */
118
+ if (val -> weight != 0 )
119
+ * (gcv -> need_recheck ) = true;
120
+
121
+ /* convert item's number to corresponding entry's (operand's) number */
122
+ j = gcv -> map_item_operand [((QueryItem * ) val ) - gcv -> first_item ];
123
+
124
+ /* return presence of current entry in indexed value */
125
+ if (!gcv -> check [j ])
126
+ return false;
127
+
128
+ if (data && gcv -> addInfo && gcv -> addInfoIsNull [j ] == false)
129
+ {
130
+ bytea * positions = DatumGetByteaP (gcv -> addInfo [j ]);
131
+ int32 i ;
132
+ char * ptrt ;
133
+ WordEntryPos post ;
134
+
135
+ data -> npos = count_pos (VARDATA_ANY (positions ),
136
+ VARSIZE_ANY_EXHDR (positions ));
137
+ data -> pos = palloc (sizeof (* data -> pos ) * data -> npos );
138
+ data -> allocated = true;
139
+
140
+ ptrt = (char * )VARDATA_ANY (positions );
141
+ post = 0 ;
142
+
143
+ for (i = 0 ; i < data -> npos ; i ++ )
144
+ {
145
+ ptrt = decompress_pos (ptrt , & post );
146
+ data -> pos [i ] = post ;
147
+ }
148
+ }
149
+
150
+ return true;
151
+ }
152
+
153
+ Datum
154
+ rum_tsquery_consistent (PG_FUNCTION_ARGS )
155
+ {
156
+ bool * check = (bool * ) PG_GETARG_POINTER (0 );
157
+ /* StrategyNumber strategy = PG_GETARG_UINT16(1); */
158
+ TSQuery query = PG_GETARG_TSQUERY (2 );
159
+ /* int32 nkeys = PG_GETARG_INT32(3); */
160
+ Pointer * extra_data = (Pointer * ) PG_GETARG_POINTER (4 );
161
+ bool * recheck = (bool * ) PG_GETARG_POINTER (5 );
162
+ Datum * addInfo = (Datum * ) PG_GETARG_POINTER (8 );
163
+ bool * addInfoIsNull = (bool * ) PG_GETARG_POINTER (9 );
164
+ bool res = FALSE;
165
+
166
+ /* The query requires recheck only if it involves
167
+ * weights */
168
+ * recheck = false;
169
+
170
+ if (query -> size > 0 )
171
+ {
172
+ QueryItem * item ;
173
+ RumChkVal gcv ;
174
+
175
+ /*
176
+ * check-parameter array has one entry for each value
177
+ * (operand) in the query.
178
+ */
179
+ gcv .first_item = item = GETQUERY (query );
180
+ gcv .check = check ;
181
+ gcv .map_item_operand = (int * ) (extra_data [0 ]);
182
+ gcv .need_recheck = recheck ;
183
+ gcv .addInfo = addInfo ;
184
+ gcv .addInfoIsNull = addInfoIsNull ;
185
+
186
+ res = TS_execute (GETQUERY (query ), & gcv , true, checkcondition_rum );
187
+ }
188
+
189
+ PG_RETURN_BOOL (res );
190
+ }
191
+
192
+
193
+
106
194
static float weights [] = {0.1f , 0.2f , 0.4f , 1.0f };
107
195
108
196
#define wpos (wep ) ( w[ WEP_GETWEIGHT(wep) ] )
@@ -409,7 +497,8 @@ calc_rank_pos(float *w, TSQuery q, Datum *addInfo, bool *addInfoIsNull, int size
409
497
return 0.0 ;
410
498
411
499
/* XXX: What about NOT? */
412
- res = (item -> type == QI_OPR && item -> qoperator .oper == OP_AND ) ?
500
+ res = (item -> type == QI_OPR && (item -> qoperator .oper == OP_AND ||
501
+ item -> qoperator .oper == OP_PHRASE )) ?
413
502
calc_rank_pos_and (w , addInfo , addInfoIsNull , size ) :
414
503
calc_rank_pos_or (w , addInfo , addInfoIsNull , size );
415
504
@@ -801,7 +890,7 @@ rum_extract_tsquery(PG_FUNCTION_ARGS)
801
890
j ;
802
891
bool * partialmatch ;
803
892
int * map_item_operand ;
804
- char * operand = GETOPERAND (query );
893
+ char * operand = GETOPERAND (query );
805
894
QueryOperand * * operands ;
806
895
807
896
/*
0 commit comments