當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Zend_Search_Lucene::addDocument方法代碼示例

本文整理匯總了PHP中Zend_Search_Lucene::addDocument方法的典型用法代碼示例。如果您正苦於以下問題:PHP Zend_Search_Lucene::addDocument方法的具體用法?PHP Zend_Search_Lucene::addDocument怎麽用?PHP Zend_Search_Lucene::addDocument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend_Search_Lucene的用法示例。


在下文中一共展示了Zend_Search_Lucene::addDocument方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: index

 function index()
 {
     $this->load->library('zend', 'Zend/Feed');
     $this->load->library('zend', 'Zend/Search/Lucene');
     $this->load->library('zend');
     $this->zend->load('Zend/Feed');
     $this->zend->load('Zend/Search/Lucene');
     //Create index.
     $index = new Zend_Search_Lucene('C:\\xampp\\xampp\\htdocs\\controle_frota\\lucene\\feeds_index', true);
     $feeds = array('http://oglobo.globo.com/rss.xml?limite=50');
     //grab each feed.
     foreach ($feeds as $feed) {
         $channel = Zend_Feed::import($feed);
         echo $channel->title() . '<br />';
         //index each item.
         foreach ($channel->items as $item) {
             if ($item->link() && $item->title() && $item->description()) {
                 //create an index doc.
                 $doc = new Zend_Search_Lucene_Document();
                 $doc->addField(Zend_Search_Lucene_Field::Keyword('link', $this->sanitize($item->link())));
                 $doc->addField(Zend_Search_Lucene_Field::Text('title', $this->sanitize($item->title())));
                 $doc->addField(Zend_Search_Lucene_Field::Unstored('contents', $this->sanitize($item->description())));
                 echo "\tAdding: " . $item->title() . '<br />';
                 $index->addDocument($doc);
             }
         }
     }
     $index->commit();
     echo $index->count() . ' Documents indexed.<br />';
 }
開發者ID:ramonsilvanet,項目名稱:controle-frota-php,代碼行數:30,代碼來源:pesquisas.php

示例2: edit

 public function edit($needFields = array(), $data = array(), $charset = 'UTF-8')
 {
     $index = new Zend_Search_Lucene(ZY_ROOT . '/index');
     $doc = new Zend_Search_Lucene_Document();
     foreach ($needFields as $key => $field) {
         switch ($field) {
             case 'keywords':
                 $doc->addField(Zend_Search_Lucene_Field::Keyword($key, $data[$key], $charset));
                 break;
             case 'text':
                 $doc->addField(Zend_Search_Lucene_Field::Text($key, $data[$key], $charset));
                 break;
             case 'unindexed':
                 $doc->addField(Zend_Search_Lucene_Field::unindexed($key, $data[$key], $charset));
                 break;
             default:
                 $doc->addField(Zend_Search_Lucene_Field::$field($key, $data[$key], $charset));
                 break;
         }
     }
     $index->addDocument($doc);
     $index->commit();
     $index->optimize();
     return TRUE;
 }
開發者ID:BGCX262,項目名稱:zyshop-svn-to-git,代碼行數:25,代碼來源:search_lucnene.php

