static float weights[] = {0.1, 0.2, 0.4, 1.0};
-#define wpos(wep) ( w[ ((WordEntryPos*)(wep))->weight ] )
+#define wpos(wep) ( w[ WEP_GETWEIGHT(wep) ] )
#define DEF_NORM_METHOD 0
}
static WordEntryPos POSNULL[] = {
- {0, 0},
- {0, MAXENTRYPOS - 1}
+ 0,
+ 0
};
static float
memset(pos, 0, sizeof(uint16 **) * q->size);
*(uint16 *) POSNULL = lengthof(POSNULL) - 1;
+ WEP_SETPOS(POSNULL[1], MAXENTRYPOS-1);
for (i = 0; i < q->size; i++)
{
{
for (p = 0; p < lenct; p++)
{
- dist = Abs(post[l].pos - ct[p].pos);
+ dist = Abs((int)WEP_GETPOS(post[l]) - (int)WEP_GETPOS(ct[p]));
if (dist || (dist == 0 && (pos[i] == (uint16 *) POSNULL || pos[k] == (uint16 *) POSNULL)))
{
float curw;
if (!dist)
dist = MAXENTRYPOS;
- curw = sqrt(wpos(&(post[l])) * wpos(&(ct[p])) * word_distance(dist));
+ curw = sqrt(wpos(post[l]) * wpos(ct[p]) * word_distance(dist));
res = (res < 0) ? curw : 1.0 - (1.0 - res) * (1.0 - curw);
}
}
for (j = 0; j < dimt; j++)
{
if (res < 0)
- res = wpos(&(post[j]));
+ res = wpos(post[j]);
else
- res = 1.0 - (1.0 - res) * (1.0 - wpos(&(post[j])));
+ res = 1.0 - (1.0 - res) * (1.0 - wpos(post[j]));
}
}
return res;
for (j = 0; j < dimt; j++)
{
doc[cur].item = &(item[i]);
- doc[cur].pos = post[j].pos;
+ doc[cur].pos = WEP_GETPOS(post[j]);
cur++;
}
}
{
dw[cur].w = STRPTR(txt) + pptr[i].pos;
dw[cur].len = pptr[i].len;
- dw[cur].pos = posdata[j].pos;
+ dw[cur].pos = WEP_GETPOS(posdata[j]);
cur++;
}
len += (pptr[i].len + 1) * (int) POSDATALEN(txt, &(pptr[i]));
static int
comparePos(const void *a, const void *b)
{
- if (((WordEntryPos *) a)->pos == ((WordEntryPos *) b)->pos)
+ if (WEP_GETPOS(*(WordEntryPos *) a) == WEP_GETPOS(*(WordEntryPos *) b))
return 1;
- return (((WordEntryPos *) a)->pos > ((WordEntryPos *) b)->pos) ? 1 : -1;
+ return (WEP_GETPOS(*(WordEntryPos *) a)> WEP_GETPOS(*(WordEntryPos *) b)) ? 1 : -1;
}
static int
ptr = a + 1;
while (ptr - a < l)
{
- if (ptr->pos != res->pos)
+ if (WEP_GETPOS(*ptr) != WEP_GETPOS(*res))
{
res++;
- res->pos = ptr->pos;
- res->weight = ptr->weight;
- if (res - a >= MAXNUMPOS - 1 || res->pos == MAXENTRYPOS - 1)
+ *res = *ptr;
+ if (res - a >= MAXNUMPOS - 1 || WEP_GETPOS(*res) == MAXENTRYPOS - 1)
break;
}
- else if (ptr->weight > res->weight)
- res->weight = ptr->weight;
+ else if (WEP_GETWEIGHT(*ptr) > WEP_GETWEIGHT(*res))
+ WEP_SETWEIGHT(*res, WEP_GETWEIGHT(*ptr));
ptr++;
}
return res + 1 - a;
state->pos = (WordEntryPos *) repalloc(state->pos, sizeof(WordEntryPos) * state->alen);
}
(*(uint16 *) (state->pos))++;
- state->pos[*(uint16 *) (state->pos)].pos = LIMITPOS(atoi(state->prsbuf));
- if (state->pos[*(uint16 *) (state->pos)].pos == 0)
+ WEP_SETPOS(state->pos[*(uint16 *) (state->pos)], LIMITPOS(atoi(state->prsbuf)));
+ if (WEP_GETPOS(state->pos[*(uint16 *) (state->pos)]) == 0)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("wrong position info")));
- state->pos[*(uint16 *) (state->pos)].weight = 0;
+ WEP_SETWEIGHT( state->pos[*(uint16 *) (state->pos)], 0 );
state->state = WAITPOSDELIM;
}
else
state->state = INPOSINFO;
else if (tolower(*(state->prsbuf)) == 'a' || *(state->prsbuf) == '*')
{
- if (state->pos[*(uint16 *) (state->pos)].weight)
+ if ( WEP_GETWEIGHT(state->pos[*(uint16 *) (state->pos)]) )
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
- state->pos[*(uint16 *) (state->pos)].weight = 3;
+ WEP_SETWEIGHT( state->pos[*(uint16 *) (state->pos)], 3 );
}
else if (tolower(*(state->prsbuf)) == 'b')
{
- if (state->pos[*(uint16 *) (state->pos)].weight)
+ if ( WEP_GETWEIGHT(state->pos[*(uint16 *) (state->pos)]) )
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
- state->pos[*(uint16 *) (state->pos)].weight = 2;
+ WEP_SETWEIGHT( state->pos[*(uint16 *) (state->pos)], 2 );
}
else if (tolower(*(state->prsbuf)) == 'c')
{
- if (state->pos[*(uint16 *) (state->pos)].weight)
+ if ( WEP_GETWEIGHT(state->pos[*(uint16 *) (state->pos)]) )
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
- state->pos[*(uint16 *) (state->pos)].weight = 1;
+ WEP_SETWEIGHT( state->pos[*(uint16 *) (state->pos)], 1 );
}
else if (tolower(*(state->prsbuf)) == 'd')
{
- if (state->pos[*(uint16 *) (state->pos)].weight)
+ if ( WEP_GETWEIGHT(state->pos[*(uint16 *) (state->pos)]) )
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("syntax error")));
- state->pos[*(uint16 *) (state->pos)].weight = 0;
+ WEP_SETWEIGHT( state->pos[*(uint16 *) (state->pos)], 0 );
}
else if (isspace((unsigned char) *(state->prsbuf)) ||
*(state->prsbuf) == '\0')
wptr = POSDATAPTR(out, ptr);
while (pp)
{
- sprintf(curout, "%d", wptr->pos);
+ sprintf(curout, "%d", WEP_GETPOS(*wptr));
curout = strchr(curout, '\0');
- switch (wptr->weight)
+ switch (WEP_GETWEIGHT(*wptr))
{
case 3:
*curout++ = 'A';
wptr = POSDATAPTR(in, ptr);
for (j = 0; j < *(uint16 *) cur; j++)
{
- wptr[j].weight = 0;
- wptr[j].pos = prs->words[i].pos.apos[j + 1];
+ WEP_SETWEIGHT(wptr[j], 0);
+ WEP_SETPOS(wptr[j], prs->words[i].pos.apos[j + 1]);
}
cur += sizeof(uint16) + prs->words[i].pos.apos[0] * sizeof(WordEntryPos);
pfree(prs->words[i].pos.apos);