2007-08-21 03:11:32 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* dict.c
|
|
|
|
* Standard interface to dictionary
|
|
|
|
*
|
2010-01-02 17:58:17 +01:00
|
|
|
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
2007-08-21 03:11:32 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2010-01-02 17:58:17 +01:00
|
|
|
* $PostgreSQL: pgsql/src/backend/tsearch/dict.c,v 1.7 2010/01/02 16:57:53 momjian Exp $
|
2007-08-21 03:11:32 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include "catalog/pg_type.h"
|
|
|
|
#include "tsearch/ts_cache.h"
|
|
|
|
#include "tsearch/ts_utils.h"
|
|
|
|
#include "utils/builtins.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lexize one word by dictionary, mostly debug function
|
|
|
|
*/
|
2007-10-20 00:01:45 +02:00
|
|
|
Datum
|
|
|
|
ts_lexize(PG_FUNCTION_ARGS)
|
2007-08-21 03:11:32 +02:00
|
|
|
{
|
2007-10-20 00:01:45 +02:00
|
|
|
Oid dictId = PG_GETARG_OID(0);
|
|
|
|
text *in = PG_GETARG_TEXT_P(1);
|
|
|
|
ArrayType *a;
|
2007-08-21 03:11:32 +02:00
|
|
|
TSDictionaryCacheEntry *dict;
|
|
|
|
TSLexeme *res,
|
|
|
|
*ptr;
|
|
|
|
Datum *da;
|
|
|
|
DictSubState dstate = {false, false, NULL};
|
|
|
|
|
|
|
|
dict = lookup_ts_dictionary_cache(dictId);
|
|
|
|
|
|
|
|
res = (TSLexeme *) DatumGetPointer(FunctionCall4(&dict->lexize,
|
|
|
|
PointerGetDatum(dict->dictData),
|
|
|
|
PointerGetDatum(VARDATA(in)),
|
|
|
|
Int32GetDatum(VARSIZE(in) - VARHDRSZ),
|
2007-11-15 22:14:46 +01:00
|
|
|
PointerGetDatum(&dstate)));
|
2007-08-21 03:11:32 +02:00
|
|
|
|
|
|
|
if (dstate.getnext)
|
|
|
|
{
|
|
|
|
dstate.isend = true;
|
|
|
|
ptr = (TSLexeme *) DatumGetPointer(FunctionCall4(&dict->lexize,
|
|
|
|
PointerGetDatum(dict->dictData),
|
|
|
|
PointerGetDatum(VARDATA(in)),
|
|
|
|
Int32GetDatum(VARSIZE(in) - VARHDRSZ),
|
2007-11-15 22:14:46 +01:00
|
|
|
PointerGetDatum(&dstate)));
|
2007-08-21 03:11:32 +02:00
|
|
|
if (ptr != NULL)
|
|
|
|
res = ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!res)
|
2007-10-20 00:01:45 +02:00
|
|
|
PG_RETURN_NULL();
|
2007-08-21 03:11:32 +02:00
|
|
|
|
|
|
|
ptr = res;
|
|
|
|
while (ptr->lexeme)
|
|
|
|
ptr++;
|
2007-10-20 00:01:45 +02:00
|
|
|
da = (Datum *) palloc(sizeof(Datum) * (ptr - res));
|
2007-08-21 03:11:32 +02:00
|
|
|
ptr = res;
|
|
|
|
while (ptr->lexeme)
|
|
|
|
{
|
2008-03-25 23:42:46 +01:00
|
|
|
da[ptr - res] = CStringGetTextDatum(ptr->lexeme);
|
2007-08-21 03:11:32 +02:00
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
a = construct_array(da,
|
|
|
|
ptr - res,
|
|
|
|
TEXTOID,
|
|
|
|
-1,
|
|
|
|
false,
|
|
|
|
'i');
|
|
|
|
|
|
|
|
ptr = res;
|
|
|
|
while (ptr->lexeme)
|
|
|
|
{
|
|
|
|
pfree(DatumGetPointer(da[ptr - res]));
|
|
|
|
pfree(ptr->lexeme);
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
pfree(res);
|
|
|
|
pfree(da);
|
|
|
|
|
2007-10-20 00:01:45 +02:00
|
|
|
PG_RETURN_POINTER(a);
|
2007-08-21 03:11:32 +02:00
|
|
|
}
|