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);
 }
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this SearchIndex is new, it will return
  * an empty collection; or if this SearchIndex has previously
  * been saved, it will retrieve related SearchIndexWords from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in SearchIndex.
  *
  * @param Criteria $criteria optional Criteria object to narrow the query
  * @param PropelPDO $con optional connection object
  * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
  * @return PropelObjectCollection|SearchIndexWord[] List of SearchIndexWord objects
  */
 public function getSearchIndexWordsJoinUserRelatedByUpdatedBy($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $query = SearchIndexWordQuery::create(null, $criteria);
     $query->joinWith('UserRelatedByUpdatedBy', $join_behavior);
     return $this->getSearchIndexWords($query, $con);
 }
 private function index(array $aPath)
 {
     $oNavigationItem = $this->oRootNavigationItem;
     PageNavigationItem::clearCache();
     while (count($aPath) > 0) {
         $oNavigationItem = $oNavigationItem->namedChild(array_shift($aPath), $this->sLanguageId, true, true);
     }
     FilterModule::getFilters()->handleNavigationPathFound($this->oRootNavigationItem, $oNavigationItem);
     FrontendManager::$CURRENT_NAVIGATION_ITEM = $oNavigationItem;
     $oPageNavigationItem = $oNavigationItem;
     while (!$oPageNavigationItem instanceof PageNavigationItem) {
         $oPageNavigationItem = $oPageNavigationItem->getParent();
     }
     FrontendManager::$CURRENT_PAGE = $oPageNavigationItem->getMe();
     $oPage = FrontendManager::$CURRENT_PAGE;
     $bIsNotFound = false;
     FilterModule::getFilters()->handlePageHasBeenSet($oPage, $bIsNotFound, $oNavigationItem);
     FilterModule::getFilters()->handleRequestStarted();
     FilterModule::getFilters()->handlePageNotFoundDetectionComplete($bIsNotFound, $oPage, $oNavigationItem, array(&$bIsNotFound));
     if ($bIsNotFound) {
         return false;
     }
     $sDescription = $oNavigationItem->getDescription($this->sLanguageId);
     if ($sDescription === null) {
         $sDescription = $oPage->getDescription($this->sLanguageId);
     }
     $aKeywords = array();
     foreach ($oPage->getConsolidatedKeywords($this->sLanguageId, true) as $sKeyword) {
         $aKeywords = array_merge($aKeywords, StringUtil::getWords($sKeyword));
     }
     $sTitle = $oNavigationItem->getTitle($this->sLanguageId);
     $sLinkText = $oNavigationItem->getLinkText($this->sLanguageId);
     if (!$sLinkText) {
         $sLinkText = $sTitle;
     }
     $sName = $oNavigationItem->getName();
     // Page type can prevent indexing
     if (!self::doIndex($oPage->getPageType(), $oNavigationItem)) {
         return false;
     }
     $oPageType = PageTypeModule::getModuleInstance($oPage->getPageType(), $oPage, $oNavigationItem);
     $aWords = $oPageType->getWords();
     $aWords = array_merge($aWords, StringUtil::getWords($sDescription), $aKeywords, StringUtil::getWords($sTitle), StringUtil::getWords($sLinkText), array($sName));
     $aPagePath = $oPage->getLink();
     $aNavigationItemPath = $oNavigationItem->getLink();
     $sPath = implode('/', array_diff($aNavigationItemPath, $aPagePath));
     $oSearchIndex = new SearchIndex();
     $oSearchIndex->setPageId($oPage->getId());
     $oSearchIndex->setPath($sPath);
     $oSearchIndex->setLinkText($sLinkText);
     $oSearchIndex->setPageTitle($sTitle);
     $oSearchIndex->setLanguageId($this->sLanguageId);
     $oSearchIndex->save();
     foreach ($aWords as $sWord) {
         $sWord = Synonyms::rootFor($sWord, $this->sLanguageId);
         $oSearchIndexWord = SearchIndexWordQuery::create()->filterBySearchIndex($oSearchIndex)->filterByWord($sWord)->findOne();
         if ($oSearchIndexWord === null) {
             $oSearchIndexWord = new SearchIndexWord();
             $oSearchIndexWord->setSearchIndex($oSearchIndex);
             $oSearchIndexWord->setWord($sWord);
         } else {
             $oSearchIndexWord->incrementCount();
         }
         $oSearchIndexWord->save();
     }
     return true;
 }
 /**
  * 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(SearchIndexWordPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = SearchIndexWordQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // denyable behavior
         if (!(SearchIndexWordPeer::isIgnoringRights() || $this->mayOperate("delete"))) {
             throw new PropelException(new NotPermittedException("delete.custom", array("role_key" => "search_index_words")));
         }
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
 /**
  * Returns a new SearchIndexWordQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   SearchIndexWordQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return SearchIndexWordQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof SearchIndexWordQuery) {
         return $criteria;
     }
     $query = new SearchIndexWordQuery(null, null, $modelAlias);
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }