/**
  * Constructor
  * 
  * @param \Zend_Search_Lucene_Interface					Lucene index instance
  * @param \Zend_Search_Lucene_Search_Query $query		Lucene query
  * @param array $terms									Original search terms
  * @param boolean $highlight							Highlight search terms in results
  * @return void
  */
 public function __construct(\Zend_Search_Lucene_Interface $index, \Zend_Search_Lucene_Search_Query $query, array $terms = array(), $highlight = false)
 {
     $this->_index = $index;
     $this->_query = $query;
     $this->_terms = $terms;
     $this->_index->addReference();
     // Run the Lucene search and register the results
     foreach ($this->_index->find($this->_query) as $hit) {
         $this->_hits[] = \Tollwerk\TwLucenesearch\Domain\Model\QueryHit::cast($hit);
     }
     // If search terms should be highlighted ...
     if (count($this->_hits) && $highlight) {
         $this->_highlight = array();
         foreach ($this->_query->rewrite($this->_index)->getQueryTerms() as $term) {
             if (!array_key_exists($term->field, $this->_highlight)) {
                 $this->_highlight[$term->field] = array($term->text);
             } else {
                 $this->_highlight[$term->field][] = $term->text;
             }
         }
     }
 }
 /**
  * Return the search terms of a lucene search query within the context of the current index 
  * 	
  * @param \Zend_Search_Lucene_Search_Query $query				Lucene search query
  * @return array												Search terms 
  */
 public function getQueryTerms(\Zend_Search_Lucene_Search_Query $query)
 {
     $terms = array();
     foreach ($query->rewrite($this->_index)->getQueryTerms() as $term) {
         if (!array_key_exists($term->field, $terms)) {
             $terms[$term->field] = array($term->text);
         } else {
             $terms[$term->field][] = $term->text;
         }
     }
     return $terms;
 }