Example #1
0
 /**
  * Evaluate a search query
  *
  * @param int $context The context to which the query applies (document/folder/both)
  * @return array $permResults
  */
 public function evaluate($context = ExprContext::DOCUMENT_AND_FOLDER)
 {
     global $default;
     $default->log->debug("START EVALUATE");
     if ($context == ExprContext::DOCUMENT_AND_FOLDER) {
         $docs = $this->evaluate(ExprContext::DOCUMENT);
         $folders = $this->evaluate(ExprContext::FOLDER);
         return array('docs' => $docs['docs'], 'folders' => $folders['folders']);
     }
     $this->setContext($context);
     $left = $this->left();
     $left->setIncludeStatus($this->incl_status);
     $right = $this->right();
     $right->setIncludeStatus($this->incl_status);
     $op = $this->op();
     $point = $this->getPoint();
     $result = array();
     if (empty($point)) {
         $point = 'point';
     }
     $resultContext = $this->getContext() == ExprContext::DOCUMENT ? 'docs' : 'folders';
     if ($point == 'merge') {
         $leftres = $left->evaluate($context);
         $rightres = $right->evaluate($context);
         switch ($op) {
             case ExprOp::OP_AND:
                 if ($this->debug) {
                     print "\n\nmerge: intersect\n\n";
                 }
                 $result = OpExpr::intersect($leftres, $rightres);
                 break;
             case ExprOp::OP_OR:
                 if ($this->debug) {
                     print "\n\nmerge: union\n\n";
                 }
                 $result = OpExpr::union($leftres, $rightres);
                 break;
             default:
                 throw new Exception("this condition should not happen");
         }
     } elseif ($point == 'point') {
         if ($this->isDBonly()) {
             $result[$resultContext] = $this->exec_db_query($op, array($this));
         } elseif ($this->isTextOnly()) {
             $result[$resultContext] = $this->exec_text_query($op, array($this));
         } elseif (in_array($op, array(ExprOp::OP_OR, ExprOp::OP_AND))) {
             // do we get to this???
             // TODO: remove me please.... the simpleQuery stuff should go???
             $db_group = array();
             $text_group = array();
             $this->explore($left, $right, $db_group, 'db');
             $this->explore($left, $right, $text_group, 'text');
             $db_result[$resultContext] = $this->exec_db_query($op, $db_group);
             $text_result[$resultContext] = $this->exec_text_query($op, $text_group);
             switch ($op) {
                 case ExprOp::OP_AND:
                     if ($this->debug) {
                         print "\n\npoint: intersect\n\n";
                     }
                     $result[$resultContext] = OpExpr::intersect($db_result, $text_result);
                     break;
                 case ExprOp::OP_OR:
                     if ($this->debug) {
                         print "\n\nmerge: union\n\n";
                     }
                     $result[$resultContext] = OpExpr::union($db_result, $text_result);
                     break;
                 default:
                     throw new Exception('how did this happen??');
             }
         } else {
             throw new Exception('and this?');
         }
     } else {
         // we don't have to do anything
         //throw new Exception('Is this reached ever?');
     }
     $permResults = array();
     if (isset($result[$resultContext])) {
         foreach ($result[$resultContext] as $idx => $item) {
             $permResults[$resultContext][$idx] = $item;
         }
     }
     return $permResults;
 }
 function yy_r9()
 {
     $expr = new OpExpr($this->yystack[$this->yyidx + -4]->minor, ExprOp::CONTAINS, $this->yystack[$this->yyidx + 0]->minor);
     $expr->not($this->yystack[$this->yyidx + -2]->minor);
     $this->_retvalue = $expr;
 }