Example #1
0
    /**
     * Re-write query into primitive queries in the context of specified index
     *
     * @param \Zend\Search\Lucene\SearchIndex $index
     * @return \Zend\Search\Lucene\Search\Query\AbstractQuery
     */
    public function rewrite(Lucene\SearchIndex $index)
    {
        if (count($this->_terms) == 0) {
            return new EmptyResult();
        } else if ($this->_terms[0]->field !== null) {
            return $this;
        } else {
            $query = new Boolean();
            $query->setBoost($this->getBoost());

            foreach ($index->getFieldNames(true) as $fieldName) {
                $subquery = new self();
                $subquery->setSlop($this->getSlop());

                foreach ($this->_terms as $termId => $term) {
                    $qualifiedTerm = new Index\Term($term->text, $fieldName);

                    $subquery->addTerm($qualifiedTerm, $this->_offsets[$termId]);
                }

                $query->addSubquery($subquery);
            }

            return $query;
        }
    }
 function copy()
 {
     $copy = new self();
     foreach ($this->terms as $term) {
         $copy->addTerm($term->copy());
     }
     return $copy;
 }