mlw wrote:
>
> I have an external search engine system which plugs in to postgres. I use a few
> C functions to interface the search daemon with the Postgres back-end.
>
> The best that I have been able to do is do a "select" for each result. I have a
> live demo/test site:
>
> http://www.mohawksoft.com/search.php3, and the PHP source code is at
> http://www.mohawksoft.com/ftss_example.txt.
>
> I would love to get the results with one select statement, but have, to date,
> been unable to figure out how. Anyone with any ideas?
Well, I think I got it, and I am posting so that people trying to do what I am
doing, can look through the postings!!
Datum ftss_search(PG_FUNCTION_ARGS) { int4 result; int state;
if(!fcinfo->resultinfo) { PG_RETURN_NULL(); } state = search_state();
if(state == 0) { text * string= PG_GETARG_TEXT_P(0); int len =
VARSIZE(string)-VARHDRSZ; char szString[len+1]; memcpy(szString, VARDATA(string),
len); szString[len]=0; search(DEFAULT_PORT, DEFAULT_HOST, szString); }
if(search_nextresult(&result)) { ReturnSetInfo *rsi = (ReturnSetInfo
*)fcinfo->resultinfo; rsi->isDone = ExprMultipleResult; PG_RETURN_INT32(result);
} else { ReturnSetInfo *rsi = (ReturnSetInfo *)fcinfo->resultinfo;
rsi->isDone = ExprEndResult ; } PG_RETURN_NULL(); }
The above is an example of how to write a function that returns multiple
results.
create function ftss_search (varchar)returns setof integeras '/usr/local/lib/library.so', 'ftss_search'language 'c'
with(iscachable);
The above in an example of how one would register this function in postgres.
select table.* from table, (select fts_search('all { bla bla }') as key) as
result where result.key = table.key;
The above is an example of how to use this function.
Thanks everyone for you help.