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; }
/** * 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(); }
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 />'; }
$results = $index->find($term); $query = Zend_Search_Lucene_Search_QueryParser::parse($term); $this->render('/sParameter/search', compact('results', 'term', 'query')); } } /** * Search index creation */ public function actionCreate() { $index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles), true); $posts = tAccount::model()->findAll(); foreach ($posts as $post) { $doc = new Zend_Search_Lucene_Document(); $doc->addField(Zend_Search_Lucene_Field::Text('account_no', CHtml::encode($post->account_no), 'utf-8'));
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 :-| } }
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(); }
/** * removeFromIndex * @param string $strIndexPath * @param string $strKey * @author Thomas Schedler <*****@*****.**> * @version 1.0 */ protected final function removeFromIndex($strIndexPath, $strKey) { try { if (count(scandir($strIndexPath)) > 2) { $this->objIndex = Zend_Search_Lucene::open($strIndexPath); $objTerm = new Zend_Search_Lucene_Index_Term($strKey, 'key'); $objQuery = new Zend_Search_Lucene_Search_Query_Term($objTerm); $objHits = $this->objIndex->find($objQuery); foreach ($objHits as $objHit) { $this->objIndex->delete($objHit->id); } $this->objIndex->commit(); $this->objIndex->optimize(); } } catch (Exception $exc) { $this->core->logger->err($exc); } }
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'; }
/** * removeFromIndex * @param string $strIndexPath * @param string $strKey * @author Thomas Schedler <*****@*****.**> * @version 1.0 */ protected final function removeFromIndex($strIndexPath, $strKey) { try { $this->core->logger->debug('massiveart->generic->data->types->GenericDataTypeAbstract->removeFromIndex(' . $strIndexPath . ', ' . $strKey . ')'); if (count(scandir($strIndexPath)) > 2) { $this->objIndex = Zend_Search_Lucene::open($strIndexPath); $objTerm = new Zend_Search_Lucene_Index_Term($strKey, 'key'); $objQuery = strpos($strKey, '*') !== false ? new Zend_Search_Lucene_Search_Query_Wildcard($objTerm) : new Zend_Search_Lucene_Search_Query_Term($objTerm); $objHits = $this->objIndex->find($objQuery); foreach ($objHits as $objHit) { $this->objIndex->delete($objHit->id); } $this->objIndex->commit(); $this->objIndex->optimize(); } } catch (Exception $exc) { $this->core->logger->err($exc); } }
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(); }
/** * 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(); $now = new CDbExpression("NOW()"); $criteria->compare('t.publish', 1); $criteria->compare('date(published_date) <', $now); $criteria->order = 'article_id DESC'; //$criteria->limit = 10; $model = Articles::model()->findAll($criteria); foreach ($model as $key => $item) { if ($item->media_id != 0) { $images = Yii::app()->request->baseUrl . '/public/article/' . $item->article_id . '/' . $item->cover->media; } else { $images = ''; } if (in_array($item->cat_id, array(2, 3, 5, 6, 7, 18))) { $url = Yii::app()->createUrl('article/news/site/view', array('id' => $item->article_id, 't' => Utility::getUrlTitle($item->title))); } else { if (in_array($item->cat_id, array(9))) { $url = Yii::app()->createUrl('article/site/view', array('id' => $item->article_id, 't' => Utility::getUrlTitle($item->title))); } else { if (in_array($item->cat_id, array(10, 15, 16))) { $url = Yii::app()->createUrl('article/archive/site/view', array('id' => $item->article_id, 't' => Utility::getUrlTitle($item->title))); } else { if (in_array($item->cat_id, array(23, 24, 25))) { $url = Yii::app()->createUrl('article/newspaper/site/view', array('id' => $item->article_id, 't' => Utility::getUrlTitle($item->title))); } else { if (in_array($item->cat_id, array(13, 14, 20, 21))) { $url = Yii::app()->createUrl('article/regulation/site/download', array('id' => $item->article_id, 't' => Utility::getUrlTitle($item->title))); } else { if (in_array($item->cat_id, array(19))) { $url = Yii::app()->createUrl('article/announcement/site/download', array('id' => $item->article_id, 't' => Utility::getUrlTitle($item->title))); } } } } } } $doc = new Zend_Search_Lucene_Document(); $doc->addField(Zend_Search_Lucene_Field::UnIndexed('id', CHtml::encode($item->article_id), 'utf-8')); $doc->addField(Zend_Search_Lucene_Field::Keyword('category', CHtml::encode(Phrase::trans($item->cat->name, 2)), '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 . $url), 'utf-8')); $doc->addField(Zend_Search_Lucene_Field::UnIndexed('date', CHtml::encode(Utility::dateFormat($item->published_date, true) . ' WIB'), 'utf-8')); $doc->addField(Zend_Search_Lucene_Field::UnIndexed('creation', CHtml::encode($item->user->displayname), 'utf-8')); $index->addDocument($doc); } echo 'Artkel Lucene index created'; $index->commit(); $this->redirect(Yii::app()->createUrl('video/search/indexing')); ob_end_flush(); }
public function actionDoIndex() { $document = Document::model()->findAll(); Yii::import('application.vendor.*'); require_once 'Zend/Search/Lucene.php'; $index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.index'), true); try { foreach ($document as $doc) { $indexDoc = new Zend_Search_Lucene_Document(); $indexDoc->addField(Zend_Search_Lucene_Field::text("title", CHtml::encode($doc->title), 'utf-8')); $indexDoc->addField(Zend_Search_Lucene_Field::text("content", CHtml::encode($doc->content), 'utf-8')); $indexDoc->addField(Zend_Search_Lucene_Field::text("author", CHtml::encode($doc->author), 'utf-8')); $indexDoc->addField(Zend_Search_Lucene_Field::unIndexed("id", CHtml::encode($doc->id), 'utf-8')); $indexDoc->addField(Zend_Search_Lucene_Field::keyword("url", CHtml::encode($doc->url), 'utf-8')); $index->addDocument($indexDoc); } $index->commit(); Yii::app()->user->setFlash('success', 'Indexing success!'); } catch (Exception $e) { Yii::app()->user->setFlash('error', 'Indexing fail, try again!'); } $this->redirect(array('document/admin')); }
/** * 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()); } }
function insert($val = array()) { $this->link(); $index = new Zend_Search_Lucene($this->dir); $analyzerObj = new search_instance_analyzer_cjk(); $analyzerObj->addPreFilter(new search_instance_analyzer_filter_goods()); $analyzerObj->addPreFilter(new search_instance_analyzer_filter_cjk()); $analyzerObj->addFilter(new search_instance_token_filter_lowercase()); Zend_Search_Lucene_Analysis_Analyzer::setDefault($analyzerObj); $doc = new Zend_Search_Lucene_Document(); $doc->addField(Zend_Search_Lucene_Field::Text('goods_id', $val['goods_id'])); if (isset($val['product'][0]['price']['price']['price'])) { $pric = $val['product'][0]['price']['price']['price']; } else { if (is_array($val['product'])) { foreach ($val['product'] as $kp => $vp) { $pric = $vp['price']['price']['price']; } } } $doc->addField(Zend_Search_Lucene_Field::UnStored('cat_id', $val['category']['cat_id'])); $doc->addField(Zend_Search_Lucene_Field::UnStored('brand_id', $val['brand']['brand_id'])); $doc->addField(Zend_Search_Lucene_Field::UnStored('price', $this->priceChange($pric))); $doc->addField(Zend_Search_Lucene_Field::UnStored('marketable', 'true')); if (isset($val['props'])) { for ($i = 1; $i <= 28; $i++) { $p = 'p_' . $i; $doc->addField(Zend_Search_Lucene_Field::UnStored($p, $val['props'][$p]['value'])); } } if (is_array($val['keywords'])) { foreach ($val['keywords'] as $k => $v) { $keyword .= '#' . $v['keyword'] . '@'; } } if (is_array($val['product'])) { foreach ($val['product'] as $k => $v) { if (is_array($v['spec_desc']['spec_value_id'])) { foreach ($v['spec_desc']['spec_value_id'] as $key => $vals) { $spec .= '#' . $key . $vals . '@'; } } $bn .= '#' . $v['bn'] . '@'; } } //$name = '#'.$val['name'].'@'.$keyword.'#'.$val['bn'].'@'.$bn; $name = '#' . $val['name'] . '@'; $doc->addField(Zend_Search_Lucene_Field::UnStored('title', $name)); $doc->addField(Zend_Search_Lucene_Field::UnStored('keyword', $keyword)); $doc->addField(Zend_Search_Lucene_Field::UnStored('spec', $spec)); $doc->addField(Zend_Search_Lucene_Field::UnStored('bn', '#' . $val['bn'] . '@' . $bn)); $index->addDocument($doc); return $index->commit(); }
public static function saveSearchIndex() { $index = new Zend_Search_Lucene(sfConfig::get('sf_lib_dir') . '/modules/search/tmp/lucene.user.index', true); $doc = new Zend_Search_Lucene_Document(); $doc->addField(Zend_Search_Lucene_Field::Keyword('id', $this->pageDocument->getId())); $doc->addField(Zend_Search_Lucene_Field::Keyword('pageid', $this->pageDocument->getId())); $doc->addField(Zend_Search_Lucene_Field::Keyword('title', $this->pageDocument->getNavigationTitle())); $blobData = $this->pageDocument->getContent(); // $blockContents = $blobData->__toString(); $blockContents = $blobData; $doc->addField(Zend_Search_Lucene_Field::Unstored('contents', $blockContents . ' ' . $this->pageDocument->getNavigationTitle())); $index->addDocument($doc); $index->commit(); $hits = $index->find(strtolower('maquette')); foreach ($hits as $hit) { // echo $hit->score.'<br/>'; // echo $hit->id; // echo $hit->contents.'<br/>'; echo $hit->pageid; } }
/** * 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(); } }
//get the record, should only be one foreach ($doc as $thisdoc) { mtrace(" Delete: {$thisdoc->title} (database id = {$thisdoc->dbid}, index id = {$thisdoc->id}, moodle instance id = {$thisdoc->docid})"); $dbcontrol->delDocument($thisdoc); $index->delete($thisdoc->id); } //add new modified document back into index if (!($add = $get_document_function($update->id, $update->itemtype))) { // ignore on errors continue; } //object to insert into db $dbid = $dbcontrol->addDocument($add); //synchronise db with index $add->addField(Zend_Search_Lucene_Field::Keyword('dbid', $dbid)); mtrace(" Add: {$add->title} (database id = {$add->dbid}, moodle instance id = {$add->docid})"); $index->addDocument($add); } } else { mtrace("No types to update.\n"); } mtrace("Finished {$mod->name}.\n"); } } } } //commit changes $index->commit(); //update index date set_config("search_indexer_update_date", $startupdatedate); mtrace("Finished {$update_count} updates");
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; }