コード例 #1
0
ファイル: indexed_search.php プロジェクト: rii-J/concrete5-de
	/** 
	 * Reindexes the search engine.
	 */
	public function reindex() {

		Loader::library('3rdparty/Zend/Search/Lucene');
		Loader::library('3rdparty/StandardAnalyzer/Analyzer/Standard/English');

		$index = new Zend_Search_Lucene(DIR_FILES_CACHE_PAGES, true);
		//Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
		Zend_Search_Lucene_Analysis_Analyzer::setDefault(new StandardAnalyzer_Analyzer_Standard_English());
		
		$db = Loader::db();
		$collection_attributes = Loader::model('collection_attributes');
		$r = $db->query("select cID from Pages order by cID asc");
		$g = Group::getByID(GUEST_GROUP_ID);
		$nh = Loader::helper('navigation');
		
		while ($row = $r->fetchRow()) {
			$c = Page::getByID($row['cID'], 'ACTIVE');
			
			if($c->getCollectionAttributeValue('exclude_search_index')) continue;		
			
			$themeObject = $c->getCollectionThemeObject();
			$g->setPermissionsForObject($c);
			if ($g->canRead()) {			
				$pageID = md5($row['cID']);
				$doc = new Zend_Search_Lucene_Document();
				$doc->addField(Zend_Search_Lucene_Field::Keyword('cIDhash', $pageID));
				$doc->addField(Zend_Search_Lucene_Field::Unindexed('cID', $row['cID']));
				$doc->addField(Zend_Search_Lucene_Field::Text('cName', $c->getCollectionName(), APP_CHARSET));
				$doc->addField(Zend_Search_Lucene_Field::Keyword('ctHandle', $c->getCollectionTypeHandle()));
				$doc->addField(Zend_Search_Lucene_Field::Text('cDescription', $c->getCollectionDescription(), APP_CHARSET));
				$doc->addField(Zend_Search_Lucene_Field::Text('cBody', $this->getBodyContentFromPage($c), APP_CHARSET));
				
				if (is_object($themeObject)) {
					$doc->addField(Zend_Search_Lucene_Field::Text('cTheme', $themeObject->getThemeHandle()));
				}
				$doc->addField(Zend_Search_Lucene_Field::Text( 'cPath', $c->getCollectionPath())); 
				
				if (count($this->cPathSections) > 0) {
					foreach($this->cPathSections as $var => $cPath) {
						$isInSection = (strstr(strtolower($c->getCollectionPath()), $cPath . '/')) ? 'true' : 'false';
						$doc->addField(Zend_Search_Lucene_Field::Keyword($var, $isInSection));
					}
				}
				
				$attributes=$c->getSetCollectionAttributes();
				foreach($attributes as $attribute){
					if ($attribute->isCollectionAttributeKeySearchable()) {
						$doc->addField(Zend_Search_Lucene_Field::Keyword( $attribute->akHandle, $c->getCollectionAttributeValue($attribute) ));
					}
				}
				
				$index->addDocument($doc);
			}			
		}
		$result = new stdClass;
		$result->count = $index->count();
		return $result;
	}