34 |
#define GET_STR(textp) DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(textp))) |
#define GET_STR(textp) DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(textp))) |
35 |
#define GET_TEXT(cstrp) DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(cstrp))) |
#define GET_TEXT(cstrp) DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(cstrp))) |
36 |
|
|
37 |
|
/* SortMem got renamed in PostgreSQL 8.0 */ |
38 |
|
#ifndef SortMem |
39 |
|
#define SortMem 16 * 1024 |
40 |
|
#endif |
41 |
|
|
42 |
|
#define ATTR_DELIMITER "{{!}}" |
43 |
|
|
44 |
/* prototype */ |
/* prototype */ |
45 |
char *attr2text(ESTDOC *doc, char *attr); |
char *attr2text(ESTDOC *doc, char *attr); |
46 |
|
|
49 |
PG_FUNCTION_INFO_V1(pgest_attr); |
PG_FUNCTION_INFO_V1(pgest_attr); |
50 |
Datum pgest_attr(PG_FUNCTION_ARGS) |
Datum pgest_attr(PG_FUNCTION_ARGS) |
51 |
{ |
{ |
52 |
ArrayType *attr_arr = PG_GETARG_ARRAYTYPE_P(5); |
ArrayType *attr_arr = PG_GETARG_ARRAYTYPE_P(6); |
53 |
Oid attr_element_type = ARR_ELEMTYPE(attr_arr); |
Oid attr_element_type = ARR_ELEMTYPE(attr_arr); |
54 |
int attr_ndims = ARR_NDIM(attr_arr); |
int attr_ndims = ARR_NDIM(attr_arr); |
55 |
int *attr_dim_counts = ARR_DIMS(attr_arr); |
int *attr_dim_counts = ARR_DIMS(attr_arr); |
83 |
char *index_path; |
char *index_path; |
84 |
char *query; |
char *query; |
85 |
char *attr; |
char *attr; |
86 |
|
char *order; |
87 |
|
|
88 |
|
|
89 |
/* only allow 1D input array */ |
/* only allow 1D input array */ |
146 |
index_path = _textout(PG_GETARG_TEXT_P(0)); |
index_path = _textout(PG_GETARG_TEXT_P(0)); |
147 |
|
|
148 |
/* query string */ |
/* query string */ |
149 |
if (PG_ARGISNULL(0)) { |
if (PG_ARGISNULL(1)) { |
150 |
query = ""; |
query = ""; |
151 |
} else { |
} else { |
152 |
query = _textout(PG_GETARG_TEXT_P(1)); |
query = _textout(PG_GETARG_TEXT_P(1)); |
158 |
} else { |
} else { |
159 |
attr = _textout(PG_GETARG_TEXT_P(2)); |
attr = _textout(PG_GETARG_TEXT_P(2)); |
160 |
} |
} |
161 |
|
|
162 |
|
/* sort order */ |
163 |
|
if (PG_ARGISNULL(3)) { |
164 |
|
order = ""; |
165 |
|
} else { |
166 |
|
order = _textout(PG_GETARG_TEXT_P(3)); |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
/* limit */ |
/* limit */ |
171 |
if (PG_ARGISNULL(3)) { |
if (PG_ARGISNULL(4)) { |
172 |
limit = 0; |
limit = 0; |
173 |
} else { |
} else { |
174 |
limit = PG_GETARG_INT32(3); |
limit = PG_GETARG_INT32(4); |
175 |
} |
} |
176 |
|
|
177 |
/* offset */ |
/* offset */ |
178 |
if (PG_ARGISNULL(4)) { |
if (PG_ARGISNULL(5)) { |
179 |
offset = 0; |
offset = 0; |
180 |
} else { |
} else { |
181 |
offset = PG_GETARG_INT32(4); |
offset = PG_GETARG_INT32(5); |
182 |
} |
} |
183 |
|
|
184 |
|
|
205 |
|
|
206 |
/* minimum valid attribute length is 10: @a STREQ a */ |
/* minimum valid attribute length is 10: @a STREQ a */ |
207 |
if (! PG_ARGISNULL(2) && strlen(attr) >= 10) { |
if (! PG_ARGISNULL(2) && strlen(attr) >= 10) { |
208 |
elog(DEBUG1,"est_cond_add_attr(%s)", attr); |
elog(DEBUG1,"attributes: %s", attr); |
209 |
est_cond_add_attr(cond, attr); |
char *curr_attr; |
210 |
|
curr_attr = strtok(attr, ATTR_DELIMITER); |
211 |
|
while (curr_attr) { |
212 |
|
elog(DEBUG1,"est_cond_add_attr(%s)", curr_attr); |
213 |
|
est_cond_add_attr(cond, curr_attr); |
214 |
|
curr_attr = strtok(NULL, ATTR_DELIMITER); |
215 |
|
} |
216 |
|
} |
217 |
|
|
218 |
|
/* set the search phrase to the search condition object */ |
219 |
|
if (! PG_ARGISNULL(3) && strlen(order) > 0) { |
220 |
|
elog(DEBUG1,"est_cond_set_order(%s)", order); |
221 |
|
est_cond_set_order(cond, order); |
222 |
|
} |
223 |
|
|
224 |
|
if (limit) { |
225 |
|
elog(DEBUG1,"est_cond_set_max(%d)", limit + offset); |
226 |
|
est_cond_set_max(cond, limit + offset); |
227 |
} |
} |
228 |
|
|
229 |
/* get the result of search */ |
/* get the result of search */ |
236 |
|
|
237 |
/* total number of tuples to be returned */ |
/* total number of tuples to be returned */ |
238 |
if (limit && limit < resnum) { |
if (limit && limit < resnum) { |
239 |
nrows = limit - offset; |
nrows = limit; |
240 |
} else { |
} else { |
241 |
nrows = resnum - offset; |
nrows = resnum - offset; |
242 |
} |
} |
302 |
rsinfo->setDesc = tupdesc; |
rsinfo->setDesc = tupdesc; |
303 |
MemoryContextSwitchTo(oldcontext); |
MemoryContextSwitchTo(oldcontext); |
304 |
|
|
305 |
|
est_cond_delete(cond); |
306 |
|
|
307 |
if(!est_db_close(db, &ecode)){ |
if(!est_db_close(db, &ecode)){ |
308 |
ereport(ERROR, (errcode(ERRCODE_IO_ERROR), |
ereport(ERROR, (errcode(ERRCODE_IO_ERROR), |
309 |
errmsg("est_db_close: %d", ecode), |
errmsg("est_db_close: %d", ecode), |