Thread: Using HStore type in TSearch
Hi
I'm new to postgres and C programming so this gives me some trouble:
I need to modify one function ts_match_vq located in postgresql-8.4.3/src/backend/utils/adt/tsvector_op.c and/or the TS_execute function refferenced in ts_match_vq.
Basically I need to be able to pass a HStore data (HStore keys to be specific) to ts_match_vq instead of TSVector.
Any help would be appreciated, thanks !
I'm new to postgres and C programming so this gives me some trouble:
I need to modify one function ts_match_vq located in postgresql-8.4.3/src/backend/utils/adt/tsvector_op.c and/or the TS_execute function refferenced in ts_match_vq.
Basically I need to be able to pass a HStore data (HStore keys to be specific) to ts_match_vq instead of TSVector.
Any help would be appreciated, thanks !
Ok, so I did this (modified the ts_match_vq function):
Datum.
ljd_test(PG_FUNCTION_ARGS).
{
//get arguments
HStore *hs = PG_GETARG_HS(0);.
TSQuery tq = PG_GETARG_TSQUERY(1);
TSQuery tq_in;
CHKVAL chkvalKeys;
bool res;
//check for empty values.
if (!hs->size || !tq->size)
{
PG_FREE_IF_COPY(hs, 0);
PG_FREE_IF_COPY(tq, 1);
PG_RETURN_BOOL(false);
}
//process TSQuery
tq_in = TSQueryGetDatum(tq);
//process HStore
//HEntry *ptr = ARRPTR(hs);
//char *words = STRPTR(hs);
chkvalKeys.arrb = ARRPTR(hs);
chkvalKeys.arre = chkvalKeys.arrb + hs->size;
chkvalKeys.values = STRPTR(hs);
chkvalKeys.operand = GETOPERAND(tq_in);
res = ljd_exec(
GETQUERY(tq_in),
&chkvalKeys,
true,
checkcondition_str
);
PG_FREE_IF_COPY(hs, 0);
PG_FREE_IF_COPY(tq, 1);
PG_RETURN_BOOL(res);
ljd_test(PG_FUNCTION_ARGS).
{
//get arguments
HStore *hs = PG_GETARG_HS(0);.
TSQuery tq = PG_GETARG_TSQUERY(1);
TSQuery tq_in;
CHKVAL chkvalKeys;
bool res;
//check for empty values.
if (!hs->size || !tq->size)
{
PG_FREE_IF_COPY(hs, 0);
PG_FREE_IF_COPY(tq, 1);
PG_RETURN_BOOL(false);
}
//process TSQuery
tq_in = TSQueryGetDatum(tq);
//process HStore
//HEntry *ptr = ARRPTR(hs);
//char *words = STRPTR(hs);
chkvalKeys.arrb = ARRPTR(hs);
chkvalKeys.arre = chkvalKeys.arrb + hs->size;
chkvalKeys.values = STRPTR(hs);
chkvalKeys.operand = GETOPERAND(tq_in);
res = ljd_exec(
GETQUERY(tq_in),
&chkvalKeys,
true,
checkcondition_str
);
PG_FREE_IF_COPY(hs, 0);
PG_FREE_IF_COPY(tq, 1);
PG_RETURN_BOOL(res);
Now the problem is in the data passed to CHKVAL type (the "chkvalKeys.values = STRPTR(hs);" line), in TSVector data is ltree (I think), but the HStore STRPTR function returns a string. How could I convert the HStore values, so they are compatible with checkcondition_str function located in /postgresql-8.4.3/contrib/ltree ??
Thanks in advance.
Thanks in advance.