a23b4c2001-05-25Per Hedbor #include <math.h>
7502512001-05-22Per Hedbor #include "global.h" #include "stralloc.h" #include "global.h" #include "pike_macros.h" #include "interpret.h" #include "program.h" #include "object.h"
4ad07e2001-05-22Per Hedbor #include "array.h" #include "module_support.h"
fcd0602003-02-18Martin Stjernholm #include "module.h"
7502512001-05-22Per Hedbor 
0853842001-05-22Per Hedbor #include "config.h"
7502512001-05-22Per Hedbor #include "whitefish.h" #include "resultset.h"
4926f72001-05-22Per Hedbor #include "blob.h"
54025d2001-05-26Per Hedbor #include "blobs.h"
9157232001-05-28Per Hedbor #include "linkfarm.h"
7502512001-05-22Per Hedbor 
4ad07e2001-05-22Per Hedbor struct tofree { Blob **blobs;
a23b4c2001-05-25Per Hedbor  Blob **tmp;
4ad07e2001-05-22Per Hedbor  int nblobs; struct object *res; };
6aa8ef2001-05-23Per Hedbor static void free_stuff( void *_t )
4ad07e2001-05-22Per Hedbor { struct tofree *t= (struct tofree *)_t; int i; if( t->res ) free_object( t->res ); for( i = 0; i<t->nblobs; i++ ) wf_blob_free( t->blobs[i] );
107c242002-01-02Johan Schön  free(t->blobs);
a23b4c2001-05-25Per Hedbor  free( t->tmp );
4ad07e2001-05-22Per Hedbor  free( t ); }
a23b4c2001-05-25Per Hedbor #define OFFSET(X) \
af27a62001-07-31Johan Schön  (X.type == HIT_BODY?X.u.body.pos:X.u.field.pos) #define DOFF(X) _distance_f(X) #define MOFF(X) (X.type==HIT_BODY?0:X.u.field.type+1)
a23b4c2001-05-25Per Hedbor 
7a08b42001-05-25Per Hedbor static int _distance_f( int distance ) { if( distance < 2 ) return 0; if( distance < 6 ) return 1; if( distance < 11 ) return 2; if( distance < 22 ) return 3; if( distance < 42 ) return 4; if( distance < 82 ) return 5; if( distance < 161 ) return 6; return 7; }
a23b4c2001-05-25Per Hedbor  static void handle_hit( Blob **blobs, int nblobs, struct object *res,
5cdc2c2001-05-25Per Hedbor  int docid,
af27a62001-07-31Johan Schön  double *field_c[65],
a633972001-05-25Per Hedbor  double *prox_c[8],
73e9422001-05-28Per Hedbor  double mc, double mp, int cutoff )
a23b4c2001-05-25Per Hedbor { int i, j, k, end = 0;
9c14f32014-04-27Martin Nilsson  Hit *hits = calloc( nblobs, sizeof(Hit) );
a23b4c2001-05-25Per Hedbor  unsigned char *nhits = malloc( nblobs ); unsigned char *pos = malloc( nblobs );
af27a62001-07-31Johan Schön  int matrix[65][8];
a23b4c2001-05-25Per Hedbor 
21b12a2014-09-03Martin Nilsson  memset(matrix, 0, sizeof(matrix) );
a23b4c2001-05-25Per Hedbor  for( i = 0; i<nblobs; i++ ) nhits[i] = wf_blob_nhits( blobs[i] ); for( i = 0; i<nblobs; i++ ) {
21b12a2014-09-03Martin Nilsson  memset( pos, 0, nblobs );
a23b4c2001-05-25Per Hedbor  for( j = 0; j<nhits[i]; j++ ) { hits[i] = wf_blob_hit( blobs[i], j );
a1a4882001-05-31Johan Schön  matrix[MOFF(hits[i])][3]++;
ccfc832001-05-25Per Hedbor 
a23b4c2001-05-25Per Hedbor  /* forward the other positions */ for( k = 0; k<nblobs; k++ )
a633972001-05-25Per Hedbor  if( k != i && pos[ k ] < nhits[ k ] )
a23b4c2001-05-25Per Hedbor  {
cce09d2001-05-25Per Hedbor  while( (hits[k].raw < hits[i].raw) && (pos[ k ] < nhits[ k ]))
a23b4c2001-05-25Per Hedbor  hits[k] = wf_blob_hit( blobs[k], pos[k]++ );
07a8a02001-05-25Per Hedbor  if( (pos[ k ] < nhits[ k ]) && hits[k].type == hits[i].type )
73e9422001-05-28Per Hedbor  matrix[MOFF(hits[i])][DOFF(OFFSET(hits[k])-OFFSET(hits[i]))]+=4;
a23b4c2001-05-25Per Hedbor  } } }
13670c2015-05-25Martin Nilsson 
ccfc832001-05-25Per Hedbor  free( pos ); free( nhits ); free( hits );
a23b4c2001-05-25Per Hedbor  /* Now we have our nice matrix. Time to do some multiplication */
5cdc2c2001-05-25Per Hedbor  { double accum = 0.0, fc, pc; int accum_i;
af27a62001-07-31Johan Schön  for( i = 0; i<65; i++ )
a633972001-05-25Per Hedbor  if( (fc = (*field_c)[i]) != 0.0 )
5cdc2c2001-05-25Per Hedbor  for( j = 0; j<8; j++ )
a633972001-05-25Per Hedbor  if( (pc = (*prox_c)[j]) != 0.0 )
73e9422001-05-28Per Hedbor  accum += (MINIMUM(matrix[i][j],cutoff)*fc*pc) / (mc*mp);
5cdc2c2001-05-25Per Hedbor  /* Limit */ if( accum > 32000.0 ) accum = 32000.0;
af27a62001-07-31Johan Schön  accum_i = (int)(accum *100 ) + 1; if( accum > 0.0 )
5cdc2c2001-05-25Per Hedbor  wf_resultset_add( res, docid, accum_i ); }
a23b4c2001-05-25Per Hedbor }
fdc4662001-05-31Johan Schön static struct object *low_do_query_or( Blob **blobs,
4ad07e2001-05-22Per Hedbor  int nblobs,
af27a62001-07-31Johan Schön  double field_c[65],
73e9422001-05-28Per Hedbor  double prox_c[8], int cutoff)
4ad07e2001-05-22Per Hedbor { struct object *res = wf_resultset_new(); struct tofree *__f = malloc( sizeof( struct tofree ) );
a633972001-05-25Per Hedbor  double max_c=0.0, max_p=0.0;
4ad07e2001-05-22Per Hedbor  ONERROR e;
ccfc832001-05-25Per Hedbor  int i, j;
a23b4c2001-05-25Per Hedbor  Blob **tmp;
3b095d2014-11-03Martin Nilsson  tmp = calloc( nblobs, sizeof( Blob *) );
4ad07e2001-05-22Per Hedbor  __f->res = res; __f->blobs = blobs; __f->nblobs = nblobs;
a23b4c2001-05-25Per Hedbor  __f->tmp = tmp;
4ad07e2001-05-22Per Hedbor  SET_ONERROR( e, free_stuff, __f );
3693062001-05-22Per Hedbor 
af27a62001-07-31Johan Schön  for( i = 0; i<65; i++ )
a633972001-05-25Per Hedbor  if( field_c[i] > max_c ) max_c = field_c[i];
13670c2015-05-25Martin Nilsson 
a633972001-05-25Per Hedbor  for( i = 0; i<8; i++ ) if( prox_c[i] > max_p ) max_p = prox_c[i];
a23b4c2001-05-25Per Hedbor 
a633972001-05-25Per Hedbor  if( max_p != 0.0 && max_c != 0.0 )
a23b4c2001-05-25Per Hedbor  {
a633972001-05-25Per Hedbor  /* Time to do the real work. :-) */ for( i = 0; i<nblobs; i++ ) /* Forward to first element */
13670c2015-05-25Martin Nilsson  wf_blob_next( blobs[i] );
a633972001-05-25Per Hedbor  /* Main loop: Find the smallest element in the blob array. */
ccfc832001-05-25Per Hedbor  while( 1 )
a633972001-05-25Per Hedbor  {
740b062001-05-28Johan Schön  unsigned int min = 0x7fffffff;
13670c2015-05-25Martin Nilsson 
a633972001-05-25Per Hedbor  for( i = 0; i<nblobs; i++ ) if( !blobs[i]->eof && ((unsigned int)blobs[i]->docid) < min ) min = blobs[i]->docid;
3693062001-05-22Per Hedbor 
740b062001-05-28Johan Schön  if( min == 0x7fffffff )
a633972001-05-25Per Hedbor  break; for( j = 0, i = 0; i < nblobs; i++ ) if( blobs[i]->docid == min && !blobs[i]->eof ) tmp[j++] = blobs[i];
ccfc832001-05-25Per Hedbor 
73e9422001-05-28Per Hedbor  handle_hit( tmp, j, res, min, &field_c, &prox_c, max_c, max_p, cutoff );
13670c2015-05-25Martin Nilsson 
a633972001-05-25Per Hedbor  for( i = 0; i<j; i++ ) wf_blob_next( tmp[i] ); }
a23b4c2001-05-25Per Hedbor  } /* Free workarea and return the result. */
3693062001-05-22Per Hedbor 
4ad07e2001-05-22Per Hedbor  UNSET_ONERROR( e ); __f->res = 0; free_stuff( __f ); return res; }
13670c2015-05-25Martin Nilsson 
ccfc832001-05-25Per Hedbor static void handle_phrase_hit( Blob **blobs, int nblobs, struct object *res, int docid,
af27a62001-07-31Johan Schön  double *field_c[65],
ccfc832001-05-25Per Hedbor  double mc ) { int i, j, k;
a5039e2001-05-30Per Hedbor  unsigned char *nhits = malloc( nblobs*2 ); unsigned char *first = nhits+nblobs;
af27a62001-07-31Johan Schön  int matrix[65];
ccfc832001-05-25Per Hedbor  double accum = 0.0;
13670c2015-05-25Martin Nilsson 
21b12a2014-09-03Martin Nilsson  memset(matrix, 0, sizeof(matrix) );
ccfc832001-05-25Per Hedbor 
a5039e2001-05-30Per Hedbor 
ccfc832001-05-25Per Hedbor  for( i = 0; i<nblobs; i++ )
a5039e2001-05-30Per Hedbor  {
ccfc832001-05-25Per Hedbor  nhits[i] = wf_blob_nhits( blobs[i] );
a5039e2001-05-30Per Hedbor  first[i] = 0; }
ccfc832001-05-25Per Hedbor 
a5039e2001-05-30Per Hedbor  for( i = 0; i<nhits[0]; i++)
ccfc832001-05-25Per Hedbor  { double add;
a5039e2001-05-30Per Hedbor  int hit = 1; Hit m = wf_blob_hit( blobs[0], i ); int h = m.raw; if( (add = (*field_c)[ MOFF(m) ]) == 0.0 ) continue; for( j = 1; j<nblobs; j++) for( k = first[j]; k<nhits[j]; k++ )
ccfc832001-05-25Per Hedbor  {
a5039e2001-05-30Per Hedbor  int h2 = wf_blob_hit_raw( blobs[j], k );
2e9c642013-02-05Jonas Walldén  if( h2 >= h + j )
ccfc832001-05-25Per Hedbor  {
a5039e2001-05-30Per Hedbor  first[j]=k; if( h2-j == h ) hit++; break;
ccfc832001-05-25Per Hedbor  } }
a5039e2001-05-30Per Hedbor  if( hit == nblobs ) accum += add/mc;
ccfc832001-05-25Per Hedbor  }
13670c2015-05-25Martin Nilsson  free( nhits );
ccfc832001-05-25Per Hedbor 
3757912001-05-31Johan Schön  if( accum > 0.0 )
ccfc832001-05-25Per Hedbor  wf_resultset_add( res, docid, (int)(accum*100) ); } static struct object *low_do_query_phrase( Blob **blobs, int nblobs,
af27a62001-07-31Johan Schön  double field_c[65])
ccfc832001-05-25Per Hedbor { struct object *res = wf_resultset_new(); struct tofree *__f = malloc( sizeof( struct tofree ) ); double max_c=0.0; ONERROR e; int i, j; __f->blobs = blobs; __f->nblobs = nblobs; __f->res = res; __f->tmp = 0; SET_ONERROR( e, free_stuff, __f );
af27a62001-07-31Johan Schön  for( i = 0; i<65; i++ )
ccfc832001-05-25Per Hedbor  if( field_c[i] > max_c ) max_c = field_c[i]; if( max_c != 0.0 ) { /* Time to do the real work. :-) */ for( i = 0; i<nblobs; i++ ) /* Forward to first element */ wf_blob_next( blobs[i] ); /* Main loop: Find the smallest element in the blob array. */ while( 1 ) {
740b062001-05-28Johan Schön  unsigned int min = 0x7fffffff;
13670c2015-05-25Martin Nilsson 
ccfc832001-05-25Per Hedbor  for( i = 0; i<nblobs; i++ ) if( blobs[i]->eof ) goto end; else if( ((unsigned int)blobs[i]->docid) < min ) min = blobs[i]->docid;
740b062001-05-28Johan Schön  if( min == 0x7fffffff )
ccfc832001-05-25Per Hedbor  goto end; for( j = 0, i = 0; i < nblobs; i++ )
7f73262013-02-05Jonas Walldén  if( blobs[i]->docid != min ) goto next;
ccfc832001-05-25Per Hedbor 
7f73262013-02-05Jonas Walldén  handle_phrase_hit( blobs, nblobs, res, min, &field_c, max_c );
13670c2015-05-25Martin Nilsson 
7f73262013-02-05Jonas Walldén  next: for( i = 0; i<nblobs; i++ ) if( blobs[i]->docid == min ) wf_blob_next( blobs[i] );
ccfc832001-05-25Per Hedbor  } } end: /* Free workarea and return the result. */ UNSET_ONERROR( e ); __f->res = 0; free_stuff( __f ); return res; }
13670c2015-05-25Martin Nilsson 
73e9422001-05-28Per Hedbor static struct object *low_do_query_and( Blob **blobs, int nblobs,
af27a62001-07-31Johan Schön  double field_c[65],
73e9422001-05-28Per Hedbor  double prox_c[8], int cutoff) { struct object *res = wf_resultset_new(); struct tofree *__f = malloc( sizeof( struct tofree ) ); double max_c=0.0, max_p=0.0; ONERROR e; int i, j; __f->blobs = blobs; __f->nblobs = nblobs; __f->res = res; __f->tmp = 0; SET_ONERROR( e, free_stuff, __f );
af27a62001-07-31Johan Schön  for( i = 0; i<65; i++ )
73e9422001-05-28Per Hedbor  if( field_c[i] > max_c ) max_c = field_c[i]; for( i = 0; i<8; i++ ) if( prox_c[i] > max_p ) max_p = prox_c[i]; if( max_c != 0.0 ) { /* Time to do the real work. :-) */ for( i = 0; i<nblobs; i++ ) /* Forward to first element */ wf_blob_next( blobs[i] ); /* Main loop: Find the smallest element in the blob array. */ while( 1 ) {
740b062001-05-28Johan Schön  unsigned int min = 0x7fffffff;
13670c2015-05-25Martin Nilsson 
73e9422001-05-28Per Hedbor  for( i = 0; i<nblobs; i++ ) if( blobs[i]->eof ) goto end; else if( ((unsigned int)blobs[i]->docid) < min ) min = blobs[i]->docid;
740b062001-05-28Johan Schön  if( min == 0x7fffffff )
73e9422001-05-28Per Hedbor  goto end; for( j = 0, i = 0; i < nblobs; i++ ) if( blobs[i]->docid != min ) goto next; handle_hit( blobs, nblobs, res, min, &field_c,&prox_c, max_c,max_p, cutoff );
13670c2015-05-25Martin Nilsson 
73e9422001-05-28Per Hedbor  next: for( i = 0; i<nblobs; i++ ) if( blobs[i]->docid == min ) wf_blob_next( blobs[i] ); } } end: /* Free workarea and return the result. */ UNSET_ONERROR( e ); __f->res = 0; free_stuff( __f ); return res; }
40a44d2004-08-07Johan Schön  /*! @module Search */
ccfc832001-05-25Per Hedbor  static void f_do_query_phrase( INT32 args )
2ca49e2001-07-05Per Hedbor /*! @decl ResultSet do_query_phrase( array(string) words, @
ccfc832001-05-25Per Hedbor  *! array(int) field_coefficients, @
a17b4d2013-01-29Jonas Walldén  *! function(string,int,int:string) blobfeeder)
40a44d2004-08-07Johan Schön  *! @param words
13670c2015-05-25Martin Nilsson  *!
40a44d2004-08-07Johan Schön  *! Arrays of word ids. Note that the order is significant for the *! ranking.
ccfc832001-05-25Per Hedbor  *!
40a44d2004-08-07Johan Schön  *! @param field_coefficients
ccfc832001-05-25Per Hedbor  *!
40a44d2004-08-07Johan Schön  *! An array of ranking coefficients for the different fields. In the *! range of [0x0000-0xffff]. The array (always) has 65 elements:
ccfc832001-05-25Per Hedbor  *!
40a44d2004-08-07Johan Schön  *! @array *! @elem int 0 *! body *! @elem int 1..64 *! Special field 0..63. *! @endarray
ccfc832001-05-25Per Hedbor  *!
40a44d2004-08-07Johan Schön  *! @param blobfeeder
13670c2015-05-25Martin Nilsson  *!
40a44d2004-08-07Johan Schön  *! This function returns a Pike string containing the word hits for a
a17b4d2013-01-29Jonas Walldén  *! certain word. Call repeatedly until it returns @expr{0@}.
ccfc832001-05-25Per Hedbor  */ { double proximity_coefficients[8];
af27a62001-07-31Johan Schön  double field_coefficients[65];
ccfc832001-05-25Per Hedbor  int numblobs, i; Blob **blobs; struct svalue *cb; struct object *res; struct array *_words, *_field; /* 1: Get all arguments. */
8dfecc2001-05-31David Norlin  get_all_args( "do_query_phrase", args, "%a%a%*",
ccfc832001-05-25Per Hedbor  &_words, &_field, &cb);
af27a62001-07-31Johan Schön  if( _field->size != 65 ) Pike_error("Illegal size of field_coefficients array (expected 65)\n" );
ccfc832001-05-25Per Hedbor  numblobs = _words->size; if( !numblobs ) { struct object *o = wf_resultset_new( ); pop_n_elems( args );
f5ac102001-06-15Per Hedbor  wf_resultset_push( o );
ccfc832001-05-25Per Hedbor  return; }
3b095d2014-11-03Martin Nilsson  blobs = calloc( numblobs, sizeof(Blob *) );
ccfc832001-05-25Per Hedbor  for( i = 0; i<numblobs; i++ )
2ca49e2001-07-05Per Hedbor  blobs[i] = wf_blob_new( cb, _words->item[i].u.string );
ccfc832001-05-25Per Hedbor 
af27a62001-07-31Johan Schön  for( i = 0; i<65; i++ )
ccfc832001-05-25Per Hedbor  field_coefficients[i] = (double)_field->item[i].u.integer; res = low_do_query_phrase(blobs,numblobs, field_coefficients ); pop_n_elems( args );
f5ac102001-06-15Per Hedbor  wf_resultset_push( res );
ccfc832001-05-25Per Hedbor }
7502512001-05-22Per Hedbor 
73e9422001-05-28Per Hedbor static void f_do_query_and( INT32 args )
2ca49e2001-07-05Per Hedbor /*! @decl ResultSet do_query_and( array(string) words, @
f8d9062013-06-14Jonas Walldén  *! array(int) field_coefficients, @ *! array(int) proximity_coefficients, @ *! int cutoff, @ *! function(string,int,int:string) blobfeeder)
40a44d2004-08-07Johan Schön  *! @param words
13670c2015-05-25Martin Nilsson  *!
40a44d2004-08-07Johan Schön  *! Arrays of word ids. Note that the order is significant for the *! ranking. *! *! @param field_coefficients
73e9422001-05-28Per Hedbor  *!
40a44d2004-08-07Johan Schön  *! An array of ranking coefficients for the different fields. In the *! range of [0x0000-0xffff]. The array (always) has 65 elements:
73e9422001-05-28Per Hedbor  *!
40a44d2004-08-07Johan Schön  *! @array *! @elem int 0 *! body *! @elem int 1..64 *! Special field 0..63. *! @endarray
73e9422001-05-28Per Hedbor  *!
40a44d2004-08-07Johan Schön  *! @param proximity_coefficients
73e9422001-05-28Per Hedbor  *!
40a44d2004-08-07Johan Schön  *! An array of ranking coefficients for the different proximity *! categories. Always has 8 elements, in the range of *! [0x0000-0xffff].
73e9422001-05-28Per Hedbor  *!
40a44d2004-08-07Johan Schön  *! @array *! @elem int 0 *! spread: 0 (Perfect hit) *! @elem int 1 *! spread: 1-5 *! @elem int 2 *! spread: 6-10 *! @elem int 3 *! spread: 11-20 *! @elem int 4 *! spread: 21-40 *! @elem int 5 *! spread: 41-80 *! @elem int 6 *! spread: 81-160 *! @elem int 7 *! spread: 161- *! @endarray
73e9422001-05-28Per Hedbor  *!
40a44d2004-08-07Johan Schön  *! @param blobfeeder
13670c2015-05-25Martin Nilsson  *!
40a44d2004-08-07Johan Schön  *! This function returns a Pike string containing the word hits for a
a17b4d2013-01-29Jonas Walldén  *! certain word. Call repeatedly until it returns @expr{0@}.
73e9422001-05-28Per Hedbor  */ { double proximity_coefficients[8];
af27a62001-07-31Johan Schön  double field_coefficients[65];
73e9422001-05-28Per Hedbor  int numblobs, i, cutoff; Blob **blobs; struct svalue *cb; struct object *res; struct array *_words, *_field, *_prox; /* 1: Get all arguments. */ get_all_args( "do_query_and", args, "%a%a%a%d%*", &_words, &_field, &_prox, &cutoff, &cb);
af27a62001-07-31Johan Schön  if( _field->size != 65 ) Pike_error("Illegal size of field_coefficients array (expected 65)\n" );
73e9422001-05-28Per Hedbor  if( _prox->size != 8 ) Pike_error("Illegal size of proximity_coefficients array (expected 8)\n" ); numblobs = _words->size; if( !numblobs ) { struct object *o = wf_resultset_new( ); pop_n_elems( args );
f5ac102001-06-15Per Hedbor  wf_resultset_push( o );
73e9422001-05-28Per Hedbor  return; }
3b095d2014-11-03Martin Nilsson  blobs = calloc( numblobs, sizeof(Blob *) );
73e9422001-05-28Per Hedbor  for( i = 0; i<numblobs; i++ )
2ca49e2001-07-05Per Hedbor  blobs[i] = wf_blob_new( cb, _words->item[i].u.string );
73e9422001-05-28Per Hedbor  for( i = 0; i<8; i++ ) proximity_coefficients[i] = (double)_prox->item[i].u.integer;
af27a62001-07-31Johan Schön  for( i = 0; i<65; i++ )
73e9422001-05-28Per Hedbor  field_coefficients[i] = (double)_field->item[i].u.integer; res = low_do_query_and(blobs,numblobs, field_coefficients, proximity_coefficients, cutoff );
107c242002-01-02Johan Schön 
73e9422001-05-28Per Hedbor  pop_n_elems( args );
f5ac102001-06-15Per Hedbor  wf_resultset_push( res );
73e9422001-05-28Per Hedbor }
1b89a82001-05-29Johan Schön static void f_do_query_or( INT32 args )
2ca49e2001-07-05Per Hedbor /*! @decl ResultSet do_query_or( array(string) words, @
1b89a82001-05-29Johan Schön  *! array(int) field_coefficients, @ *! array(int) proximity_coefficients, @
f8d9062013-06-14Jonas Walldén  *! int cutoff, @
a17b4d2013-01-29Jonas Walldén  *! function(string,int,int:string) blobfeeder)
40a44d2004-08-07Johan Schön  *! @param words
13670c2015-05-25Martin Nilsson  *!
40a44d2004-08-07Johan Schön  *! Arrays of word ids. Note that the order is significant for the *! ranking.
4926f72001-05-22Per Hedbor  *!
40a44d2004-08-07Johan Schön  *! @param field_coefficients
4926f72001-05-22Per Hedbor  *!
40a44d2004-08-07Johan Schön  *! An array of ranking coefficients for the different fields. In the *! range of [0x0000-0xffff]. The array (always) has 65 elements:
4926f72001-05-22Per Hedbor  *!
40a44d2004-08-07Johan Schön  *! @array *! @elem int 0 *! body *! @elem int 1..64 *! Special field 0..63. *! @endarray
4926f72001-05-22Per Hedbor  *!
40a44d2004-08-07Johan Schön  *! @param proximity_coefficients
4926f72001-05-22Per Hedbor  *!
40a44d2004-08-07Johan Schön  *! An array of ranking coefficients for the different proximity *! categories. Always has 8 elements, in the range of *! [0x0000-0xffff].
4926f72001-05-22Per Hedbor  *!
40a44d2004-08-07Johan Schön  *! @array *! @elem int 0 *! spread: 0 (Perfect hit) *! @elem int 1 *! spread: 1-5 *! @elem int 2 *! spread: 6-10 *! @elem int 3 *! spread: 11-20 *! @elem int 4 *! spread: 21-40 *! @elem int 5 *! spread: 41-80 *! @elem int 6 *! spread: 81-160 *! @elem int 7 *! spread: 161- *! @endarray *! *! @param blobfeeder
13670c2015-05-25Martin Nilsson  *!
40a44d2004-08-07Johan Schön  *! This function returns a Pike string containing the word hits for a
a17b4d2013-01-29Jonas Walldén  *! certain word. Call repeatedly until it returns @expr{0@}.
4926f72001-05-22Per Hedbor  */ {
5cdc2c2001-05-25Per Hedbor  double proximity_coefficients[8];
af27a62001-07-31Johan Schön  double field_coefficients[65];
73e9422001-05-28Per Hedbor  int numblobs, i, cutoff;
4ad07e2001-05-22Per Hedbor  Blob **blobs; struct svalue *cb;
a23b4c2001-05-25Per Hedbor  struct object *res;
4ad07e2001-05-22Per Hedbor  struct array *_words, *_field, *_prox; /* 1: Get all arguments. */
8dfecc2001-05-31David Norlin  get_all_args( "do_query_or", args, "%a%a%a%d%*",
73e9422001-05-28Per Hedbor  &_words, &_field, &_prox, &cutoff, &cb);
4ad07e2001-05-22Per Hedbor 
af27a62001-07-31Johan Schön  if( _field->size != 65 ) Pike_error("Illegal size of field_coefficients array (expected 65)\n" );
4ad07e2001-05-22Per Hedbor  if( _prox->size != 8 ) Pike_error("Illegal size of proximity_coefficients array (expected 8)\n" ); numblobs = _words->size; if( !numblobs ) { struct object *o = wf_resultset_new( ); pop_n_elems( args );
f5ac102001-06-15Per Hedbor  wf_resultset_push( o );
4ad07e2001-05-22Per Hedbor  return; }
3b095d2014-11-03Martin Nilsson  blobs = calloc( numblobs, sizeof(Blob *) );
4ad07e2001-05-22Per Hedbor  for( i = 0; i<numblobs; i++ )
2ca49e2001-07-05Per Hedbor  blobs[i] = wf_blob_new( cb, _words->item[i].u.string );
4ad07e2001-05-22Per Hedbor  for( i = 0; i<8; i++ )
a633972001-05-25Per Hedbor  proximity_coefficients[i] = (double)_prox->item[i].u.integer;
4ad07e2001-05-22Per Hedbor 
af27a62001-07-31Johan Schön  for( i = 0; i<65; i++ )
a633972001-05-25Per Hedbor  field_coefficients[i] = (double)_field->item[i].u.integer;
4926f72001-05-22Per Hedbor 
fdc4662001-05-31Johan Schön  res = low_do_query_or(blobs,numblobs,
2ca49e2001-07-05Per Hedbor  field_coefficients, proximity_coefficients, cutoff );
a23b4c2001-05-25Per Hedbor  pop_n_elems( args );
f5ac102001-06-15Per Hedbor  wf_resultset_push( res );
4926f72001-05-22Per Hedbor }
40a44d2004-08-07Johan Schön /*! @endmodule */
73e9422001-05-28Per Hedbor 
fcd0602003-02-18Martin Stjernholm PIKE_MODULE_INIT
7502512001-05-22Per Hedbor { init_resultset_program();
20c5972001-05-23Per Hedbor  init_blob_program();
54025d2001-05-26Per Hedbor  init_blobs_program();
9157232001-05-28Per Hedbor  init_linkfarm_program();
4926f72001-05-22Per Hedbor 
362e4e2016-01-29Martin Nilsson  ADD_FUNCTION( "do_query_or", f_do_query_or, tFunc( tArr(tStr) tArr(tInt) tArr(tInt) tInt tFunc(tStr tInt tInt, tStr), tObj), 0 ); ADD_FUNCTION( "do_query_and", f_do_query_and, tFunc( tArr(tStr) tArr(tInt) tArr(tInt) tInt tFunc(tStr tInt tInt, tStr), tObj), 0 ); ADD_FUNCTION( "do_query_phrase", f_do_query_phrase, tFunc( tArr(tStr) tArr(tInt) tFunc(tStr tInt tInt, tStr), tObj ), 0 );
7502512001-05-22Per Hedbor }
fcd0602003-02-18Martin Stjernholm PIKE_MODULE_EXIT
7502512001-05-22Per Hedbor {
0853842001-05-22Per Hedbor  exit_resultset_program();
20c5972001-05-23Per Hedbor  exit_blob_program();
54025d2001-05-26Per Hedbor  exit_blobs_program();
9157232001-05-28Per Hedbor  exit_linkfarm_program();
7502512001-05-22Per Hedbor }