public function display(Template $oTemplate, $bIsPreview = false) { $sTemplateName = $this->oPage->getTemplateNameUsed(); $sLanguageId = Session::language(); $oListTemplate = null; $oItemTemplatePrototype = null; try { $oListTemplate = new Template("search_results/{$sTemplateName}"); $oItemTemplatePrototype = new Template("search_results/{$sTemplateName}_item"); } catch (Exception $e) { $oListTemplate = new Template("search_results/default"); $oItemTemplatePrototype = new Template("search_results/default_item"); } $aResults = array(); $sWords = isset($_REQUEST['q']) ? $_REQUEST['q'] : ''; if ($sWords) { $aWords = StringUtil::getWords($sWords, false, '%'); $oSearchWordQuery = SearchIndexWordQuery::create(); foreach ($aWords as $sWord) { $sWord = Synonyms::rootFor($sWord); $sComparison = Criteria::EQUAL; if (strpos($sWord, '%') !== false) { $sComparison = Criteria::LIKE; } $oSearchWordQuery->addOr(SearchIndexWordPeer::WORD, $sWord, $sComparison); } $oSearchWordQuery->joinSearchIndex()->useQuery('SearchIndex')->joinPage()->useQuery('Page')->active(true)->filterByIsProtected(false)->endUse()->endUse(); foreach ($oSearchWordQuery->find() as $oSearchIndexWord) { $iId = $oSearchIndexWord->getSearchIndexId(); if (isset($aResults[$iId])) { $aResults[$iId] += $oSearchIndexWord->getCount(); } else { $aResults[$iId] = $oSearchIndexWord->getCount(); } } arsort($aResults); } $oListTemplate->replaceIdentifier('count', count($aResults)); $oListTemplate->replaceIdentifier('search_string', $sWords); if (count($aResults) === 0) { $oListTemplate->replaceIdentifier('no_results', TranslationPeer::getString('wns.search.no_results', null, null, array('search_string' => $sWords))); } foreach ($aResults as $iIndexId => $iCount) { $oIndex = SearchIndexQuery::create()->findPk(array($iIndexId, $sLanguageId)); if (!$oIndex || !$oIndex->getPage()) { continue; } $oItemTemplate = clone $oItemTemplatePrototype; $oIndex->renderListItem($oItemTemplate); $oItemTemplate->replaceIdentifier('count', $iCount); $oListTemplate->replaceIdentifierMultiple('items', $oItemTemplate); } $oTemplate->replaceIdentifier('search_results', $oListTemplate); }
public function renderFile() { //Prerequisites Session::getSession()->setLanguage($this->sLanguageId); //Clear index SearchIndexQuery::create()->filterByLanguageId($this->sLanguageId)->delete(); //Spider index $oRootPage = PagePeer::getRootPage(); $this->oRootNavigationItem = PageNavigationItem::navigationItemForPage($oRootPage); $this->spider($this->oRootNavigationItem); //GC gc_enable(); //Update index PreviewManager::setTemporaryManager('FrontendManager'); foreach ($this->aIndexPaths as $aPath) { $bIsIndexed = $this->index($aPath); set_time_limit(30); $this->gc(); $sMessage = $bIsIndexed ? 'Indexed' : 'Skipped'; print "{$sMessage} <code>/" . htmlentities(implode('/', $aPath)) . "</code><br>\n"; } PreviewManager::revertTemporaryManager(); }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @throws Exception * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(SearchIndexPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = SearchIndexQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); // denyable behavior if (!(SearchIndexPeer::isIgnoringRights() || $this->mayOperate("delete"))) { throw new PropelException(new NotPermittedException("delete.custom", array("role_key" => "search_index"))); } if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * Get the associated SearchIndex object * * @param PropelPDO $con Optional Connection object. * @param $doQuery Executes a query to get the object if required * @return SearchIndex The associated SearchIndex object. * @throws PropelException */ public function getSearchIndex(PropelPDO $con = null, $doQuery = true) { if ($this->aSearchIndex === null && $this->search_index_id !== null && $doQuery) { $this->aSearchIndex = SearchIndexQuery::create()->filterBySearchIndexWord($this)->findOne($con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aSearchIndex->addSearchIndexWords($this); */ } return $this->aSearchIndex; }