/**
  * Return the associated index document
  * 
  * @return \Tollwerk\TwLucenesearch\Domain\Model\Document 			Associated index document
  * @see \Zend_Search_Lucene_Search_QueryHit::getDocument()
  */
 public function getDocument()
 {
     if (!$this->_document instanceof \Tollwerk\TwLucenesearch\Domain\Model\Document) {
         $this->_document = \Tollwerk\TwLucenesearch\Domain\Model\Document::cast(parent::getDocument());
     }
     return $this->_document;
 }
 /**
  * Reindex an index document 
  * 
  * @param \Tollwerk\TwLucenesearch\Domain\Model\Document $document		Document
  * @return \boolean														Success
  */
 protected function _reindex(\Tollwerk\TwLucenesearch\Domain\Model\Document $document)
 {
     // Prepare the reference parameters
     $reference = $document->getReferenceParameters();
     if (array_key_exists('id', $reference)) {
         $pageUid = $reference['id'];
         unset($reference['id']);
     } else {
         $pageUid = $document->getPageUid();
     }
     if (array_key_exists('type', $reference)) {
         $pageType = $reference['type'];
         unset($reference['type']);
     } else {
         $pageType = 0;
     }
     $reference['index_force_reindex'] = 1;
     // Simulate a frontend environment
     \Tollwerk\TwLucenesearch\Utility\FrontendSimulator::simulateFrontendEnvironment($pageUid);
     // Create the frontend URL
     $uri = $this->uriBuilder->reset()->setTargetPageUid($pageUid)->setTargetPageType($pageType)->setNoCache(true)->setUseCacheHash(false)->setLinkAccessRestrictedPages(true)->setArguments($reference)->setCreateAbsoluteUri(true)->setAddQueryString(false)->setArgumentsToBeExcludedFromQueryString(array())->buildFrontendUri();
     // Fetch (and thus re-index) the URL
     $success = !!strlen($this->_getUrl($uri));
     // Reset the frontend environment
     \Tollwerk\TwLucenesearch\Utility\FrontendSimulator::resetFrontendEnvironment();
     return $success;
 }
 /**
  * Fetch a document by it's type and ID
  * 
  * @param \string $type											Document type
  * @param \string $id											Document ID
  * @return \Tollwerk\TwLucenesearch\Domain\Model\Document		Requested document
  */
 public function getByTypeId($type = null, $id = null)
 {
     $documents = array();
     // Query all index documents for the current page
     $query = new \Zend_Search_Lucene_Search_Query_Boolean();
     // Add a type query
     if ($type !== null && strlen($type)) {
         $typeTerm = new \Zend_Search_Lucene_Index_Term($type, 'type');
         $typeQuery = new \Zend_Search_Lucene_Search_Query_Term($typeTerm);
         $query->addSubquery($typeQuery, true);
     }
     // Add an ID query
     if ($id !== null && strlen($id)) {
         $idTerm = new \Zend_Search_Lucene_Index_Term($id, 'id');
         $idQuery = new \Zend_Search_Lucene_Search_Query_Term($idTerm);
         $query->addSubquery($idQuery, true);
     }
     foreach ($this->_index()->find($query) as $hit) {
         $documents[] = \Tollwerk\TwLucenesearch\Domain\Model\Document::cast($hit->getDocument());
     }
     return $documents;
 }