示例3: actionIndexing

 /**
  * This is the default 'index' action that is invoked
  * when an action is not explicitly requested by users.
  */
 public function actionIndexing()
 {
     ini_set('max_execution_time', 0);
     ob_start();
     $index = new Zend_Search_Lucene(Yii::getPathOfAlias($this->_indexFilesPath), true);
     $criteria = new CDbCriteria();
     $criteria->compare('t.publish', 1);
     $criteria->order = 'album_id DESC';
     //$criteria->limit = 10;
     $model = Albums::model()->findAll($criteria);
     foreach ($model as $key => $item) {
         if ($item->media_id != 0) {
             $images = Yii::app()->request->baseUrl . '/public/album/' . $item->album_id . '/' . $item->cover->media;
         } else {
             $images = '';
         }
         $doc = new Zend_Search_Lucene_Document();
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('id', CHtml::encode($item->album_id), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('media', CHtml::encode($images), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('title', CHtml::encode($item->title), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('body', CHtml::encode(Utility::hardDecode(Utility::softDecode($item->body))), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('url', CHtml::encode(Utility::getProtocol() . '://' . Yii::app()->request->serverName . Yii::app()->createUrl('album/site/view', array('id' => $item->album_id, 't' => Utility::getUrlTitle($item->title)))), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('date', CHtml::encode(Utility::dateFormat($item->creation_date, true) . ' WIB'), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('creation', CHtml::encode($item->user->displayname), 'utf-8'));
         $index->addDocument($doc);
     }
     echo 'Album Lucene index created';
     $index->commit();
     $this->redirect(Yii::app()->createUrl('article/search/indexing'));
     ob_end_flush();
 }
開發者ID:OmmuOpenSource,項目名稱:OOS-Company-Profile,代碼行數:35,代碼來源:SearchController.php

示例4: addDocumentToIndex

 /**
  * @param $doc \Zend_Search_Lucene_Document
  */
 public function addDocumentToIndex($doc)
 {
     if ($doc instanceof \Zend_Search_Lucene_Document) {
         $this->index->addDocument($doc);
         \Pimcore\Logger::debug('LuceneSearch: Added to lucene index db entry');
     } else {
         \Pimcore\Logger::error('LuceneSearch: could not parse lucene document ');
     }
 }
開發者ID:dachcom-digital,項目名稱:pimcore-lucene-search,代碼行數:12,代碼來源:Parser.php

示例5: addDocument

 /**
  * A refactored method to add the document to the index..
  *
  * @param int $docid
  * @param string $content
  * @param string $discussion
  */
 private function addDocument($docid, $content, $discussion, $title, $version)
 {
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Text('DocumentID', PHPLuceneIndexer::longToString($docid)));
     $doc->addField(Zend_Search_Lucene_Field::Text('Content', $content, 'UTF-8'));
     $doc->addField(Zend_Search_Lucene_Field::Text('Discussion', $discussion, 'UTF-8'));
     $doc->addField(Zend_Search_Lucene_Field::Text('Title', $title, 'UTF-8'));
     $doc->addField(Zend_Search_Lucene_Field::Text('Version', $version, 'UTF-8'));
     $this->lucene->addDocument($doc);
 }
開發者ID:sfsergey,項目名稱:knowledgetree,代碼行數:17,代碼來源:PHPLuceneIndexer.inc.php

示例6: addDocument

 /**
  * Add a document to the index.
  *
  * @param Zend_Search_Lucene_Document $document The document to be added.
  * @return Zend_Search_Lucene                   
  */
 public function addDocument(Zend_Search_Lucene_Document $document)
 {
     // Search for documents with the same Key value.
     $term = new Zend_Search_Lucene_Index_Term($document->Key, 'Key');
     $docIds = $this->termDocs($term);
     // Delete any documents found.
     foreach ($docIds as $id) {
         $this->delete($id);
     }
     return parent::addDocument($document);
 }
開發者ID:philipnorton42,項目名稱:PDFSearch,代碼行數:17,代碼來源:Lucene.php

示例7: addDocument

 public function addDocument(Zend_Search_Lucene_Document $document)
 {
     $docRef = $document->docRef;
     $term = new Zend_Search_Lucene_Index_Term($docRef, 'docRef');
     $query = new Zend_Search_Lucene_Search_Query_Term($term);
     $results = $this->find($query);
     if (count($results) > 0) {
         foreach ($results as $result) {
             $this->delete($result->id);
         }
     }
     return parent::addDocument($document);
 }
開發者ID:joshauza,項目名稱:baseapp,代碼行數:13,代碼來源:Lucene.php

示例8: fill_index

function fill_index()
{
    for ($i = 0; $i < 10; $i++) {
        $index = new Zend_Search_Lucene('./data/index', true);
        $index->find("test");
        $doc = new Zend_Search_Lucene_Document();
        $doc->addField(Zend_Search_Lucene_Field::Text("test", getword()));
        $doc->addField(Zend_Search_Lucene_Field::UnStored("contents", getword()));
        $index->addDocument($doc);
        $index->commit();
        $index->getDirectory()->close();
        //comment this to see another bug :-|
    }
}
開發者ID:Tony133,項目名稱:zf-web,代碼行數:14,代碼來源:search_test.php

示例9: indexationAdd

 public static function indexationAdd($indexationData)
 {
     $directory = Zend_Registry::get('lucene_index');
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Keyword('pageID', $indexationData['pageID']));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('moduleID', $indexationData['moduleID']));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('contentID', $indexationData['contentID']));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('languageID', $indexationData['languageID']));
     $doc->addField(Zend_Search_Lucene_Field::Text('title', Cible_FunctionsGeneral::html2text($indexationData['title'])));
     $doc->addField(Zend_Search_Lucene_Field::Text('text', Cible_FunctionsGeneral::html2text($indexationData['text'])));
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('link', $indexationData['link']));
     $doc->addField(Zend_Search_Lucene_Field::UnStored('contents', strtolower(Cible_FunctionsGeneral::removeAccents(Cible_FunctionsGeneral::html2text($indexationData['contents'])))));
     $newIndex = !is_dir($directory);
     $index = new Zend_Search_Lucene($directory, $newIndex);
     $index->addDocument($doc);
     $index->commit();
 }
