Ejemplo n.º 1
0
 /**
  * @param $ID
  * @return Document
  */
 public function getDocumentByID($ID)
 {
     $stmntDoc = $this->db->prepare("\n\t\t\tSELECT ID, internal_ID, type, title, description, path, lang\n\t\t\tFROM mod_search_data\n\t\t\tWHERE ID = ?\n\t\t");
     $resDoc = $this->db->select($stmntDoc, array($ID));
     $doc = new Document();
     if (count($resDoc) <= 0) {
         return $doc;
     }
     $docData = $resDoc[0];
     $doc->setID($docData->ID);
     $doc->setType($docData->type);
     $doc->setTitle($docData->title);
     $doc->setDescription($docData->description);
     $doc->setPath($docData->path);
     $doc->setLanguage($docData->lang);
     return $doc;
 }
Ejemplo n.º 2
0
 public function index()
 {
     $oldReqUri = $_SERVER['REQUEST_URI'];
     $_SERVER['REQUEST_URI'] = '';
     $pageModel = new PageModel($this->indexer->getDB());
     $elementModel = new ElementModel($this->indexer->getDB());
     $searchModel = new SearchModel($this->indexer->getDB());
     $stmntPages = $this->indexer->getDB()->prepare("\n\t\t\tSELECT p.ID, p.language_codeFK lang, p.title, p.description, r.pattern, p.role\n\t\t\tFROM page p\n\t\t\tLEFT JOIN route r ON r.page_IDFK = p.ID\n\t\t\tWHERE r.ID IS NOT NULL\n\t\t");
     $resPages = $this->indexer->getDB()->select($stmntPages);
     $indexedPages = 0;
     foreach ($resPages as $p) {
         if ($p->role !== 'page') {
             echo "  Skipped page #" . $p->ID . ": reason -> unusable role: " . $p->role . PHP_EOL;
             continue;
         }
         $searchIndexInterface = $this->indexer->getIndex($p->lang);
         // Index page
         echo "  Indexing page #" . $p->ID . " into index \"" . $p->lang . "\": ";
         $cmsPage = $pageModel->getPageByID($p->ID);
         $elementTree = $elementModel->getElementTree($cmsPage);
         try {
             $searchableContent = $this->renderElementTreeRecursive($elementTree, $cmsPage->getLanguage());
         } catch (\Exception $e) {
             echo " Error -> " . $e->getMessage() . "\n";
             continue;
         }
         $searchDoc = new Document();
         $searchDoc->setInternalID($p->ID);
         $searchDoc->setLanguage($p->lang);
         $searchDoc->setTitle($p->title);
         $searchDoc->setDescription($searchableContent);
         $searchDoc->setPath($p->pattern);
         $searchDoc->setType('core_page');
         $docID = $searchModel->saveDocument($searchDoc);
         $luceneDocument = new \ZendSearch\Lucene\Document();
         $luceneDocument->addField(Field::keyword('ID', $docID));
         $luceneDocument->addField(Field::unStored('content', $searchableContent));
         $luceneDocument->addField(Field::unStored('description', $p->description));
         $searchIndexInterface->addDocument($luceneDocument);
         echo "done";
         echo "\n";
         ++$indexedPages;
     }
     $_SERVER['REQUEST_URI'] = $oldReqUri;
     echo "  Total indexed pages: " . $indexedPages . "\n";
 }