/**
  * コンテンツデータを登録する
  * コンテンツデータを次のように作成して引き渡す
  * array('SearchIndex' =>
  * 			array(	'model_id'	=> 'モデルでのID'
  * 					'category'	=> 'カテゴリ名',
  * 					'title'		=> 'コンテンツタイトル',		// 検索対象
  * 					'detail'	=> 'コンテンツ内容',		// 検索対象
  * 					'url'		=> 'URL',
  * 					'status' => '公開ステータス'
  * ))
  *
  * @param Model $model
  * @param array $data
  * @return boolean
  */
 public function saveSearchIndex(Model $model, $data)
 {
     if (!$data) {
         return;
     }
     $Content = ClassRegistry::init('Content');
     $content = $Content->find('first', ['fields' => ['lft', 'rght'], 'conditions' => ['Content.id' => $data['SearchIndex']['content_id']], 'recursive' => 1]);
     $data['SearchIndex']['lft'] = $content['Content']['lft'];
     $data['SearchIndex']['rght'] = $content['Content']['rght'];
     $data['SearchIndex']['model'] = $model->alias;
     // タグ、空白を除外
     $data['SearchIndex']['detail'] = str_replace(array("\r\n", "\r", "\n", "\t", "\\s"), '', trim(strip_tags($data['SearchIndex']['detail'])));
     // 検索用データとして保存
     $this->SearchIndex = ClassRegistry::init('SearchIndex');
     $before = false;
     if (!empty($data['SearchIndex']['model_id'])) {
         $before = $this->SearchIndex->find('first', array('fields' => array('SearchIndex.id', 'SearchIndex.content_id'), 'conditions' => array('SearchIndex.model' => $data['SearchIndex']['model'], 'SearchIndex.model_id' => $data['SearchIndex']['model_id'])));
     }
     if ($before) {
         $data['SearchIndex']['id'] = $before['SearchIndex']['id'];
         $this->SearchIndex->set($data);
     } else {
         if (empty($data['SearchIndex']['priority'])) {
             $data['SearchIndex']['priority'] = '0.5';
         }
         $this->SearchIndex->create($data);
     }
     $result = $this->SearchIndex->save();
     // カテゴリを site_configsに保存
     if ($result) {
         return $this->updateSearchIndexMeta($model);
     }
     return $result;
 }
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aSearchIndex !== null) {
             if ($this->aSearchIndex->isModified() || $this->aSearchIndex->isNew()) {
                 $affectedRows += $this->aSearchIndex->save($con);
             }
             $this->setSearchIndex($this->aSearchIndex);
         }
         if ($this->aUserRelatedByCreatedBy !== null) {
             if ($this->aUserRelatedByCreatedBy->isModified() || $this->aUserRelatedByCreatedBy->isNew()) {
                 $affectedRows += $this->aUserRelatedByCreatedBy->save($con);
             }
             $this->setUserRelatedByCreatedBy($this->aUserRelatedByCreatedBy);
         }
         if ($this->aUserRelatedByUpdatedBy !== null) {
             if ($this->aUserRelatedByUpdatedBy->isModified() || $this->aUserRelatedByUpdatedBy->isNew()) {
                 $affectedRows += $this->aUserRelatedByUpdatedBy->save($con);
             }
             $this->setUserRelatedByUpdatedBy($this->aUserRelatedByUpdatedBy);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Exemple #3
0
 private function insertSearchWord($strText, $intId)
 {
     foreach ($this->getWords($strText, self::SEARCH_WEIGHT) as $strWord => $intWeight) {
         $objSearchIndex = new SearchIndex();
         $objSearchIndex->setElementId($intId);
         $objSearchIndex->setWord($strWord);
         $objSearchIndex->setCount($intWeight);
         $objSearchIndex->save();
     }
 }
 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;
 }
Exemple #5
0
 public function updateSearchIndex()
 {
     // update search index
     $c = new Criteria();
     $c->add(SearchIndexPeer::QUESTION_ID, $this->getId());
     SearchIndexPeer::doDelete($c);
     foreach ($this->getWords() as $word => $weight) {
         $index = new SearchIndex();
         $index->setQuestionId($this->getId());
         $index->setWord($word);
         $index->setWeight($weight);
         $index->save();
     }
 }