Skip site navigation (1) Skip section navigation (2)

Using HStore type in TSearch

From: Łukasz Dejneka <l(dot)dejneka(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Using HStore type in TSearch
Date: 2010-03-29 11:18:04
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers

I've asked this question in novice group and another Postgres forum, but
didn't get any help.

What I want to do is to use HStore data type (namely the HStore keys) in
TSearch. I don't want use TSVector and the original ts_match_vq function,
because I want to be able to control exact values that are passed to the
search and not use their lexemes.

I'm pretty green about Postgres and C, so please forgive me for any mistakes
I make here...

What I tried was to modify the ts_match_vq function and use it to pass
values from HStore directly to the recursive TS_execute function.
Unfortunately the HStore ARRPTR() and STRPTR() functions do not return the
same structures as their TSVector counterparts. HStore as I gathered returns
pointer to a string, but the TSVector (and the TS_execute) needs a ltree of
search entries. I guess I need to convert the HStore values to the ltree
structure, but I can't get it right.

This is the partially modified ts_match_vq:

#undef ARRPTR
#undef STRPTR
#define CALCDATASIZE(x, lenstr) ( (x) * sizeof(HEntry) + HSHRDSIZE +
(lenstr) )
#define ARRPTR(x)                ( (HEntry*) ( (char*)(x) + HSHRDSIZE ) )
#define STRPTR(x)                ( (char*)(x) + HSHRDSIZE + ( sizeof(HEntry)
* ((HStore*)x)->size ) )

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);
    //process TSQuery
    tq_in = TSQueryGetDatum(tq);
    //process HStore
    chkvalKeys.arrb = ARRPTR(hs);
    chkvalKeys.arre = chkvalKeys.arrb + hs->size
    chkvalKeys.values = STRPTR(hs);
    chkvalKeys.operand = GETQUERY(tq_in);
res = ljd_exec(
<------>    GETQUERY(tq_in),
<------>    &chkvalKeys,
<------>    true,
<------>    checkcondition_str


Thank you in advance for any help and tips on how to solve this.


pgsql-hackers by date

Next:From: Michael MeskesDate: 2010-03-29 11:34:35
Subject: Problems with variable cursorname in ecpg
Previous:From: Stefan KaltenbrunnerDate: 2010-03-29 11:16:11
Subject: Re: Known Issues Page

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group