63 |
if (SRF_IS_FIRSTCALL()) { |
if (SRF_IS_FIRSTCALL()) { |
64 |
MemoryContext oldcontext; |
MemoryContext oldcontext; |
65 |
|
|
|
/* take arguments from function */ |
|
|
//index_path = _textout(PG_GETARG_TEXT_P(0)); |
|
|
index_path = _textout(PG_GETARG_TEXT_P(0)); |
|
|
query = _textout(PG_GETARG_TEXT_P(1)); |
|
|
attr = _textout(PG_GETARG_TEXT_P(2)); |
|
|
limit = PG_GETARG_INT32(3); |
|
|
offset = PG_GETARG_INT32(4); |
|
|
|
|
66 |
/* create a function context for cross-call persistence */ |
/* create a function context for cross-call persistence */ |
67 |
funcctx = SRF_FIRSTCALL_INIT(); |
funcctx = SRF_FIRSTCALL_INIT(); |
68 |
|
|
69 |
/* switch to memory context appropriate for multiple function calls */ |
/* switch to memory context appropriate for multiple function calls */ |
70 |
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); |
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); |
71 |
|
/* take arguments from function */ |
72 |
|
|
73 |
|
/* index path */ |
74 |
|
if (PG_ARGISNULL(0)) { |
75 |
|
elog(ERROR, "index path can't be null"); |
76 |
|
SRF_RETURN_DONE(funcctx); |
77 |
|
} |
78 |
|
index_path = _textout(PG_GETARG_TEXT_P(0)); |
79 |
|
|
80 |
|
/* query string */ |
81 |
|
if (PG_ARGISNULL(0)) { |
82 |
|
query = ""; |
83 |
|
} else { |
84 |
|
query = _textout(PG_GETARG_TEXT_P(1)); |
85 |
|
} |
86 |
|
|
87 |
|
/* atribute filter */ |
88 |
|
if (PG_ARGISNULL(2)) { |
89 |
|
attr = ""; |
90 |
|
} else { |
91 |
|
attr = _textout(PG_GETARG_TEXT_P(2)); |
92 |
|
} |
93 |
|
|
94 |
|
/* limit */ |
95 |
|
if (PG_ARGISNULL(3)) { |
96 |
|
limit = 0; |
97 |
|
} else { |
98 |
|
limit = PG_GETARG_INT32(3); |
99 |
|
} |
100 |
|
|
101 |
|
/* offset */ |
102 |
|
if (PG_ARGISNULL(4)) { |
103 |
|
offset = 0; |
104 |
|
} else { |
105 |
|
offset = PG_GETARG_INT32(4); |
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
/* open the database */ |
/* open the database */ |
110 |
elog(DEBUG1, "pgest: est_db_open(%s)", index_path); |
elog(DEBUG1, "pgest: est_db_open(%s)", index_path); |
114 |
SRF_RETURN_DONE(funcctx); |
SRF_RETURN_DONE(funcctx); |
115 |
} |
} |
116 |
|
|
117 |
elog(INFO, "pgest: query[%s] attr[%s] limit %d offset %d", query, attr, limit, offset); |
elog(INFO, "pgest: query[%s] attr[%s] limit %d offset %d", query, (PG_ARGISNULL(2) ? "NULL" : attr), limit, offset); |
118 |
|
|
119 |
/* create a search condition object */ |
/* create a search condition object */ |
120 |
if (!(cond = est_cond_new())) { |
if (!(cond = est_cond_new())) { |
123 |
} |
} |
124 |
|
|
125 |
/* set the search phrase to the search condition object */ |
/* set the search phrase to the search condition object */ |
126 |
est_cond_set_phrase(cond, query); |
if (! PG_ARGISNULL(1) && strlen(query) > 0) |
127 |
|
est_cond_set_phrase(cond, query); |
128 |
|
|
129 |
/* minimum valid attribute length is 10: @a STREQ a */ |
/* minimum valid attribute length is 10: @a STREQ a */ |
130 |
if (attr != NULL && strlen(attr) >= 10) { |
if (! PG_ARGISNULL(2) && strlen(attr) >= 10) { |
131 |
elog(INFO,"est_cond_add_attr(%s)", attr); |
elog(INFO,"est_cond_add_attr(%s)", attr); |
132 |
est_cond_add_attr(cond, attr); |
est_cond_add_attr(cond, attr); |
133 |
} |
} |
214 |
values[0] = (char *) attr2text(doc,"@id"); |
values[0] = (char *) attr2text(doc,"@id"); |
215 |
values[1] = (char *) attr2text(doc,"@uri"); |
values[1] = (char *) attr2text(doc,"@uri"); |
216 |
values[2] = (char *) attr2text(doc,"@title"); |
values[2] = (char *) attr2text(doc,"@title"); |
217 |
values[3] = (char *) attr2text(doc,"@type"); |
values[3] = (char *) attr2text(doc,"@size"); |
218 |
|
|
219 |
/* destloy the document object */ |
/* destloy the document object */ |
220 |
elog(DEBUG2, "est_doc_delete"); |
elog(DEBUG2, "est_doc_delete"); |