/* parser's states */
#define WAITOPERAND 1
#define WAITOPERATOR 2
+#define WAITFIRSTOPERAND 3
/*
* node of query tree, also used
{
switch (state->state)
{
+ case WAITFIRSTOPERAND:
case WAITOPERAND:
if (*(state->buf) == '!')
{
else if (*(state->buf) != ' ')
{
state->valstate.prsbuf = state->buf;
- state->state = WAITOPERATOR;
if (gettoken_tsvector(&(state->valstate)))
{
*strval = state->valstate.word;
*lenval = state->valstate.curpos - state->valstate.word;
state->buf = get_weight(state->valstate.prsbuf, weight);
+ state->state = WAITOPERATOR;
return VAL;
}
+ else if ( state->state == WAITFIRSTOPERAND )
+ return END;
else
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
/* init state */
state.buf = buf;
- state.state = WAITOPERAND;
+ state.state = WAITFIRSTOPERAND;
state.count = 0;
state.num = 0;
state.str = NULL;
/* parse query & make polish notation (postfix, but in reverse order) */
makepol(&state, pushval);
pfree(state.valstate.word);
- if (!state.num)
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("empty query")));
+ if (!state.num) {
+ elog(NOTICE, "Query doesn't contain lexem(s)");
+ query = (QUERYTYPE*)palloc( HDRSIZEQT );
+ query->len = HDRSIZEQT;
+ query->size = 0;
+ return query;
+ }
/* make finish struct */
commonlen = COMPUTESIZE(state.num, state.sumlen);
PG_FREE_IF_COPY(in, 1);
query = queryin(str, pushval_morph, PG_GETARG_INT32(0));
+
+ if ( query->size == 0 )
+ PG_RETURN_POINTER(query);
+
res = clean_fakeval_v2(GETQUERY(query), &len);
if (!res)
{
int4 dimt,
j,
i;
- float res = -1.0;
+ float res = 0.0;
ITEM **item;
int size = q->size;
for (i = 0; i < size; i++)
{
+ float resj,wjm;
+ int4 jm;
entry = find_wordentry(t, q, item[i]);
if (!entry)
continue;
post = POSNULL + 1;
}
- for (j = 0; j < dimt; j++)
- {
- if (res < 0)
- res = wpos(post[j]);
- else
- res = 1.0 - (1.0 - res) * (1.0 - wpos(post[j]));
- }
+ resj = 0.0;
+ wjm = -1.0;
+ jm = 0;
+ for (j = 0; j < dimt; j++)
+ {
+ resj = resj + wpos(post[j])/((j+1)*(j+1));
+ if ( wpos(post[j]) > wjm ) {
+ wjm = wpos(post[j]);
+ jm = j;
+ }
+ }
+/*
+ limit (sum(i/i^2),i->inf) = pi^2/6
+ resj = sum(wi/i^2),i=1,noccurence,
+ wi - should be sorted desc,
+ don't sort for now, just choose maximum weight. This should be corrected
+ Oleg Bartunov
+*/
+ res = res + ( wjm + resj - wjm/((jm+1)*(jm+1)))/1.64493406685;
}
+ res = res /size;
pfree(item);
return res;
}