pike.git / src / modules / _WhiteFish / whitefish.c

version» Context lines:

pike.git/src/modules/_WhiteFish/whitefish.c:1:   #include <math.h>      #include "global.h"   #include "stralloc.h"   #include "global.h" - RCSID("$Id: whitefish.c,v 1.10 2001/05/25 10:25:38 per Exp $"); + RCSID("$Id: whitefish.c,v 1.11 2001/05/25 10:38:53 per Exp $");   #include "pike_macros.h"   #include "interpret.h"   #include "program.h"   #include "program_id.h"   #include "object.h"   #include "operators.h"   #include "array.h"   #include "module_support.h"      #include "config.h"
pike.git/src/modules/_WhiteFish/whitefish.c:43:      #define OFFSET(X) \    (X.type == HIT_BODY?X.u.body.pos:X.type==HIT_FIELD?(X.u.field.pos<<(14-8)):(X.u.anchor.pos<<10))      #define DOFF(X) MINIMUM((int)sqrt(X),7)   #define MOFF(X) (X.type==HIT_BODY?X.u.body.id:X.type==HIT_FIELD?X.u.field.type+3:67)      static void handle_hit( Blob **blobs,    int nblobs,    struct object *res, -  int *field_c[68], -  int *prox_c[8] ) +  int docid, +  double *field_c[68], +  double *prox_c[8] )   {    int i, j, k, end = 0;    Hit *hits = malloc( nblobs * sizeof(Hit) );    unsigned char *nhits = malloc( nblobs );    unsigned char *pos = malloc( nblobs );       int matrix[68][8];       MEMSET(hits, 0, nblobs * sizeof(Hit) );    MEMSET(pos, 0, nblobs );
pike.git/src/modules/_WhiteFish/whitefish.c:82:    hits[k] = wf_blob_hit( blobs[k], pos[k]++ );    if( hits[k].type == hits[i].type )    matrix[MOFF(hits[i])][DOFF(OFFSET(hits[i])-OFFSET(hits[k]))]++;    }    }    }          /* Now we have our nice matrix. Time to do some multiplication */    +  { +  double accum = 0.0, fc, pc; +  int accum_i; +  for( i = 0; i<68; i++ ) +  if( (fc = *field_c[i]) != 0.0 ) +  for( j = 0; j<8; j++ ) +  if( (pc = *prox_c[j]) != 0.0 ) +  accum += matrix[i][j] * fc * pc;    -  +  /* Limit */ +  if( accum > 32000.0 ) +  accum = 32000.0; +  accum_i = (int)(accum * 65535); +  if( accum_i > 0 ) +  wf_resultset_add( res, docid, accum_i );    } -  + }      static struct object *low_do_query_merge( Blob **blobs,    int nblobs, -  int field_c[68], -  int prox_c[8]) +  double field_c[68], +  double prox_c[8] )   {    struct object *res = wf_resultset_new();    struct tofree *__f = malloc( sizeof( struct tofree ) );    ONERROR e;    int i, j, end=0;    Blob **tmp;       tmp = malloc( nblobs * sizeof( Blob *) );       __f->res = res;
pike.git/src/modules/_WhiteFish/whitefish.c:123:    int min = blobs[0]->docid;       for( i = 1; i<nblobs; i++ )    if( blobs[i]->docid < min )    min = blobs[i]->docid;       for( j = 0, i = 0; i < nblobs; i++ )    if( blobs[i]->docid == min && !blobs[i]->eof )    tmp[j++] = blobs[i];    -  handle_hit( tmp, j, res, &field_c, &prox_c ); +  handle_hit( tmp, j, res, min, &field_c, &prox_c );       /* Step the 'min' blobs */    for( i = 0; i<j; i++ )    wf_blob_next( tmp[i] );       /* Are we done? */    end = 1;    for( i=0; i<nblobs; i++ )    if( !blobs[i]->eof )    {
pike.git/src/modules/_WhiteFish/whitefish.c:198:    *! 7 spread: 161-    *!    *! The 'spread' value should be defined somehow.    *!    *! @[blobfeeder]    *!    *! This function returns a Pike string containing the word hits    *! for a certain word_id. Call repeatedly until it returns 0.    */   { -  int proximity_coefficients[8]; -  int field_coefficients[68]; +  double proximity_coefficients[8]; +  double field_coefficients[68];    int numblobs, i;    Blob **blobs;       struct svalue *cb;    struct object *res;    struct array *_words, *_field, *_prox;       /* 1: Get all arguments. */    get_all_args( "do_query_merge", args, "%a%a%a%O",    &_words, &_field, &_prox, &cb);
pike.git/src/modules/_WhiteFish/whitefish.c:231:    push_object( o );    return;    }       blobs = malloc( sizeof(Blob *) * numblobs );       for( i = 0; i<numblobs; i++ )    blobs[i] = wf_blob_new( cb, _words->item[i].u.integer );       for( i = 0; i<8; i++ ) -  proximity_coefficients[i] = _prox->item[i].u.integer; +  proximity_coefficients[i] = (double)_prox->item[i].u.integer/65535.0;       for( i = 0; i<68; i++ ) -  field_coefficients[i] = _field->item[i].u.integer; +  field_coefficients[i] = (double)_field->item[i].u.integer/65535.0;       res = low_do_query_merge(blobs,numblobs,    field_coefficients,    proximity_coefficients );    pop_n_elems( args );    push_object( res );   }      void pike_module_init(void)   {