/* count space needed for last item */
buflen += res->entry.len; if (res->entry.haspos)
{
res->poslen = uniquePos(res->pos, res->poslen);
buflen = SHORTALIGN(buflen);
buflen += res->poslen * sizeof(WordEntryPos) + sizeof(uint16);
}
*outbuflen = buflen; return res + 1 - a;
}
Datum
tsvectorin(PG_FUNCTION_ARGS)
{ char *buf = PG_GETARG_CSTRING(0);
Node *escontext = fcinfo->context;
TSVectorParseState state;
WordEntryIN *arr; int totallen; int arrlen; /* allocated size of arr */
WordEntry *inarr; int len = 0;
TSVector in; int i; char *token; int toklen;
WordEntryPos *pos; int poslen; char *strbuf; int stroff;
/* *Tokensareappendedtotmpbuf,curisapointertotheendofused *spaceintmpbuf.
*/ char *tmpbuf; char *cur; int buflen = 256; /* allocated size of tmpbuf */
while (gettoken_tsvector(state, &token, &toklen, &pos, &poslen, NULL))
{ if (toklen >= MAXSTRLEN)
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("word is too long (%ld bytes, max %ld bytes)",
(long) toklen,
(long) (MAXSTRLEN - 1))));
if (cur - tmpbuf > MAXSTRPOS)
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("string is too long for tsvector (%ld bytes, max %ld bytes)",
(long) (cur - tmpbuf), (long) MAXSTRPOS)));
/* *Enlargebuffersifneeded
*/ if (len >= arrlen)
{
arrlen *= 2;
arr = (WordEntryIN *)
repalloc(arr, sizeof(WordEntryIN) * arrlen);
} while ((cur - tmpbuf) + toklen >= buflen)
{ int dist = cur - tmpbuf;
buflen *= 2;
tmpbuf = (char *) repalloc(tmpbuf, buflen);
cur = tmpbuf + dist;
}
arr[len].entry.len = toklen;
arr[len].entry.pos = cur - tmpbuf;
memcpy(cur, token, toklen);
cur += toklen;
/* Did gettoken_tsvector fail? */ if (SOFT_ERROR_OCCURRED(escontext))
PG_RETURN_NULL();
if (len > 0)
len = uniqueentry(arr, len, tmpbuf, &buflen); else
buflen = 0;
if (buflen > MAXSTRPOS)
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("string is too long for tsvector (%d bytes, max %d bytes)", buflen, MAXSTRPOS)));
totallen = CALCDATASIZE(len, buflen);
in = (TSVector) palloc0(totallen);
SET_VARSIZE(in, totallen);
in->size = len;
inarr = ARRPTR(in);
strbuf = STRPTR(in);
stroff = 0; for (i = 0; i < len; i++)
{
memcpy(strbuf + stroff, &tmpbuf[arr[i].entry.pos], arr[i].entry.len);
arr[i].entry.pos = stroff;
stroff += arr[i].entry.len; if (arr[i].entry.haspos)
{ /* This should be unreachable because of MAXNUMPOS restrictions */ if (arr[i].poslen > 0xFFFF)
elog(ERROR, "positions array too long");
/* Copy number of positions */
stroff = SHORTALIGN(stroff);
*(uint16 *) (strbuf + stroff) = (uint16) arr[i].poslen;
stroff += sizeof(uint16);
Datum
tsvectorrecv(PG_FUNCTION_ARGS)
{
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
TSVector vec; int i;
int32 nentries; int datalen; /* number of bytes used in the variable size *areaafterfixedsizeTSVectorheaderand
* WordEntries */
Size hdrlen;
Size len; /* allocated size of vec */ bool needSort = false;
nentries = pq_getmsgint(buf, sizeof(int32)); if (nentries < 0 || nentries > (MaxAllocSize / sizeof(WordEntry)))
elog(ERROR, "invalid size of tsvector");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.