1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
mapping blob_done=([]); 
 
static function(int:string) blobfeeder(Search.Database.MySQL db, array word_ids) 
{ 
  mapping state = mkmapping(word_ids,allocate(sizeof(word_ids))); 
  return lambda( int word ) 
         { 
           return db->get_blob(word, state[word]++); 
         }; 
} 
 
 
Search.ResultSet do_query_or(Search.Database.MySQL db, 
                             array(string) words, 
                             Search.RankingProfile ranking) 
{ 
  array(int) word_ids=map(Array.uniq(words), db->hash_word); 
  return _WhiteFish.do_query_or(word_ids, 
                                ranking->field_ranking, 
                                ranking->prox_ranking, 
                                ranking->cutoff, 
                                blobfeeder(db, word_ids)); 
} 
 
Search.ResultSet do_query_and(Search.Database.MySQL db, 
                              array(string) words, 
                              Search.RankingProfile ranking) 
{ 
  array(int) word_ids=map(Array.uniq(words), db->hash_word); 
  return _WhiteFish.do_query_or(word_ids, 
                                ranking->field_ranking, 
                                ranking->prox_ranking, 
                                ranking->cutoff, 
                                blobfeeder(db, word_ids)); 
} 
 
Search.ResultSet do_query_phrase(Search.Database.MySQL db, 
                                 array(string) words, 
                                 Search.RankingProfile ranking) 
{ 
  array(int) word_ids=map(words, db->hash_word); 
  return _WhiteFish.do_query_phrase(word_ids, 
                                    ranking->field_ranking, 
                                    //    ranking->cutoff, 
                                    blobfeeder(db, word_ids)); 
} 
 
 
/* Test stuff */ 
Search.ResultSet test_query(Search.Database.MySQL db, array(string) words) 
{ 
  array(int) field_ranking=allocate(66); 
  field_ranking[0]=17; 
  field_ranking[2]=147; 
 
  array(int) prox_ranking=allocate(8); 
  for(int i=0; i<8; i++) 
    prox_ranking[i]=8-i; 
 
  return _WhiteFish.do_query_and(map(words, hash), 
                                   field_ranking, 
                                   prox_ranking, 
                                   8, 
                                   blobfeeder(db, map(words,hash) )); 
} 
 
_WhiteFish.ResultSet test_query2(Search.Database.MySQL db, array(string) words) 
{ 
  array(int) field_ranking=allocate(66); 
  field_ranking[0]=17; 
  field_ranking[2]=47; 
  return _WhiteFish.do_query_phrase(map(words, hash), 
                                    field_ranking, 
                                    blobfeeder(db, map(words,hash) )); 
}