pike.git
/
src
/
modules
/
_WhiteFish
/
whitefish.c
version
»
Context lines:
10
20
40
80
file
none
3
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.
14
2001/05/25
14
:
29
:
14
per
Exp $");
+
RCSID("$Id: whitefish.c,v 1.
15
2001/05/25
15
:
00
:
04
js
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:44:
#define OFFSET(X) \ (X.type == HIT_BODY?X.u.body.pos:X.type==HIT_FIELD?(X.u.field.pos):(X.u.anchor.pos)) #define DOFF(X) MINIMUM((int)sqrt(X),7) #define MOFF(X) (X.type==HIT_BODY?0:X.type==HIT_FIELD?X.u.field.type+2:1) static void handle_hit( Blob **blobs, int nblobs, struct object *res, int docid,
-
double *field_c[
68
],
+
double *field_c[
66
],
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];
+
int matrix[
66
][8];
MEMSET(hits, 0, nblobs * sizeof(Hit) ); MEMSET(pos, 0, nblobs ); for( i = 0; i<nblobs; i++ ) nhits[i] = wf_blob_nhits( blobs[i] ); for( i = 0; i<nblobs; i++ ) {
pike.git/src/modules/_WhiteFish/whitefish.c:86:
} } } /* 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++ )
+
for( i = 0; i<
66
; 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,
-
double field_c[
68
],
+
double field_c[
66
],
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 *) );
pike.git/src/modules/_WhiteFish/whitefish.c:165:
/* Free workarea and return the result. */ UNSET_ONERROR( e ); __f->res = 0; free_stuff( __f ); return res; } static void f_do_query_merge( INT32 args )
-
/*! @decl ResultSet do_query_merge( array(int)
musthave
, @
+
/*! @decl ResultSet do_query_merge( array(int)
words
, @
*! array(int) field_coefficients, @ *! array(int) proximity_coefficients, @
-
*! function(int:string) blobfeeder
,
@
-
*!
int field)
-
*!
@[
musthave
]
+
*! function(int:string) blobfeeder
)
+
*! @[
words
]
*! *! Arrays of word ids. Note that the order is significant *! for the ranking. *! *! @[field_coefficients] *! *! An array of ranking coefficients for the different fields.
-
*! In the range of [0x0000-0xffff]. The array (always) has
68
+
*! In the range of [0x0000-0xffff]. The array (always) has
66
*! elements: *! *! Index Coefficient for field *! ----- ---------------------
-
*! 0
..63
Special
field
0..63
-
*!
64 Large
body
text
-
*!
65
Medium
body text
-
*!
66
Small body text
-
*! 67 Anchor
+
*! 0 body
+
*!
1
anchor
+
*!
2..65
Special
field
0..63
*! *! @[proximity_coefficients] *! *! An array of ranking coefficients for the different *! proximity categories. Always has 8 elements, in the range *! of [0x0000-0xffff]. *! *! Index Meaning *! ----- ------- *! 0 spread: 0 (Perfect hit)
pike.git/src/modules/_WhiteFish/whitefish.c:215:
*! *! 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. */ { double proximity_coefficients[8];
-
double field_coefficients[
68
];
+
double field_coefficients[
66
];
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
",
+
get_all_args( "do_query_merge", args, "%a%a%a%
*
",
&_words, &_field, &_prox, &cb);
-
if( _field->size !=
68
)
-
Pike_error("Illegal size of field_coefficients array (expected
68
)\n" );
+
if( _field->size !=
66
)
+
Pike_error("Illegal size of field_coefficients array (expected
66
)\n" );
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 ); 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] = (double)_prox->item[i].u.integer/65535.0;
-
for( i = 0; i<
68
; i++ )
+
for( i = 0; i<
66
; i++ )
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)