#include "postgres.h"#include "catalog/pg_type.h"#include "tsearch/ts_cache.h"#include "tsearch/ts_utils.h"#include "utils/builtins.h"
Go to the source code of this file.
Functions | |
| Datum | ts_lexize (PG_FUNCTION_ARGS) |
| Datum ts_lexize | ( | PG_FUNCTION_ARGS | ) |
Definition at line 26 of file dict.c.
References construct_array(), CStringGetTextDatum, DatumGetPointer, TSDictionaryCacheEntry::dictData, FunctionCall4, DictSubState::getnext, Int32GetDatum, DictSubState::isend, TSLexeme::lexeme, TSDictionaryCacheEntry::lexize, lookup_ts_dictionary_cache(), NULL, palloc(), pfree(), PG_GETARG_OID, PG_GETARG_TEXT_P, PG_RETURN_NULL, PG_RETURN_POINTER, PointerGetDatum, TEXTOID, VARDATA, VARHDRSZ, and VARSIZE.
Referenced by tsa_lexize_bycurrent(), and tsa_lexize_byname().
{
Oid dictId = PG_GETARG_OID(0);
text *in = PG_GETARG_TEXT_P(1);
ArrayType *a;
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),
PointerGetDatum(&dstate)));
if (dstate.getnext)
{
dstate.isend = true;
ptr = (TSLexeme *) DatumGetPointer(FunctionCall4(&dict->lexize,
PointerGetDatum(dict->dictData),
PointerGetDatum(VARDATA(in)),
Int32GetDatum(VARSIZE(in) - VARHDRSZ),
PointerGetDatum(&dstate)));
if (ptr != NULL)
res = ptr;
}
if (!res)
PG_RETURN_NULL();
ptr = res;
while (ptr->lexeme)
ptr++;
da = (Datum *) palloc(sizeof(Datum) * (ptr - res));
ptr = res;
while (ptr->lexeme)
{
da[ptr - res] = CStringGetTextDatum(ptr->lexeme);
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);
PG_RETURN_POINTER(a);
}
1.7.1