24 static const float weights[] = {0.1f, 0.2f, 0.4f, 1.0f};
26 #define wpos(wep) ( w[ WEP_GETWEIGHT(wep) ] ) 28 #define RANK_NO_NORM 0x00 29 #define RANK_NORM_LOGLENGTH 0x01 30 #define RANK_NORM_LENGTH 0x02 31 #define RANK_NORM_EXTDIST 0x04 32 #define RANK_NORM_UNIQ 0x08 33 #define RANK_NORM_LOGUNIQ 0x10 34 #define RANK_NORM_RDIVRPLUS1 0x20 35 #define DEF_NORM_METHOD RANK_NO_NORM 49 return 1.0 / (1.005 + 0.05 * exp(((
float4) w) / 1.5 - 2));
75 #define WordECompareQueryItem(e,q,p,i,m) \ 76 tsCompareString((q) + (i)->distance, (i)->length, \ 77 (e) + (p)->pos, (p)->len, (m)) 96 while (StopLow < StopHigh)
98 StopMiddle = StopLow + (StopHigh - StopLow) / 2;
102 StopHigh = StopMiddle;
106 else if (difference > 0)
107 StopLow = StopMiddle + 1;
109 StopHigh = StopMiddle;
114 if (StopLow >= StopHigh)
115 StopMiddle = StopHigh;
127 return (*nitem > 0) ? StopHigh : NULL;
137 char *operand = (
char *) arg;
185 while (ptr - res < *size)
195 *size = prevptr + 1 - res;
235 for (i = 0; i < size; i++)
241 while (entry - firstentry < nitem)
250 for (k = 0; k <
i; k++)
254 lenct = pos[k]->
npos;
256 for (l = 0; l < dimt; l++)
258 for (p = 0; p < lenct; p++)
261 if (dist || (dist == 0 && (pos[i] == POSNULL || pos[k] == POSNULL)))
268 res = (res < 0) ? curw : 1.0 - (1.0 - res) * (1.0 - curw);
303 for (i = 0; i < size; i++)
313 while (entry - firstentry < nitem)
329 for (j = 0; j < dimt; j++)
331 resj = resj +
wpos(post[j]) / ((j + 1) * (j + 1));
332 if (
wpos(post[j]) > wjm)
345 res = res + (wjm + resj - wjm / ((jm + 1) * (jm + 1))) / 1.64493406685;
376 res /= log((
double) (
cnt_length(t) + 1)) / log(2.0);
388 res /= (
float) (t->
size);
391 res /= log((
double) (t->
size + 1)) / log(2.0);
411 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
412 errmsg(
"array of weight must be one-dimensional")));
416 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
417 errmsg(
"array of weight is too short")));
421 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
422 errmsg(
"array of weight must not contain nulls")));
427 ws[
i] = (arrdata[
i] >= 0) ? arrdata[i] :
weights[i];
430 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
431 errmsg(
"weight out of range")));
540 #define MAXQROPOS MAXENTRYPOS 556 #define QR_GET_OPERAND_DATA(q, v) \ 557 ( (q)->operandData + (((QueryItem*)(v)) - GETQUERY((q)->query)) ) 612 for (i = 0; i < entry->
data.
query.nitem; i++)
621 if (opData->
npos == 0)
624 opData->
pos[lastPos] = entry->
pos;
639 opData->
pos[lastPos] = entry->
pos;
649 int lastpos = ext->
pos;
662 ptr = doc + ext->
pos;
665 while (ptr - doc < len)
692 while (ptr >= doc + ext->
pos)
712 if (ext->
p <= ext->
q)
718 ext->
pos = (ptr - doc) + 1;
723 return Cover(doc, len, qr, ext);
761 while (entry - firstentry < nitem)
775 while (
cur + dimt >= len)
782 for (j = 0; j < dimt; j++)
784 if (curoperand->
weight == 0 ||
812 storage.pos = doc->pos;
814 storage.data.query.items[0] = doc->data.map.item;
815 storage.data.query.nitem = 1;
817 while (rptr - doc <
cur)
819 if (rptr->
pos == (rptr - 1)->pos &&
820 rptr->
data.
map.entry == (rptr - 1)->data.map.entry)
822 storage.data.query.items[storage.data.query.nitem] = rptr->
data.
map.item;
823 storage.data.query.nitem++;
829 storage.pos = rptr->
pos;
831 storage.data.query.items[0] = rptr->
data.
map.item;
832 storage.data.query.nitem = 1;
841 *doclen = wptr - doc;
859 double SumDist = 0.0,
867 invws[
i] = ((double) ((arrdata[i] >= 0) ? arrdata[
i] :
weights[
i]));
870 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
871 errmsg(
"weight out of range")));
872 invws[
i] = 1.0 / invws[
i];
887 while (
Cover(doc, doclen, &qr, &ext))
895 while (ptr <= ext.
end)
901 Cpos = ((double) (ext.
end - ext.
begin + 1)) / InvSum;
908 nNoise = (ext.
q - ext.
p) - (ext.
end - ext.
begin);
911 Wdoc += Cpos / ((double) (1 + nNoise));
913 CurExtPos = ((double) (ext.
q + ext.
p)) / 2.0;
914 if (NExtent > 0 && CurExtPos > PrevExtPos
917 SumDist += 1.0 / (CurExtPos - PrevExtPos);
919 PrevExtPos = CurExtPos;
930 Wdoc /= (double) len;
934 Wdoc /= ((
double) NExtent) / SumDist;
937 Wdoc /= (
double) (txt->
size);
940 Wdoc /= log((
double) (txt->
size + 1)) / log(2.0);
#define RANK_NORM_RDIVRPLUS1
bool TS_execute(QueryItem *curitem, void *arg, uint32 flags, TSExecuteCallback chkcond)
static float calc_rank_or(const float *w, TSVector t, TSQuery q)
#define PG_GETARG_INT32(n)
#define RANK_NORM_EXTDIST
#define PG_RETURN_FLOAT4(x)
static TSTernaryValue checkcondition_QueryOperand(void *checkval, QueryOperand *val, ExecPhraseData *data)
Datum ts_rankcd_tt(PG_FUNCTION_ARGS)
Datum ts_rank_wttf(PG_FUNCTION_ARGS)
static bool Cover(DocRepresentation *doc, int len, QueryRepresentation *qr, CoverExt *ext)
#define PG_GETARG_DATUM(n)
#define RANK_NORM_LOGLENGTH
#define PG_GETARG_TSQUERY(n)
#define QR_GET_OPERAND_DATA(q, v)
int ArrayGetNItems(int ndim, const int *dims)
Datum ts_rankcd_wttf(PG_FUNCTION_ARGS)
int errcode(int sqlerrcode)
#define MemSet(start, val, len)
static DocRepresentation * get_docrep(TSVector txt, QueryRepresentation *qr, int *doclen)
Datum ts_rankcd_ttf(PG_FUNCTION_ARGS)
static int compareDocR(const void *va, const void *vb)
static void fillQueryRepresentationData(QueryRepresentation *qr, DocRepresentation *entry)
union DocRepresentation::@30 data
Datum ts_rank_wtt(PG_FUNCTION_ARGS)
static int cnt_length(TSVector t)
void pfree(void *pointer)
WordEntryPos pos[FLEXIBLE_ARRAY_MEMBER]
static int compareQueryOperand(const void *a, const void *b, void *arg)
void check_stack_depth(void)
static float4 word_distance(int32 w)
struct DocRepresentation::@30::@32 map
#define WordECompareQueryItem(e, q, p, i, m)
static float calc_rank(const float *w, TSVector t, TSQuery q, int32 method)
#define RANK_NORM_LOGUNIQ
void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg)
static QueryOperand ** SortAndUniqItems(TSQuery q, int *size)
void * palloc0(Size size)
Datum difference(PG_FUNCTION_ARGS)
static void resetQueryRepresentation(QueryRepresentation *qr, bool reverseinsert)
QueryRepresentationOperand * operandData
Datum ts_rank_ttf(PG_FUNCTION_ARGS)
#define ereport(elevel,...)
Datum ts_rank_tt(PG_FUNCTION_ARGS)
static float calc_rank_and(const float *w, TSVector t, TSQuery q)
#define PG_FREE_IF_COPY(ptr, n)
int32 tsCompareString(char *a, int lena, char *b, int lenb, bool prefix)
static float4 calc_rank_cd(const float4 *arrdata, TSVector txt, TSQuery query, int method)
void * repalloc(void *pointer, Size size)
static WordEntry * find_wordentry(TSVector t, TSQuery q, QueryOperand *item, int32 *nitem)
int errmsg(const char *fmt,...)
#define PG_DETOAST_DATUM(datum)
#define PG_GETARG_TSVECTOR(n)
#define qsort(a, b, c, d)
bool array_contains_nulls(ArrayType *array)
Datum ts_rankcd_wtt(PG_FUNCTION_ARGS)
static const float * getWeights(ArrayType *win)
WordEntryPos pos[MAXQROPOS]
struct DocRepresentation::@30::@31 query
DocRepresentation * begin
static const float weights[]