開發者ID:anunay,項目名稱:stentors,代碼行數:18,代碼來源:FunctionsIndexation.php

示例10: actionCreate

 public function actionCreate()
 {
     $index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles), true);
     $items = Items::model()->findAll();
     foreach ($items as $item) {
         $doc = new Zend_Search_Lucene_Document();
         Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
         $doc->addField(Zend_Search_Lucene_Field::keyword('part_number', CHtml::encode($item->part_number), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('name', CHtml::encode($item->name), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('description', CHtml::encode($item->description), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('barcode', CHtml::encode($item->barcode), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::float('available_quantity', CHtml::encode($item->available_quantity), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::float('current_quantity', CHtml::encode($item->current_quantity), 'utf-8'));
         $index->addDocument($doc);
     }
     $index->commit();
     echo 'Lucene index created';
 }
開發者ID:EmmanuelFernando,項目名稱:rapport-stock-control,代碼行數:18,代碼來源:SearchController.php

示例11: addEntryToSearchIndex

 private function addEntryToSearchIndex($url, array $content)
 {
     $options = $this->getInvokeArg('bootstrap')->getOption('lucene');
     $luceneDir = $options['dir'];
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Keyword('url', $url));
     foreach ($content as $key => $value) {
         if (!is_array($value) && $value && strlen($value) && !is_numeric($value)) {
             $doc->addField(Zend_Search_Lucene_Field::Text($key, $value));
         }
     }
     $newIndex = !is_dir($luceneDir);
     $index = new Zend_Search_Lucene($luceneDir, $newIndex);
     $index->addDocument($doc);
     $index->commit();
     //        $index->optimize();
 }
開發者ID:rollxx,項目名稱:iso,代碼行數:17,代碼來源:IndexController.php

示例12: createIndex

function createIndex()
{
    global $db;
    $dir = FULL_PATH . 'Zend/app/tmp/cache';
    $iterator = new RecursiveDirectoryIterator($dir);
    foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) {
        if ($file->isDir()) {
            rmdir($file->getPathname());
        } else {
            unlink($file->getPathname());
        }
    }
    $indexPath1 = FULL_PATH . 'Zend/app/tmp/cache/index1';
    $index1 = new Zend_Search_Lucene($indexPath1, true);
    $q = "SELECT userid, FirstName, LastName, About, tr_About, BizDesc, tr_BizDesc  FROM ! where 1";
    $res1 = $db->getAll($q, array(TBL_BORROWER));
    foreach ($res1 as $row1) {
        $doc1 = new Zend_Search_Lucene_Document();
        // Add some information
        $doc1->addField(Zend_Search_Lucene_Field::Keyword('pk', $row1['userid']));
        $doc1->addField(Zend_Search_Lucene_Field::UnIndexed('document_id', $row1['userid']));
        $doc1->addField(Zend_Search_Lucene_Field::UnStored('document_FirstName', $row1['FirstName']), 'utf-8');
        $doc1->addField(Zend_Search_Lucene_Field::UnStored('document_LastName', $row1['LastName']), 'utf-8');
        $doc1->addField(Zend_Search_Lucene_Field::UnStored('document_About', $row1['About']), 'utf-8');
        $doc1->addField(Zend_Search_Lucene_Field::UnStored('document_tr_About', $row1['tr_About']), 'utf-8');
        $doc1->addField(Zend_Search_Lucene_Field::UnStored('document_BizDesc', $row1['BizDesc']), 'utf-8');
        $doc1->addField(Zend_Search_Lucene_Field::UnStored('document_tr_BizDesc', $row1['tr_BizDesc']), 'utf-8');
        $index1->addDocument($doc1);
    }
    $index1->commit();
    $indexPath2 = FULL_PATH . 'Zend/app/tmp/cache/index2';
    $index2 = new Zend_Search_Lucene($indexPath2, true);
    $p = "SELECT borrowerid,loanid, loanuse,tr_loanuse FROM ! where 1";
    $res2 = $db->getAll($p, array(TBL_LOANAPPLIC));
    foreach ($res2 as $row2) {
        $doc2 = new Zend_Search_Lucene_Document();
        // Add some information
        $doc2->addField(Zend_Search_Lucene_Field::Keyword('pk', $row2['loanid']));
        $doc2->addField(Zend_Search_Lucene_Field::UnIndexed('document_id', $row2['borrowerid']));
        $doc2->addField(Zend_Search_Lucene_Field::UnStored('document_loanuse', $row2['loanuse']), 'utf-8');
        $doc2->addField(Zend_Search_Lucene_Field::UnStored('document_tr_loanuse', $row2['tr_loanuse']), 'utf-8');
        $index2->addDocument($doc2);
    }
    $index2->commit();
    $indexPath3 = FULL_PATH . 'Zend/app/tmp/cache/index3';
    $index3 = new Zend_Search_Lucene($indexPath3, true);
    $r = "SELECT id,receiverid, message, tr_message FROM ! where 1";
    $res3 = $db->getAll($r, array('zi_comment'));
    foreach ($res3 as $row3) {
        $doc3 = new Zend_Search_Lucene_Document();
        // Add some information
        $doc3->addField(Zend_Search_Lucene_Field::Keyword('pk', $row3['id']));
        $doc3->addField(Zend_Search_Lucene_Field::UnIndexed('document_id', $row3['receiverid']));
        $doc3->addField(Zend_Search_Lucene_Field::UnStored('document_message', $row3['message']), 'utf-8');
        $doc3->addField(Zend_Search_Lucene_Field::UnStored('document_tr_message', $row3['tr_message']), 'utf-8');
        $index3->addDocument($doc3);
    }
    $index3->commit();
    /*$queryStr= "use";
    	$query = Zend_Search_Lucene_Search_QueryParser::parse($queryStr);
    	$index = Zend_Search_Lucene::open(FULL_PATH.'Zend/app/tmp/cache/index3');
    	$results = $index->find($query);
    	//print_r($results);
    	$count = 0;
    	foreach ($results as $result)
    	{
    		$data[$count]["userid"] = $result->document_id;
    		$count++;
    	}
    	print_R($data);exit;*/
    $count = 0;
    foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) {
        $count++;
    }
    return $count;
}
開發者ID:mickdane,項目名稱:zidisha,代碼行數:76,代碼來源:indexer.php

示例13: RefreshSearchIndex

 /**
  * This will refresh the search index for this topic (for all message content under this topic)
  * @param Zend_Search_Lucene $objIndex should be null if we are updating just one -- but for bulk index updates, you can pass in an already loaded index file
  * @return void
  */
 public function RefreshSearchIndex($objIndex = null)
 {
     // Currently only implemented for Forum-based topic/message searches
     if ($this->TopicLink->TopicLinkTypeId != TopicLinkType::Forum) {
         return;
     }
     if (!$objIndex) {
         $objIndex = new Zend_Search_Lucene(__SEARCH_INDEXES__ . '/topics');
         $blnIndexProvided = false;
     } else {
         $blnIndexProvided = true;
     }
     // Retrievew the Index Documents (if applicable) to delete them from the index
     $objSearchTerm = new Zend_Search_Lucene_Index_Term($this->Id, 'db_id');
     foreach ($objIndex->termDocs($objSearchTerm) as $intDocId) {
         $objIndex->delete($intDocId);
     }
     // Create the Message Contents for this Topic
     $strContents = null;
     foreach ($this->GetMessageArray(QQ::OrderBy(QQN::Message()->ReplyNumber)) as $objMessage) {
         $strMessage = strip_tags(trim($objMessage->CompiledHtml));
         $strMessage = html_entity_decode($strMessage, ENT_QUOTES, 'UTF-8');
         $strContents .= $strMessage . "\r\n\r\n";
     }
     // Create the Document
     $objDocument = new Zend_Search_Lucene_Document();
     $objDocument->addField(Zend_Search_Lucene_Field::Keyword('db_id', $this->Id));
     $objDocument->addField(Zend_Search_Lucene_Field::UnIndexed('topic_link_id', $this->TopicLinkId));
     $objDocument->addField(Zend_Search_Lucene_Field::UnIndexed('topic_link_type_id', $this->TopicLink->TopicLinkTypeId));
     $objDocument->addField(Zend_Search_Lucene_Field::UnIndexed('message_count', $this->MessageCount));
     $objDocument->addField(Zend_Search_Lucene_Field::UnIndexed('last_post_date', $this->LastPostDate->Timestamp));
     $objDocument->addField(Zend_Search_Lucene_Field::Text('title', $this->Name));
     $objDocument->addField(Zend_Search_Lucene_Field::UnStored('contents', trim($strContents)));
     // Add Document to Index
     $objIndex->addDocument($objDocument);
     // Only call commit on the index if it was provided for us
     if (!$blnIndexProvided) {
         $objIndex->commit();
     }
 }
開發者ID:qcodo,項目名稱:qcodo-website,代碼行數:45,代碼來源:Topic.class.php

示例14: addToIndex

 /**
  * addToIndex
  * @param string $strIndexPath
  * @param string $strKey
  * @author Thomas Schedler <tsh@massiveart.com>
  * @version 1.0
  */
 protected final function addToIndex($strIndexPath, $strKey)
 {
     try {
         if (!is_object($this->objIndex) || !$this->objIndex instanceof Zend_Search_Lucene) {
             if (count(scandir($strIndexPath)) > 2) {
                 $this->objIndex = Zend_Search_Lucene::open($strIndexPath);
             } else {
                 $this->objIndex = Zend_Search_Lucene::create($strIndexPath);
             }
         }
         $objDoc = new Zend_Search_Lucene_Document();
         $objDoc->addField(Zend_Search_Lucene_Field::keyword('key', $strKey));
         $objDoc->addField(Zend_Search_Lucene_Field::unIndexed('date', $this->setup->getPublishDate('d.m.Y')));
         $objDoc->addField(Zend_Search_Lucene_Field::unIndexed('rootLevelId', $this->setup->getRootLevelId()));
         /**
          * index fields
          */
         foreach ($this->setup->FieldNames() as $strField => $intFieldType) {
             $objField = $this->setup->getField($strField);
             if (is_object($objField) && $objField->idSearchFieldTypes != Search::FIELD_TYPE_NONE) {
                 $strValue = '';
                 if (is_array($objField->getValue()) && $objField->sqlSelect != '') {
                     $arrIds = $objField->getValue();
                     $sqlSelect = $objField->sqlSelect;
                     if (is_array($arrIds)) {
                         if (count($arrIds) > 0) {
                             $strReplaceWhere = '';
                             foreach ($arrIds as $strId) {
                                 $strReplaceWhere .= $strId . ',';
                             }
                             $strReplaceWhere = trim($strReplaceWhere, ',');
                             $objReplacer = new Replacer();
                             $sqlSelect = $objReplacer->sqlReplacer($sqlSelect, $this->setup->getLanguageId(), $this->setup->getRootLevelId(), ' AND tbl.id IN (' . $strReplaceWhere . ')');
                             $objCategoriesData = $this->core->dbh->query($sqlSelect)->fetchAll(Zend_Db::FETCH_OBJ);
                             if (count($objCategoriesData) > 0) {
                                 foreach ($objCategoriesData as $objCategories) {
                                     $strValue .= $objCategories->title . ', ';
                                 }
                                 $strValue = rtrim($strValue, ', ');
                             }
                         }
                     }
                 } else {
                     $strValue = $objField->getValue();
                 }
                 if ($strValue != '') {
                     switch ($objField->idSearchFieldTypes) {
                         case Search::FIELD_TYPE_KEYWORD:
                             $objDoc->addField(Zend_Search_Lucene_Field::keyword($strField, $strValue, $this->core->sysConfig->encoding->default));
                             break;
                         case Search::FIELD_TYPE_UNINDEXED:
                             $objDoc->addField(Zend_Search_Lucene_Field::unIndexed($strField, $strValue, $this->core->sysConfig->encoding->default));
                             break;
                         case Search::FIELD_TYPE_BINARY:
                             $objDoc->addField(Zend_Search_Lucene_Field::binary($strField, $strValue, $this->core->sysConfig->encoding->default));
                             break;
                         case Search::FIELD_TYPE_TEXT:
                             $objDoc->addField(Zend_Search_Lucene_Field::text($strField, $strValue, $this->core->sysConfig->encoding->default));
                             break;
                         case Search::FIELD_TYPE_UNSTORED:
                             $objDoc->addField(Zend_Search_Lucene_Field::unStored($strField, strip_tags($strValue), $this->core->sysConfig->encoding->default));
                             break;
                     }
                 }
             }
         }
         // Add document to the index.
         $this->objIndex->addDocument($objDoc);
         $this->objIndex->optimize();
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
     }
 }
開發者ID:BGCX261,項目名稱:zoolu-svn-to-git,代碼行數:80,代碼來源:generic.data.type.abstract.class.php

示例15: actionCreate

 /**
  * Search index creation
  */
 public function actionCreate()
 {
     /**
      * Если это не AJAX-запрос - посылаем:
      **/
     if (!Yii::app()->getRequest()->getIsPostRequest() && !Yii::app()->getRequest()->getIsAjaxRequest()) {
         throw new CHttpException(404, Yii::t('ZendSearchModule.zendsearch', 'Page was not found!'));
     }
     try {
         // Папка для хранения индекса поиска
         $indexFiles = Yii::app()->getModule('zendsearch')->indexFiles;
         // Модели, включенные в индекс
         $searchModels = Yii::app()->getModule('zendsearch')->searchModels;
         // Лимит количества символов к описанию превью найденной страницы
         $limit = 600;
         SetLocale(LC_ALL, 'ru_RU.UTF-8');
         $analyzer = new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive();
         Zend_Search_Lucene_Analysis_Analyzer::setDefault($analyzer);
         $index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $indexFiles), true);
         $messages = [];
         if (extension_loaded('iconv') === true) {
             // Пробежаться по всем моделям и добавить их в индекс
             foreach ($searchModels as $modelName => $model) {
                 if (!empty($model['path'])) {
                     Yii::import($model['path']);
                 }
                 if (!isset($model['module'])) {
                     $messages[] = Yii::t('ZendSearchModule.zendsearch', 'Update config file or module, Module index not found for model "{model}"!', ['{model}' => $modelName]);
                 } elseif (is_file(Yii::getPathOfAlias($model['path']) . '.php') && Yii::app()->hasModule($model['module'])) {
                     $criteria = isset($model['criteria']) ? $model['criteria'] : [];
                     $searchNodes = $modelName::model()->findAll(new CDbCriteria($criteria));
                     foreach ($searchNodes as $node) {
                         $doc = new Zend_Search_Lucene_Document();
                         $doc->addField(Zend_Search_Lucene_Field::Text('title', CHtml::encode($node->{$model}['titleColumn']), 'UTF-8'));
                         $link = str_replace('{' . $model['linkColumn'] . '}', $node->{$model}['linkColumn'], $model['linkPattern']);
                         $doc->addField(Zend_Search_Lucene_Field::Text('link', $link, 'UTF-8'));
                         $contentColumns = explode(',', $model['textColumns']);
                         $i = 0;
                         foreach ($contentColumns as $column) {
                             $content = $this->cleanContent($node->{$column});
                             if ($i == 0) {
                                 $doc->addField(Zend_Search_Lucene_Field::Text('content', $content, 'UTF-8'));
                                 $description = $this->cleanContent($this->previewContent($node->{$column}, $limit));
                                 $doc->addField(Zend_Search_Lucene_Field::Text('description', $description, 'UTF-8'));
                             } else {
                                 $doc->addField(Zend_Search_Lucene_Field::Text('content' . $i, $content, 'UTF-8'));
                             }
                             $i++;
                         }
                         $index->addDocument($doc);
                     }
                     $index->optimize();
                     $index->commit();
                 } else {
                     $messages[] = Yii::t('ZendSearchModule.zendsearch', 'Module "{module}" not installed!', ['{module}' => $model['module']]);
                 }
             }
         } else {
             $messages[] = Yii::t('ZendSearchModule.zendsearch', 'This module require "Iconv" extension!');
         }
         Yii::app()->ajax->raw(empty($messages) ? Yii::t('ZendSearchModule.zendsearch', 'Index updated successfully!') : Yii::t('ZendSearchModule.zendsearch', 'There is an error!') . ': ' . implode("\n", $messages));
     } catch (Exception $e) {
         Yii::app()->ajax->raw(Yii::t('ZendSearchModule.zendsearch', 'There is an error!') . ":\n" . $e->getMessage());
     }
 }
開發者ID:yupe,項目名稱:yupe,代碼行數:68,代碼來源:ManageBackendController.php


注:本文中的Zend_Search_Lucene::addDocument方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。