示例#1
0
文件: Phrase.php 项目: stunti/zf2
 /**
  * Optimize query in the context of specified index
  *
  * @param \Zend\Search\Lucene\IndexInterface $index
  * @return \Zend\Search\Lucene\Search\Query\AbstractQuery
  */
 public function optimize(Lucene\IndexInterface $index)
 {
     // Check, that index contains all phrase terms
     foreach ($this->_terms as $term) {
         if (!$index->hasTerm($term)) {
             return new EmptyResult();
         }
     }
     if (count($this->_terms) == 1) {
         // It's one term query
         $optimizedQuery = new Term(reset($this->_terms));
         $optimizedQuery->setBoost($this->getBoost());
         return $optimizedQuery;
     }
     if (count($this->_terms) == 0) {
         return new EmptyResult();
     }
     return $this;
 }
示例#2
0
文件: Term.php 项目: stunti/zf2
 /**
  * Optimize query in the context of specified index
  *
  * @param \Zend\Search\Lucene\IndexInterface $index
  * @return \Zend\Search\Lucene\Search\Query\AbstractQuery
  */
 public function optimize(Lucene\IndexInterface $index)
 {
     // Check, that index contains specified term
     if (!$index->hasTerm($this->_term)) {
         return new EmptyResult();
     }
     return $this;
 }
示例#3
0
文件: MultiTerm.php 项目: stunti/zf2
 /**
  * Optimize query in the context of specified index
  *
  * @param \Zend\Search\Lucene\IndexInterface $index
  * @return \Zend\Search\Lucene\Search\Query\AbstractQuery
  */
 public function optimize(Lucene\IndexInterface $index)
 {
     $terms = $this->_terms;
     $signs = $this->_signs;
     foreach ($terms as $id => $term) {
         if (!$index->hasTerm($term)) {
             if ($signs === null || $signs[$id] === true) {
                 // Term is required
                 return new EmptyResult();
             } else {
                 // Term is optional or prohibited
                 // Remove it from terms and signs list
                 unset($terms[$id]);
                 unset($signs[$id]);
             }
         }
     }
     // Check if all presented terms are prohibited
     $allProhibited = true;
     if ($signs === null) {
         $allProhibited = false;
     } else {
         foreach ($signs as $sign) {
             if ($sign !== false) {
                 $allProhibited = false;
                 break;
             }
         }
     }
     if ($allProhibited) {
         return new EmptyResult();
     }
     /**
      * @todo make an optimization for repeated terms
      * (they may have different signs)
      */
     if (count($terms) == 1) {
         // It's already checked, that it's not a prohibited term
         // It's one term query with one required or optional element
         $optimizedQuery = new Term(reset($terms));
         $optimizedQuery->setBoost($this->getBoost());
         return $optimizedQuery;
     }
     if (count($terms) == 0) {
         return new EmptyResult();
     }
     $optimizedQuery = new MultiTerm($terms, $signs);
     $optimizedQuery->setBoost($this->getBoost());
     return $optimizedQuery;
 }