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

version» Context lines:

pike.git/lib/modules/Search.pmod/Query.pmod:60:    werror("do_query_phrase(%{ %O %}) => %d hits\n", words, result->size());    return result;   }      //! @param query   //! The query string entered by user.   //! @param db   //! The search database.   //! @param defaultRanking   //! Used when searching in the field "any:". - Search.ResultSet execute(Search.Database.Base db, + //! + //! @returns + //! An array with two elements: + //! @array + //! @elem Search.ResultSet 0 + //! The ResultSet containing the hits. + //! @elem array(string) 1 + //! All wanted words in the query. (I.e. not the words that were + //! preceded by minus.) + //! @endarray + //! + array(Search.ResultSet|array(string)) execute(Search.Database.Base db,    Search.Grammar.AbstractParser parser,    string query,    Search.RankingProfile defaultRanking)   { -  +     Search.Grammar.ParseNode q = parser->parse(query);    q = Search.Grammar.optimize(q);    -  if (!q) // The query was a null query -  return Search.ResultSet(); // so return an empty resultset +  if (!q) // The query was a null query +  return ({ Search.ResultSet(), ({}) }); // so return an empty resultset       string error = Search.Grammar.validate(q);    if (error)    throw (error);       werror("Search.Query.execute:\n%s\n", q->print());       return class {    static Search.RankingProfile defaultRanking;    static Search.Database.Base db;
pike.git/lib/modules/Search.pmod/Query.pmod:93:    static Search.RankingProfile specialRanking;       static void create(Search.Database.Base _db, Search.RankingProfile _defaultRanking) {    db = _db;    defaultRanking = _defaultRanking;    specialRanking = defaultRanking->copy();    }       static constant ParseNode = Search.Grammar.ParseNode;    +  static array(array(string)|string) words = ({ });    static array(Search.ResultSet) stack = ({ });    static void push(Search.ResultSet r) {    werror("---PUSH\n");    stack = ({ r }) + stack;    }    static Search.ResultSet pop() {    werror("---POP\n");    if (!sizeof(stack))    error("Very bad!");    Search.ResultSet r = stack[0];    stack = stack[1 .. ];    return r;    }    -  Search.ResultSet execute(ParseNode q) { +  array(Search.ResultSet|array(string)) execute(ParseNode q) {    exec(q);    if (sizeof(stack) != 1)    throw ("Stack should have exactly one item!"); -  return pop(); +  return ({ pop(), words });    }       void exec(ParseNode q) {    werror("EXEC %s\n", q->op);    switch (q->op) {    case "and":    {    int first = 1;    foreach (q->children, ParseNode child)    if (child->op != "date") {
pike.git/lib/modules/Search.pmod/Query.pmod:178:    ranking->field_ranking[fieldID] = defaultRanking->field_ranking[fieldID];    // ranking->field_ranking[fieldID] = 1;    }       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)) { +  words += q->plusWords;    push(do_query_and(db, q->plusWords, ranking));    first = 0;    }    foreach (q->plusPhrases, array(string) ph) { -  +  words += ph;    push(do_query_phrase(db, ph, ranking));    if (!first) {    Search.ResultSet r2 = pop();    Search.ResultSet r1 = pop();    push(r1 & r2);    }    first = 0;    }    }    if (hasOrdinary) {    int first = 1;    if (sizeof(q->words)) { -  +  words += q->words;    push(do_query_or(db, q->words, ranking));    first = 0;    }    foreach (q->phrases, array(string) ph) { -  +  words += ph;    push(do_query_phrase(db, ph, ranking));    if (!first) {    Search.ResultSet r2 = pop();    Search.ResultSet r1 = pop();    push(r1 | r2);    }    first = 0;    }    }