11aeec2001-05-25Johan Schön mapping blob_done=([]);
eac31a2001-05-31Johan Schön static function(int:string) blobfeeder(Search.Database.Base db, array word_ids)
11aeec2001-05-25Johan Schön { mapping state = mkmapping(word_ids,allocate(sizeof(word_ids))); return lambda( int word ) { return db->get_blob(word, state[word]++); }; }
965c0b2001-05-29Johan Schön 
eac31a2001-05-31Johan Schön Search.ResultSet do_query_or(Search.Database.Base db,
965c0b2001-05-29Johan Schön  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)); }
eac31a2001-05-31Johan Schön Search.ResultSet do_query_and(Search.Database.Base db,
965c0b2001-05-29Johan Schön  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)); }
eac31a2001-05-31Johan Schön Search.ResultSet do_query_phrase(Search.Database.Base db,
965c0b2001-05-29Johan Schön  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)); }
3771f12001-05-31David Norlin  // Execute a parsed, optimized and validated query by a parser static void lowlevel(string s, mixed ... args) { werror(s, @args); werror("\n"); } static constant ParseNode = Search.Grammar.ParseNode; void execute(ParseNode q) { switch (q->op) { case "and": { int first = 1; foreach (q->children, ParseNode child) if (child->op != "date") { execute(child); if (!first) lowlevel("AND"); else first = 0; } foreach (q->children, ParseNode child) if (child->op == "date") execute(child); } break; case "or": int first = 1; foreach (q->children, ParseNode child) { execute(child); if (!first) lowlevel("OR"); else first = 0; } break; case "date": lowlevel("DATE_FILTER %O", q->date); break; case "text": { int hasPlus = sizeof(q->plusWords) || sizeof(q->plusPhrases); int hasOrdinary = sizeof(q->words) || sizeof(q->phrases); int hasMinus = sizeof(q->minusWords) || sizeof(q->minusPhrases); if (hasPlus) { int first = 1; if (sizeof(q->plusWords)) { lowlevel("QUERY_AND field:%O %{ %O%}", q->field, q->plusWords); first = 0; } foreach (q->plusPhrases, array(string) ph) { lowlevel("QUERY_PHRASE field:%O %{ %O%}", q->field, ph); if (first) first = 0; else lowlevel("AND"); } } if (hasOrdinary) { int first = 1; if (sizeof(q->words)) { lowlevel("QUERY_OR field:%O %{ %O%}", q->field, q->words); first = 0; } foreach (q->phrases, array(string) ph) { lowlevel("QUERY_PHRASE field:%O %{ %O%}", q->field, ph); if (first) first = 0; else lowlevel("OR"); } } if (hasPlus && hasOrdinary) lowlevel("UPRANK"); // the XXX operation :) if (hasMinus) { int first = 1; if (sizeof(q->minusWords)) { lowlevel("QUERY_OR field:%O %{ %O%}", q->field, q->minusWords); first = 0; } foreach (q->minusPhrases, array(string) ph) { lowlevel("QUERY_PHRASE field:%O %{ %O%}", q->field, ph); if (first) first = 0; else lowlevel("OR"); } lowlevel("SUB"); // Only - words are not allowed } break; } } // switch (q->op) }
965c0b2001-05-29Johan Schön /* Test stuff */
eac31a2001-05-31Johan Schön Search.ResultSet test_query(Search.Database.Base db, array(string) words)
11aeec2001-05-25Johan Schön { array(int) field_ranking=allocate(66); field_ranking[0]=17;
965c0b2001-05-29Johan Schön  field_ranking[2]=147;
11aeec2001-05-25Johan Schön  array(int) prox_ranking=allocate(8); for(int i=0; i<8; i++) prox_ranking[i]=8-i;
965c0b2001-05-29Johan Schön  return _WhiteFish.do_query_and(map(words, hash),
11aeec2001-05-25Johan Schön  field_ranking, prox_ranking,
965c0b2001-05-29Johan Schön  8,
11aeec2001-05-25Johan Schön  blobfeeder(db, map(words,hash) )); }
eb80b82001-05-25Per Hedbor 
eac31a2001-05-31Johan Schön _WhiteFish.ResultSet test_query2(Search.Database.Base db, array(string) words)
eb80b82001-05-25Per Hedbor { 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) )); }