pike.git / lib / modules / Search.pmod / Query.pmod

version» Context lines:

pike.git/lib/modules/Search.pmod/Query.pmod:1:         // This file is part of Roxen Search   // Copyright © 2001 Roxen IS. All rights reserved.   // - // $Id: Query.pmod,v 1.33 2008/03/27 08:04:06 liin Exp $ + // $Id: Query.pmod,v 1.34 2008/03/27 12:57:37 jonasw Exp $      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 = ([ ]);    return lambda( string word, int foo )    {    return db->get_blob(word, state[word]++, blobcache);    };
pike.git/lib/modules/Search.pmod/Query.pmod:150:    static function(void:Search.ResultSet) pop;       array(Search.ResultSet|array(string)) execute(ParseNode q) {    exec(q);    if (sizeof(stack) != 1)    error("Stack should have exactly one item!");    return ({ pop(), words, glob_words });    }       -  void exec(ParseNode q) { +  void exec(ParseNode q, void|int use_AND_optimization) {    int max_globs = 100;    switch (q->op) {    case "and":    {    int first = 1;    foreach (q->children, ParseNode child)    { -  exec(child); +  exec(child, (q->op == "and") && !first);    if (!first) {    Search.ResultSet r2 = pop();    Search.ResultSet r1 = pop();    push(r1 & r2);    }    else    first = 0;    }    }    break;    case "or":    {    int first = 1;    foreach (q->children, ParseNode child) { -  exec(child); +  exec(child, 0);    if (!first) {    Search.ResultSet r2 = pop();    Search.ResultSet r1 = pop();    push(r1 | r2);    }    else    first = 0;    }    }    break;
pike.git/lib/modules/Search.pmod/Query.pmod:289:    }       int hasPlus = sizeof(q->plusWords) || sizeof(q->plusPhrases);    int hasOrdinary = sizeof(q->words) || sizeof(q->phrases);    int hasMinus = sizeof(q->minusWords) || sizeof(q->minusPhrases);    int hasEverything =    has_value(plusWordGlobs, "*") ||    has_value(ordinaryWordGlobs, "*");    if (hasEverything) {    // FIXME: Ranking? +  if (use_AND_optimization && sizeof(stack)) { +  // If the current operation is AND we can never get a +  // result set after subtraction containing more entries than +  // the set pushed on the stack from our previous siblings. +  push(stack->top()); +  } else {    push(db->get_all_documents()); -  +  }    hasPlus = 0;    hasOrdinary = 0;    plusWordGlobs -= ({ "*" });    ordinaryWordGlobs -= ({ "*" });    }       glob_words += Array.uniq(plusWordGlobs | ordinaryWordGlobs);       if(hasPlus)    {