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 |
|
/* prototype */ |
38 |
|
char *attr2text(ESTDOC *doc, char *attr); |
39 |
|
|
40 |
ESTDB *db; |
ESTDB *db; |
41 |
ESTCOND *cond; |
ESTCOND *cond; |
57 |
AttInMetadata *attinmeta; |
AttInMetadata *attinmeta; |
58 |
char *index_path; |
char *index_path; |
59 |
char *query; |
char *query; |
60 |
|
char *attr; |
61 |
|
|
62 |
/* stuff done only on the first call of the function */ |
/* stuff done only on the first call of the function */ |
63 |
if (SRF_IS_FIRSTCALL()) { |
if (SRF_IS_FIRSTCALL()) { |
67 |
//index_path = _textout(PG_GETARG_TEXT_P(0)); |
//index_path = _textout(PG_GETARG_TEXT_P(0)); |
68 |
index_path = _textout(PG_GETARG_TEXT_P(0)); |
index_path = _textout(PG_GETARG_TEXT_P(0)); |
69 |
query = _textout(PG_GETARG_TEXT_P(1)); |
query = _textout(PG_GETARG_TEXT_P(1)); |
70 |
limit = PG_GETARG_INT32(2); |
attr = _textout(PG_GETARG_TEXT_P(2)); |
71 |
offset = PG_GETARG_INT32(3); |
limit = PG_GETARG_INT32(3); |
72 |
|
offset = PG_GETARG_INT32(4); |
73 |
|
|
74 |
/* create a function context for cross-call persistence */ |
/* create a function context for cross-call persistence */ |
75 |
funcctx = SRF_FIRSTCALL_INIT(); |
funcctx = SRF_FIRSTCALL_INIT(); |
85 |
SRF_RETURN_DONE(funcctx); |
SRF_RETURN_DONE(funcctx); |
86 |
} |
} |
87 |
|
|
88 |
elog(INFO, "pgest: query=%s limit %d offset %d", query, limit, offset); |
elog(INFO, "pgest: query[%s] attr[%s] limit %d offset %d", query, attr, limit, offset); |
89 |
|
|
90 |
/* create a search condition object */ |
/* create a search condition object */ |
91 |
if (!(cond = est_cond_new())) { |
if (!(cond = est_cond_new())) { |
96 |
/* set the search phrase to the search condition object */ |
/* set the search phrase to the search condition object */ |
97 |
est_cond_set_phrase(cond, query); |
est_cond_set_phrase(cond, query); |
98 |
|
|
99 |
|
/* minimum valid attribute length is 10: @a STREQ a */ |
100 |
|
if (attr != NULL && strlen(attr) >= 10) { |
101 |
|
elog(INFO,"est_cond_add_attr(%s)", attr); |
102 |
|
est_cond_add_attr(cond, attr); |
103 |
|
} |
104 |
|
|
105 |
/* get the result of search */ |
/* get the result of search */ |
106 |
est_result = est_db_search(db, cond, &resnum, NULL); |
est_result = est_db_search(db, cond, &resnum, NULL); |
107 |
|
|
108 |
/* total number of tuples to be returned */ |
/* total number of tuples to be returned */ |
109 |
funcctx->max_calls = resnum; |
if (limit && limit < resnum) { |
110 |
|
funcctx->max_calls = limit - offset; |
111 |
|
} else { |
112 |
|
funcctx->max_calls = resnum - offset; |
113 |
|
} |
114 |
|
|
115 |
/* check if results exists */ |
/* check if results exists */ |
116 |
if ( 0 == funcctx->max_calls ) |
if ( 0 == funcctx->max_calls ) |
117 |
elog(INFO, "pgest: no results for: %s", query ); |
elog(INFO, "pgest: no results for: %s", query ); |
118 |
|
|
119 |
elog(DEBUG1, "pgest: found %d hits for %s", funcctx->max_calls, query); |
elog(DEBUG1, "pgest: found %d hits for %s", resnum, query); |
120 |
|
|
121 |
/* Build a tuple description for a __pgest tuple */ |
/* Build a tuple description for a __pgest tuple */ |
122 |
tupdesc = RelationNameGetTupleDesc("__pgest"); |
tupdesc = RelationNameGetTupleDesc("__pgest"); |
181 |
|
|
182 |
// values[0] = (char *) palloc(strlen(_estval) * sizeof(char)); |
// values[0] = (char *) palloc(strlen(_estval) * sizeof(char)); |
183 |
|
|
184 |
values[0] = attr2text(doc,"@id"); |
values[0] = (char *) attr2text(doc,"@id"); |
185 |
values[1] = attr2text(doc,"@uri"); |
values[1] = (char *) attr2text(doc,"@uri"); |
186 |
values[2] = attr2text(doc,"@title"); |
values[2] = (char *) attr2text(doc,"@title"); |
187 |
values[3] = attr2text(doc,"@type"); |
values[3] = (char *) attr2text(doc,"@type"); |
188 |
|
|
189 |
/* destloy the document object */ |
/* destloy the document object */ |
190 |
elog(DEBUG2, "est_doc_delete"); |
elog(DEBUG2, "est_doc_delete"); |