pike.git / lib / modules / Search.pmod / Grammar.pmod / module.pmod

version» Context lines:

pike.git/lib/modules/Search.pmod/Grammar.pmod/module.pmod:1:   #pike __REAL_VERSION__      //! Abstract parse tree node.   class ParseNode {    string op = "<node>";    array(ParseNode) children = ({});    void addChild(ParseNode n) { if (n) children += ({ n }); }    -  static string indentArray(array(string) stuff, string indent) { +  protected string indentArray(array(string) stuff, string indent) {    return map(stuff,    lambda(string s) {    return replace(s, "\n", "\n" + indent);    }) * ("\n" + indent);    }    -  static string printChildren(string indent) { +  protected string printChildren(string indent) {    return indentArray(children->print(), indent);    }       string print() {    string indent = " " * (strlen(op) + 2);    return sprintf("(%s %s)", op, printChildren(indent));    }    -  static string _sprintf(int t) { +  protected string _sprintf(int t) {    return t=='O' && "ParseNode" + print();    }   }      //! And node.   class AndNode {    inherit ParseNode;    string op = "and";   }   
pike.git/lib/modules/Search.pmod/Grammar.pmod/module.pmod:74:    }   }      //!   multiset(string) getDefaultFields() {    return (< "anchor", "any", "body", "keywords", "title", "url", >);   }      // AND merge: Can merge all nodes with - or + bef. each thing.   // OR merge: Can merge all nodes without any - or +. - static private array(TextNode) mergeTextNodes(array(TextNode) a, string op) { + private array(TextNode) mergeTextNodes(array(TextNode) a, string op) {    array(TextNode) result = ({});    mapping(string:array(TextNode)) fields = ([]);    foreach (a, TextNode t)    fields[t->field] = (fields[t->field] || ({ })) + ({ t });       // Only merge nodes in the same field    foreach (indices(fields), string field) {    array(TextNode) unMerged = ({});    TextNode merged = 0;    foreach (fields[field], TextNode t) {
pike.git/lib/modules/Search.pmod/Grammar.pmod/module.pmod:203:    && !sizeof(node->phrases)) {    node->words = ({ "*" });    }    }    }    if (newChildren)    node->children = newChildren;    return node;   }    - static private void _validate(ParseNode node, ParseNode parent) { + private void _validate(ParseNode node, ParseNode parent) {    map(node->children, _validate, node);    switch (node->op) {    case "date":    if (!parent || parent->op != "and")    throw ("date must restrict query");    break;    case "and":    break;    case "text":    // NOTE: This should no longer be happening since we adjust these
pike.git/lib/modules/Search.pmod/Grammar.pmod/module.pmod:246:    return 0;   }      //!   void remove_stop_words(ParseNode node, array(string) stop_words) {    if (!node || !sizeof(stop_words))    return;    low_remove_stop_words(node, stop_words);   }    - static void low_remove_stop_words(ParseNode node, array(string) stop_words) { + protected void low_remove_stop_words(ParseNode node, array(string) stop_words) {    switch (node->op) {    case "or":    case "and":    foreach(node->children, ParseNode c)    remove_stop_words(c, stop_words);    break;       case "text":    node->plusWords -= stop_words;    node->minusWords -= stop_words;    node->words -= stop_words;    break;    }   }