22#include "utils/fmgrprotos.h"
27#define wpos(wep) ( w[ WEP_GETWEIGHT(wep) ] )
29#define RANK_NO_NORM 0x00
30#define RANK_NORM_LOGLENGTH 0x01
31#define RANK_NORM_LENGTH 0x02
32#define RANK_NORM_EXTDIST 0x04
33#define RANK_NORM_UNIQ 0x08
34#define RANK_NORM_LOGUNIQ 0x10
35#define RANK_NORM_RDIVRPLUS1 0x20
36#define DEF_NORM_METHOD RANK_NO_NORM
50 return 1.0 / (1.005 + 0.05 *
exp(((
float4) w) / 1.5 - 2));
76#define WordECompareQueryItem(e,q,p,i,m) \
77 tsCompareString((q) + (i)->distance, (i)->length, \
78 (e) + (p)->pos, (p)->len, (m))
138 char *operand = (
char *)
arg;
143 operand +
qb->distance,
qb->length,
186 while (ptr - res < *size)
236 for (
i = 0;
i < size;
i++)
251 for (k = 0; k <
i; k++)
257 for (l = 0; l <
dimt; l++)
259 for (p = 0; p <
lenct; p++)
269 res = (res < 0) ?
curw : 1.0 - (1.0 - res) * (1.0 -
curw);
304 for (
i = 0;
i < size;
i++)
346 res = res + (
wjm +
resj -
wjm / ((
jm + 1) * (
jm + 1))) / 1.64493406685;
389 res /= (
float) (t->
size);
392 res /=
log((
double) (t->
size + 1)) /
log(2.0);
415 errmsg(
"array of weight must be one-dimensional")));
420 errmsg(
"array of weight is too short")));
425 errmsg(
"array of weight must not contain nulls")));
434 errmsg(
"weight out of range")));
533 if (
a->data.map.entry ==
b->data.map.entry)
536 return (
a->data.map.entry >
b->data.map.entry) ? 1 : -1;
545#define MAXQROPOS MAXENTRYPOS
561#define QR_GET_OPERAND_DATA(q, v) \
562 ( (q)->operandData + (((QueryItem*)(v)) - GETQUERY((q)->query)) )
574 if (!
opData->operandexists)
581 if (
opData->reverseinsert)
602 for (
i = 0;
i <
qr->query->size;
i++)
604 qr->operandData[
i].operandexists =
false;
605 qr->operandData[
i].reverseinsert = reverseinsert;
606 qr->operandData[
i].npos = 0;
624 opData->operandexists =
true;
697 while (ptr >=
doc + ext->
pos)
717 if (ext->
p <= ext->
q)
723 ext->
pos = (ptr -
doc) + 1;
742 int len =
qr->query->size * 4,
752 for (
i = 0;
i <
qr->query->size;
i++)
789 if (curoperand->
weight == 0 ||
793 doc[
cur].data.map.entry = entry;
819 storage.data.query.items[0] =
doc->data.map.item;
825 rptr->data.map.entry == (
rptr - 1)->data.map.entry)
876 errmsg(
"weight out of range")));
899 while (ptr <= ext.
end)
bool array_contains_nulls(const ArrayType *array)
int ArrayGetNItems(int ndim, const int *dims)
#define Assert(condition)
#define MemSet(start, val, len)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define palloc_array(type, count)
#define palloc0_array(type, count)
#define PG_FREE_IF_COPY(ptr, n)
#define PG_GETARG_DATUM(n)
#define PG_DETOAST_DATUM(datum)
#define PG_GETARG_INT32(n)
#define PG_RETURN_FLOAT4(x)
Datum difference(PG_FUNCTION_ARGS)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg)
#define qsort(a, b, c, d)
void check_stack_depth(void)
DocRepresentation * begin
struct DocRepresentation::@30::@31 query
union DocRepresentation::@30 data
QueryRepresentationOperand * operandData
WordEntryPos pos[FLEXIBLE_ARRAY_MEMBER]
#define PG_GETARG_TSVECTOR(n)
#define PG_GETARG_TSQUERY(n)
#define RANK_NORM_RDIVRPLUS1
Datum ts_rankcd_wtt(PG_FUNCTION_ARGS)
static DocRepresentation * get_docrep(TSVector txt, QueryRepresentation *qr, int *doclen)
Datum ts_rankcd_wttf(PG_FUNCTION_ARGS)
#define WordECompareQueryItem(e, q, p, i, m)
static int compareDocR(const void *va, const void *vb)
#define RANK_NORM_LOGLENGTH
static TSTernaryValue checkcondition_QueryOperand(void *checkval, QueryOperand *val, ExecPhraseData *data)
static void resetQueryRepresentation(QueryRepresentation *qr, bool reverseinsert)
static float4 calc_rank_cd(const float4 *arrdata, TSVector txt, TSQuery query, int method)
static float calc_rank(const float *w, TSVector t, TSQuery q, int32 method)
static int cnt_length(TSVector t)
static WordEntry * find_wordentry(TSVector t, TSQuery q, QueryOperand *item, int32 *nitem)
static float4 word_distance(int32 w)
static int compareQueryOperand(const void *a, const void *b, void *arg)
Datum ts_rank_ttf(PG_FUNCTION_ARGS)
Datum ts_rank_wttf(PG_FUNCTION_ARGS)
Datum ts_rank_tt(PG_FUNCTION_ARGS)
static QueryOperand ** SortAndUniqItems(TSQuery q, int *size)
static void getWeights(ArrayType *win, float *ws)
static float calc_rank_or(const float *w, TSVector t, TSQuery q)
static void fillQueryRepresentationData(QueryRepresentation *qr, DocRepresentation *entry)
static const float default_weights[NUM_WEIGHTS]
Datum ts_rank_wtt(PG_FUNCTION_ARGS)
#define QR_GET_OPERAND_DATA(q, v)
Datum ts_rankcd_ttf(PG_FUNCTION_ARGS)
Datum ts_rankcd_tt(PG_FUNCTION_ARGS)
#define RANK_NORM_EXTDIST
static float calc_rank_and(const float *w, TSVector t, TSQuery q)
static bool Cover(DocRepresentation *doc, int len, QueryRepresentation *qr, CoverExt *ext)
#define RANK_NORM_LOGUNIQ
bool TS_execute(QueryItem *curitem, void *arg, uint32 flags, TSExecuteCallback chkcond)
int32 tsCompareString(char *a, int lena, char *b, int lenb, bool prefix)