Commit 8f91e2b6 authored by Teodor Sigaev's avatar Teodor Sigaev

Fix compare bug for tsvector: problem was in aligment. Per Stefan...

Fix compare bug for tsvector: problem was in aligment. Per Stefan Kaltenbrunner <stefan@kaltenbrunner.cc> and Phil Frost <indigo@bitglue.com>
parent 726ede73
...@@ -966,17 +966,43 @@ silly_cmp_tsvector(const tsvector * a, const tsvector * b) ...@@ -966,17 +966,43 @@ silly_cmp_tsvector(const tsvector * a, const tsvector * b)
return 1; return 1;
else else
{ {
unsigned char *aptr = (unsigned char *) (a->data) + DATAHDRSIZE; WordEntry *aptr = ARRPTR(a);
unsigned char *bptr = (unsigned char *) (b->data) + DATAHDRSIZE; WordEntry *bptr = ARRPTR(b);
int i = 0;
int res;
for(i=0;i<a->size;i++) {
if ( aptr->haspos != bptr->haspos ) {
return ( aptr->haspos > bptr->haspos ) ? -1 : 1;
} else if ( aptr->pos != bptr->pos ) {
return ( aptr->pos > bptr->pos ) ? -1 : 1;
} else if ( aptr->len != bptr->len ) {
return ( aptr->len > bptr->len ) ? -1 : 1;
} else if ( (res=strncmp(STRPTR(a) + aptr->pos, STRPTR(b) + bptr->pos, b->len))!= 0 ) {
return res;
} else if ( aptr->haspos ) {
WordEntryPos *ap = POSDATAPTR(a, aptr);
WordEntryPos *bp = POSDATAPTR(b, bptr);
int j;
if ( POSDATALEN(a, aptr) != POSDATALEN(b, bptr) )
return ( POSDATALEN(a, aptr) > POSDATALEN(b, bptr) ) ? -1 : 1;
for(j=0;j<POSDATALEN(a, aptr);j++) {
if ( WEP_GETPOS(*ap) != WEP_GETPOS(*bp) ) {
return ( WEP_GETPOS(*ap) > WEP_GETPOS(*bp) ) ? -1 : 1;
} else if ( WEP_GETWEIGHT(*ap) != WEP_GETWEIGHT(*bp) ) {
return ( WEP_GETWEIGHT(*ap) > WEP_GETWEIGHT(*bp) ) ? -1 : 1;
}
ap++, bp++;
}
}
while (aptr - ((unsigned char *) (a->data)) < a->len) aptr++; bptr++;
{
if (*aptr != *bptr)
return (*aptr < *bptr) ? -1 : 1;
aptr++;
bptr++;
} }
} }
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment