Branch: Tag:

2004-08-07

2004-08-07 15:27:00 by Johan Schön <js@opera.com>

Merge from external js/per/nilsson fork

Rev: lib/modules/Search.pmod/Database.pmod/Base.pike:1.5
Rev: lib/modules/Search.pmod/Database.pmod/Base.pmod:1.20(DEAD)
Rev: lib/modules/Search.pmod/Database.pmod/MySQL.pike:1.77
Rev: lib/modules/Search.pmod/Filter.pmod/Base.pike:1.16
Rev: lib/modules/Search.pmod/Filter.pmod/HTML.pmod:1.37
Rev: lib/modules/Search.pmod/Filter.pmod/Output.pike:1.1
Rev: lib/modules/Search.pmod/Filter.pmod/PDF.pmod:1.16
Rev: lib/modules/Search.pmod/Filter.pmod/PlainText.pmod:1.9
Rev: lib/modules/Search.pmod/Filter.pmod/Word.pmod:1.12
Rev: lib/modules/Search.pmod/Grammar.pmod/AbstractParser.pike:1.7
Rev: lib/modules/Search.pmod/Grammar.pmod/DefaultParser.pike:1.11
Rev: lib/modules/Search.pmod/Grammar.pmod/Lexer.pmod:1.7
Rev: lib/modules/Search.pmod/Grammar.pmod/module.pmod:1.12
Rev: lib/modules/Search.pmod/Indexer.pmod:1.17
Rev: lib/modules/Search.pmod/MergeFile.pike:1.1
Rev: lib/modules/Search.pmod/Process.pmod:1.12
Rev: lib/modules/Search.pmod/Query.pmod:1.26
Rev: src/modules/_WhiteFish/Makefile.in:1.7
Rev: src/modules/_WhiteFish/blob.c:1.34
Rev: src/modules/_WhiteFish/blobs.c:1.12
Rev: src/modules/_WhiteFish/buffer.c:1.13
Rev: src/modules/_WhiteFish/linkfarm.c:1.5
Rev: src/modules/_WhiteFish/resultset.c:1.24
Rev: src/modules/_WhiteFish/resultset.h:1.9
Rev: src/modules/_WhiteFish/whitefish.c:1.35

1: +  +    // This file is part of Roxen Search   // Copyright © 2001 Roxen IS. All rights reserved.   // - // $Id: Query.pmod,v 1.25 2002/03/25 12:54:32 js Exp $ + // $Id: Query.pmod,v 1.26 2004/08/07 15:26:58 js Exp $    - static function(string,int:string) blobfeeder(Search.Database.Base db, array words) + static function(string,int:string) blobfeeder(Search.Database.Base db, +  array words)   {    mapping state = mkmapping(words,allocate(sizeof(words)));    mapping(string:mapping(int:string)) blobcache = ([ ]);
59:    return result;   }    + enum search_order + { +  RELEVANCE=1, DATE_ASC, DATE_DESC, NONE + }; +  + static Search.ResultSet sort_resultset(Search.ResultSet resultset, +  search_order order, +  Search.Database.Base db) + { +  + } +  +    //! @param query   //! The query string entered by user.   //! @param db
79:   array(Search.ResultSet|array(string)) execute(Search.Database.Base db,    Search.Grammar.AbstractParser parser,    string query, -  Search.RankingProfile defaultRanking, -  array(string)|void stop_words) +  Search.RankingProfile ranking, +  void|array(string) stop_words, +  void|search_order order)   {    Search.Grammar.ParseNode q = parser->parse(query); -  if (stop_words && sizeof(stop_words)) { -  q = Search.Grammar.remove_stop_words(q, stop_words); -  } +  if (stop_words && sizeof(stop_words)) +  Search.Grammar.remove_stop_words(q, stop_words);       q = Search.Grammar.optimize(q);   
96:    if (error)    throw (error);    -  return class { +  array(Search.ResultSet|array(string)) res = class {    static Search.RankingProfile defaultRanking;    static Search.Database.Base db;   
107:    db = _db;    defaultRanking = _defaultRanking;    specialRanking = defaultRanking->copy(); +  pop = stack->pop; +  push = stack->push;    }       static array(array(string)) split_words(array(string) words)
123:    static constant ParseNode = Search.Grammar.ParseNode;       static array(array(string)|string) words = ({ }); -  static array(Search.ResultSet) stack = ({ }); -  static void push(Search.ResultSet r) { -  stack = ({ r }) + stack; -  } -  static Search.ResultSet pop() { -  if (!sizeof(stack)) -  error("Very bad!"); -  Search.ResultSet r = stack[0]; -  stack = stack[1 .. ]; -  return r; -  } +  static ADT.Stack stack = ADT.Stack(); +  static function(Search.ResultSet:void) push; +  static function(void:Search.ResultSet) pop;       array(Search.ResultSet|array(string)) execute(ParseNode q) {    exec(q);    if (sizeof(stack) != 1) -  throw ("Stack should have exactly one item!"); +  error("Stack should have exactly one item!");    return ({ pop(), words });    }   
150:    {    int first = 1;    foreach (q->children, ParseNode child) -  if (child->op != "date") { +  {    exec(child);    if (!first) {    Search.ResultSet r2 = pop();
160:    else    first = 0;    } -  // ( DATE: limitations not implemented yet... ) -  // -  // foreach (q->children, ParseNode child) -  // if (child->op == "date") -  // exec(child); +     }    break;    case "or": -  +  {    int first = 1;    foreach (q->children, ParseNode child) {    exec(child);
179:    else    first = 0;    } +  }    break;    case "date": -  // NOT IMPLEMENTED YET +  _WhiteFish.DateSet global_dateset = db->get_global_dateset(); +  +  int t = Calendar.ISO.dwim_day(q->date)->unix_time(); +  +  if(!sizeof(global_dateset)) +  { +  push(global_dateset);    break; -  +  } +  +  _WhiteFish.DateSet restriction; +  switch(q->operator[1]) +  { +  case "=": +  break; +  case "<>": +  break; +  case "!=": +  // restriction = global_dateset->...; +  break; +  case "<=": +  restriction = global_dateset->before(t+1)->finalize(); +  break; +  case ">=": +  restriction = global_dateset->after(t-1)->finalize(); +  break; +  case "<": +  restriction = global_dateset->before(t)->finalize(); +  break; +  case ">": +  restriction = global_dateset->after(t)->finalize(); +  break; +  } +  push(restriction); +  break; +     case "text":    {    Search.RankingProfile ranking = defaultRanking;
205:    [array ordinaryWords, array ordinaryWordGlobs] = split_words(q->words);    [array minusWords, array minusWordGlobs] = split_words(q->minusWords);    - // werror("[%-10s] plus: %-15s ordinary: %-15s minus: %-15s\n", q->field, q>plusWords*", ", q->words*", ", q->minusWords*", "); + // werror("[%-10s] plus: %-15s ordinary: %-15s minus: %-15s\n", q->field, q>plusWords*", ", q->words*", ", q->minusWords*", ");       int hasPlus = sizeof(q->plusWords) || sizeof(q->plusPhrases);    int hasOrdinary = sizeof(q->words) || sizeof(q->phrases);
329:    } // switch (q->op)    }    -  } (db, defaultRanking)->execute(q); +  } (db, ranking)->execute(q); +  +  res[0] -= db->get_deleted_documents(); +  +  if(!order) +  order = RELEVANCE; +  +  if(order!=NONE) +  switch(order) +  { +  case RELEVANCE: +  res[0]->sort(); +  break; +  case DATE_ASC: +  case DATE_DESC: +  res[0] = res[0]->finalize()->add_ranking(db->get_global_dateset()); +  if(order==DATE_DESC) +  res[0]->sort(); +  else +  res[0]->sort_rev(); +  case NONE:    } -  +  +  return res; + }