コード例 #1
0
 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 />';
 }
コード例 #2
0
ファイル: Product.class.php プロジェクト: vcgato29/poff
 public function updateLuceneIndex()
 {
     //delete existing entries
     $index = $this->getTable()->getLuceneIndex();
     // remove existing entries
     foreach ($index->find('pk:' . $this->getId()) as $hit) {
         $index->delete($hit->id);
     }
     // create new Lucene document
     $doc = new Zend_Search_Lucene_Document();
     // store product primary key to identify it in the search results
     $doc->addField(Zend_Search_Lucene_Field::Keyword('pk', $this->getId()));
     $tr = Doctrine::getTable('ProductTranslation')->createQuery()->from('ProductTranslation pt')->where('pt.id = ?', $this->getId())->execute();
     $doc->addField(Zend_Search_Lucene_Field::UnStored('original_title', $this->getOriginalTitle(), 'utf-8'));
     // add fields to index depending on existing Translations
     foreach ($tr->toArray() as $transArr) {
         $lang = $transArr['lang'];
         unset($transArr['lang'], $transArr['id'], $transArr['volume'], $transArr['slug']);
         foreach ($transArr as $field => $value) {
             $fieldName = $field . '_' . $lang;
             // (name_en, name_fi),  (description_en, description_fi)
             $doc->addField(Zend_Search_Lucene_Field::UnStored($fieldName, strip_tags($value), 'utf-8'));
         }
     }
     // add product to the index
     $index->addDocument($doc);
     $index->commit();
 }
コード例 #3
0
 public function updateAction()
 {
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
     // Создание индекса
     $index = Zend_Search_Lucene::create(APPLICATION_ROOT . '/data/my-index');
     $mediaMapper = new Media_Model_Mapper_Media();
     $select = $mediaMapper->getDbTable()->select();
     $select->where('deleted != ?', 1)->where('active != ?', 0)->where('category_id IN(?)', array(2, 3, 4))->order('timestamp DESC');
     $mediaItems = $mediaMapper->fetchAll($select);
     if (!empty($mediaItems)) {
         foreach ($mediaItems as $mediaItem) {
             $doc = new Zend_Search_Lucene_Document();
             // Сохранение Name документа для того, чтобы идентифицировать его
             // в результатах поиска
             $doc->addField(Zend_Search_Lucene_Field::Text('title', strtolower($mediaItem->getName()), 'UTF-8'));
             // Сохранение URL документа для того, чтобы идентифицировать его
             // в результатах поиска
             $doc->addField(Zend_Search_Lucene_Field::Text('url', '/media/' . $mediaItem->getFullPath(), 'UTF-8'));
             // Сохранение Description документа для того, чтобы идентифицировать его
             // в результатах поиска
             // $doc->addField(Zend_Search_Lucene_Field::Text('description', strtolower($mediaItem->getSContent()),'UTF-8'));
             // Индексирование keyWords содержимого документа
             $doc->addField(Zend_Search_Lucene_Field::UnStored('keyword', strtolower($mediaItem->getMetaKeywords()), 'UTF-8'));
             // Индексирование содержимого документа
             $doc->addField(Zend_Search_Lucene_Field::UnStored('contents', strtolower($mediaItem->getContent()), 'UTF-8'));
             // Добавление документа в индекс
             $index->addDocument($doc);
         }
     }
 }
コード例 #4
0
 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;
 }
コード例 #5
0
ファイル: HSearch.php プロジェクト: skapl/design
 /**
  * Adds a new model to the search index
  *
  * @param ISearchable $obj
  * @throws CException
  */
 public function addModel($obj)
 {
     if (!$obj instanceof ISearchable) {
         throw new CException("Invalid Object given, must implement ISearchable");
     }
     // Get Primary Key
     $attributes = $obj->getSearchAttributes();
     $guid = $attributes['model'] . $attributes['pk'];
     $index = $this->getIndex();
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Text('guid', $guid));
     $doc->addField(Zend_Search_Lucene_Field::Text('belongsToType', $attributes['belongsToType']));
     $doc->addField(Zend_Search_Lucene_Field::Text('belongsToId', $attributes['belongsToId']));
     $doc->addField(Zend_Search_Lucene_Field::Text('belongsToGuid', $attributes['belongsToGuid']));
     $doc->addField(Zend_Search_Lucene_Field::Text('model', $attributes['model']));
     $doc->addField(Zend_Search_Lucene_Field::Text('pk', $attributes['pk']));
     $doc->addField(Zend_Search_Lucene_Field::Text('title', $attributes['title'], 'UTF-8'));
     $doc->addField(Zend_Search_Lucene_Field::Text('url', $attributes['url'], 'UTF-8'));
     // Remove all internal attributes
     unset($attributes['belongsToType']);
     unset($attributes['belongsToId']);
     unset($attributes['belongsToGuid']);
     unset($attributes['model']);
     unset($attributes['pk']);
     unset($attributes['title']);
     unset($attributes['url']);
     foreach ($attributes as $key => $val) {
         $doc->addField(Zend_Search_Lucene_Field::Text($key, $val, 'UTF-8'));
     }
     #print "\t ADD ".$guid." \n";
     $index->addDocument($doc);
     $index->commit();
 }
コード例 #6
0
 public function buildAction()
 {
     // create the index
     $index = Zend_Search_Lucene::create(APPLICATION_PATH . '/indexes');
     // fetch all of the current pages
     $mdlPage = new Model_Page();
     $currentPages = $mdlPage->fetchAll();
     if ($currentPages->count() > 0) {
         // create a new search document for each page
         foreach ($currentPages as $p) {
             $page = new CMS_Content_Item_Page($p->id);
             $doc = new Zend_Search_Lucene_Document();
             // you use an unindexed field for the id because you want the id to be
             // included in the search results but not searchable
             $doc->addField(Zend_Search_Lucene_Field::unIndexed('page_id', $page->id));
             // you use text fields here because you want the content to be searchable
             // and to be returned in search results
             $doc->addField(Zend_Search_Lucene_Field::text('page_name', $page->name));
             $doc->addField(Zend_Search_Lucene_Field::text('page_headline', $page->headline));
             $doc->addField(Zend_Search_Lucene_Field::text('page_description', $page->description));
             $doc->addField(Zend_Search_Lucene_Field::text('page_content', $page->content));
             // add the document to the index
             $index->addDocument($doc);
         }
     }
     // optimize the index
     $index->optimize();
     // pass the view data for reporting
     $this->view->indexSize = $index->numDocs();
 }
コード例 #7
0
ファイル: places.php プロジェクト: abdulnizam/zend-freniz
 public function buildplaces()
 {
     ini_set('memory_limit', '1000M');
     set_time_limit(0);
     $time = time();
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
     /**
      * Create index
      */
     $index = Zend_Search_Lucene::create($this->_indexPath);
     /**
      * Get all users
      */
     $sql = $this->_db->select()->from($this->_name, array('id', 'name', 'placepic'))->limit(7500);
     $result = $this->_db->fetchAssoc($sql);
     foreach ($result as $values) {
         $doc = new Zend_Search_Lucene_Document();
         $doc->addField(Zend_Search_Lucene_Field::keyword('placeid', $values['id']));
         $doc->addField(Zend_Search_Lucene_Field::text('placename', $values['name']));
         $doc->addField(Zend_Search_Lucene_Field::unStored('placepic', $values['placepic']));
         $index->addDocument($doc);
     }
     $index->commit();
     $elapsed = time() - $time;
     print_r($elapsed);
 }
コード例 #8
0
ファイル: Search.php プロジェクト: neolao/wiki
 /**
  * Index a file
  *
  * @param   string  $filePath   The file path
  */
 public function index($filePath)
 {
     $content = file_get_contents($filePath);
     $modificationTime = filemtime($filePath);
     $checksum = md5($content);
     // Get the document
     $hits = $this->_data->find('path:' . $filePath);
     if (count($hits) > 0) {
         $hit = $hits[0];
         $document = $hit->getDocument();
         // If the checksums are the same, no need to update
         if ($checksum === $document->checksum) {
             return;
         }
         // Delete the document
         $this->_data->delete($hit);
     }
     // Create a new document
     $document = new Zend_Search_Lucene_Document();
     $document->addField(Zend_Search_Lucene_Field::keyword('path', $filePath));
     $document->addField(Zend_Search_Lucene_Field::keyword('modificationTime', $modificationTime));
     $document->addField(Zend_Search_Lucene_Field::keyword('checksum', $checksum));
     $document->addField(Zend_Search_Lucene_Field::unStored('content', $content, 'utf-8'));
     $this->_data->addDocument($document);
     // Commit the changes
     $this->_data->commit();
     $this->_data->optimize();
 }
コード例 #9
0
ファイル: Tools.php プロジェクト: PavloKovalov/seotoaster
 public static function addPageToIndex($page, $toasterSearchIndex = false)
 {
     if (!self::initIndex()) {
         return false;
     }
     if ($page instanceof Application_Model_Models_Page) {
         $page = $page->toArray();
         $containers = Application_Model_Mappers_ContainerMapper::getInstance()->findByPageId($page['id']);
         $page['content'] = '';
         if (!empty($containers)) {
             foreach ($containers as $container) {
                 $page['content'] .= $container->getContent();
             }
         }
     }
     $document = new Zend_Search_Lucene_Document();
     $document->addField(Zend_Search_Lucene_Field::keyword('pageId', $page['id']));
     $document->addField(Zend_Search_Lucene_Field::unStored('metaKeyWords', $page['metaKeywords'], 'UTF-8'));
     $document->addField(Zend_Search_Lucene_Field::unStored('metaDescription', $page['metaDescription'], 'UTF-8'));
     $document->addField(Zend_Search_Lucene_Field::unStored('headerTitle', $page['headerTitle'], 'UTF-8'));
     $document->addField(Zend_Search_Lucene_Field::unStored('content', $page['content'], 'UTF-8'));
     $document->addField(Zend_Search_Lucene_Field::text('draft', $page['draft'], 'UTF-8'));
     $document->addField(Zend_Search_Lucene_Field::text('teaserText', $page['teaserText'], 'UTF-8'));
     $document->addField(Zend_Search_Lucene_Field::text('url', $page['url'], 'UTF-8'));
     $document->addField(Zend_Search_Lucene_Field::text('navName', $page['navName'], 'UTF-8'));
     $document->addField(Zend_Search_Lucene_Field::text('h1', $page['h1'], 'UTF-8'));
     //		$document->addField(Zend_Search_Lucene_Field::text('previewImage', $page['previewImage']));
     self::$_index->addDocument($document);
 }
コード例 #10
0
ファイル: ImageController.php プロジェクト: riteshsahu1981/we
 public function luceneIndexAction()
 {
     $this->view->layout()->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $path = PUBLIC_PATH . '/tmp/lucene';
     try {
         $index = Zend_Search_Lucene::open($path);
     } catch (Zend_Search_Lucene_Exception $e) {
         try {
             $index = Zend_Search_Lucene::create($path);
         } catch (Zend_Search_Lucene_Exception $e) {
             echo "Unable to open or create index : {$e->getMessage()}";
         }
     }
     for ($i = 0; $i < $index->maxDoc(); $i++) {
         $index->delete($i);
     }
     $users = new Application_Model_User();
     $users = $users->fetchAll();
     foreach ($users as $_user) {
         Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
         $doc = new Zend_Search_Lucene_Document();
         $doc->addField(Zend_Search_Lucene_Field::Text('title', $_user->getFirstName()));
         $doc->addField(Zend_Search_Lucene_Field::keyword('empcode', $_user->getEmployeeCode()));
         $index->addDocument($doc);
         $index->commit();
         $index->optimize();
     }
 }
コード例 #11
0
ファイル: Page.php プロジェクト: laiello/digitalus-cms
 public function asLuceneDocument()
 {
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Text('page_title', $this->title, $this->_charset));
     $doc->addField(Zend_Search_Lucene_Field::Text('page_link', $this->path, $this->_charset));
     $doc->addField(Zend_Search_Lucene_Field::Text('page_teaser', $this->teaser, $this->_charset));
     $doc->addField(Zend_Search_Lucene_Field::unstored('page_content', $this->content, $this->_charset));
     $doc->addField(Zend_Search_Lucene_Field::UnStored('search_tags', $this->searchTags, $this->_charset));
     return $doc;
 }
コード例 #12
0
ファイル: lucene.php プロジェクト: simonescu/mashupkeyword
 public function insertFromDB($since)
 {
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Keyword('id', $row['id']));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('person', $row['person']));
     $doc->addField(Zend_Search_Lucene_Field::Text('celeb_type', $row['celeb_type']));
     $doc->addField(Zend_Search_Lucene_Field::Text('wikikeyword', $row['wikikeyword']));
     $doc->addField(Zend_Search_Lucene_Field::Text('blurb', $row['blurb']));
     $this->search->addDocument($doc);
 }
コード例 #13
0
ファイル: LuceneIndex.php プロジェクト: nhochong/qlkh-sgu
 public static function update($data)
 {
     try {
         //Update an index.
         $index = Zend_Search_Lucene::open('../application/searchindex');
         Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
     } catch (Zend_Search_Exception $e) {
         throw $e;
     }
     // remove an existing entry
     $hits = $index->find('pk:' . $data['pk']);
     foreach ($hits as $hit) {
         $index->delete($hit->id);
     }
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Keyword('pk', $data['pk']));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('code', $data['code'], 'UTF-8'));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('u_code', strtolower($data['code']), 'UTF-8'));
     $doc->addField(Zend_Search_Lucene_Field::unIndexed('type', $data['type'], 'UTF-8'));
     $doc->addField(Zend_Search_Lucene_Field::unIndexed('id', $data['id'], 'UTF-8'));
     $doc->addField(Zend_Search_Lucene_Field::Text('title', $data['title'], 'UTF-8'));
     $doc->addField(Zend_Search_Lucene_Field::Text('en_title', Default_Model_Functions::convert_vi_to_en($data['title']), 'UTF-8'));
     $doc->addField(Zend_Search_Lucene_Field::Text('description', $data['description'], 'UTF-8'));
     $doc->addField(Zend_Search_Lucene_Field::Text('en_description', Default_Model_Functions::convert_vi_to_en($data['description']), 'UTF-8'));
     $index->addDocument($doc);
     $index->commit();
 }
コード例 #14
0
ファイル: ItemIndex.php プロジェクト: josephholsten/swaplady
 private static function _insert($index, $item, $tags)
 {
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Text('title', $item->name));
     $doc->addField(Zend_Search_Lucene_Field::Text('item_id', strval($item->id)));
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('image_id', strval($item->image_id)));
     $doc->addField(Zend_Search_Lucene_Field::Text('description', $item->description));
     $doc->addField(Zend_Search_Lucene_Field::Text('tag', $tags));
     $index->addDocument($doc);
     $index->commit();
 }
コード例 #15
0
ファイル: search.php プロジェクト: sdoney/cookbook
 /**
  * rebuild the index
  *
  * @access public
  * @return void
  */
 function build_index()
 {
     $index = $this->__open(true);
     $index->setMergeFactor(2000);
     $index->setMaxBufferedDocs(500);
     $start = time();
     foreach ($this->settings as $model => $model_options) {
         App::import('Model', $model);
         $model = new $model();
         if (empty($model_options['find_options'])) {
             $model_options['find_options'] = array();
         }
         if (method_exists($model, 'find_index')) {
             $results = $model->find_index('all', $model_options['find_options']);
         } else {
             $results = $model->find('all', $model_options['find_options']);
         }
         if (Configure::read()) {
             $this->log($model->name . ' find time: ' . (time() - $start), 'searchable');
             $start = time();
         }
         $count = count($results);
         $i = 1;
         foreach ($results as $result) {
             printf("%.1f", $i / $count * 100);
             $this->out("");
             $i++;
             $this->out('Processing ' . $model->name . ' #' . $result[$model->name]['id']);
             $doc = new Zend_Search_Lucene_Document();
             // add the model field
             $doc->addField(Zend_Search_Lucene_Field::Keyword('cake_model', $model->name, 'utf-8'));
             foreach ($model_options['fields'] as $field_name => $options) {
                 if (!empty($options['prepare']) && function_exists($options['prepare'])) {
                     $result[$model->name][$field_name] = call_user_func($options['prepare'], $result[$model->name][$field_name]);
                 }
                 $alias = !empty($options['alias']) ? $options['alias'] : $field_name;
                 $doc->addField(Zend_Search_Lucene_Field::$options['type']($alias, $result[$model->name][$field_name], 'utf-8'));
             }
             $index->addDocument($doc);
             $this->out('Processed ' . $model->name . ' #' . $result[$model->name]['id']);
         }
         if (Configure::read()) {
             $this->log($model->name . ' adding time: ' . (time() - $start), 'searchable');
             $start = time();
         }
     }
     $this->optimize($index);
     $index->commit();
     if (Configure::read()) {
         $this->log('Optimize+commit time: ' . (time() - $start));
     }
 }
コード例 #16
0
ファイル: search_test.php プロジェクト: Tony133/zf-web
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 :-|
    }
}
コード例 #17
0
function index_lucene($article, $optimise)
{
    $index = getIndex_lucene();
    $term = new Zend_Search_Lucene_Index_Term($article["PMID"], 'PMID');
    // a pre-existing page cannot be updated, it has to be
    // deleted, and indexed again:
    $exactSearchQuery = new Zend_Search_Lucene_Search_Query_Term($term);
    $hits = $index->find($exactSearchQuery);
    if (count($hits) > 0) {
        echo "[deleting previous version]\n";
        foreach ($hits as $hit) {
            $index->delete($hit->id);
        }
    }
    $doc = new Zend_Search_Lucene_Document();
    $doc->addField(Zend_Search_Lucene_Field::Keyword('PMID', $article["PMID"]));
    $doc->addField(Zend_Search_Lucene_Field::Keyword('Year', $article["Year"]));
    $doc->addField(Zend_Search_Lucene_Field::Keyword('Journal', $article["Journal"]));
    $doc->addField(Zend_Search_Lucene_Field::Text('Title', $article["Title"], 'utf-8'));
    $doc->addField(Zend_Search_Lucene_Field::Text('Authors', $article["Authors"], 'utf-8'));
    $doc->addField(Zend_Search_Lucene_Field::Text('Reference', $article["Reference"], 'utf-8'));
    $doc->addField(Zend_Search_Lucene_Field::UnStored('Abstract', $article["Abstract"], 'utf-8'));
    $doc->addField(Zend_Search_Lucene_Field::Text('MeshHeadings', $article["MeshHeadings"], 'utf-8'));
    $index->addDocument($doc);
    if ($optimise) {
        echo "Optimising index\n";
        $index->optimize();
    }
    $index->commit();
    echo "The index contains " . $index->numDocs() . " documents\n";
}
コード例 #18
0
         $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'));
コード例 #19
0
ファイル: LuceneIndexer.php プロジェクト: padraic/ZFPlanet
 public function index(Zfplanet_Model_Entry $entry)
 {
     if (is_null($this->_index)) {
         return;
     }
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Keyword('id', $entry->id, 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('publishedDate', $entry->publishedDate, 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('uri', $entry->uri, 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::Text('title', $entry->title, 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::UnStored('content', $entry->content, 'utf-8'));
     $this->_index->addDocument($doc);
     $this->_index->commit();
     $this->_index->optimize();
 }
コード例 #20
0
ファイル: articulo.class.php プロジェクト: recchia/solmed
 public function updateLuceneIndex()
 {
     $index = articuloTable::getLuceneIndex();
     $hit = $index->find('pk:' . $this->getId());
     if ($hit) {
         $index->delete($hit->id);
     }
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::unIndexed('pk', $this->getId()));
     $doc->addField(Zend_Search_Lucene_Field::unStored('marca', $this->getMarca(), 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::unStored('categoria', $this->getCategoria(), 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::unStored('descripcion', $this->getDescripcion(), 'utf-8'));
     $index->addDocument($doc);
     $index->commit();
 }
コード例 #21
0
ファイル: LuceneTest.php プロジェクト: JellyBellyDev/zle
 /**
  * This method is called before the first test of this test class is run.
  *
  * Build a temporary index with a couple of documents
  */
 public static function setUpBeforeClass()
 {
     // ensure no index exist
     system(sprintf("rm -rf %s", self::indexDir()));
     // create the index
     $index = Zend_Search_Lucene::create(self::indexDir());
     // add some documents
     for ($i = 0; $i < 3; $i++) {
         $document = new Zend_Search_Lucene_Document();
         $document->addField(Zend_Search_Lucene_Field::text('title', "foo bar baz {$i}"));
         $document->addField(Zend_Search_Lucene_Field::text('content', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc pharetra laoreet sodales. Aenean consequat ornare aliquam. Etiam vestibulum ultrices elit nec vestibulum'));
         $index->addDocument($document);
     }
     $index->commit();
 }
コード例 #22
0
ファイル: DocumentTest.php プロジェクト: lortnus/zf1
 public function testAddFieldMethodChaining()
 {
     $document = new Zend_Search_Lucene_Document();
     $this->assertTrue($document->addField(Zend_Search_Lucene_Field::Text('title', 'Title')) instanceof Zend_Search_Lucene_Document);
     $document = new Zend_Search_Lucene_Document();
     $document->addField(Zend_Search_Lucene_Field::Text('title', 'Title'))->addField(Zend_Search_Lucene_Field::Text('annotation', 'Annotation'))->addField(Zend_Search_Lucene_Field::Text('body', 'Document body, document body, document body...'));
 }
コード例 #23
0
ファイル: Search.php プロジェクト: ntulip/joobsbox-php
 public function addJob($jobData)
 {
     if (!$this->_enabled) {
         return false;
     }
     // Delete old job with the same id from index
     $term = new Zend_Search_Lucene_Index_Term($jobData['id'], 'id');
     $hits = $this->_index->termDocs($term);
     if (count($hits)) {
         foreach ($hits as $hit) {
             $this->_index->delete($hit->id);
         }
     }
     // Add the job now
     $job = new Zend_Search_Lucene_Document();
     $job->addField(Zend_Search_Lucene_Field::Keyword('DocumentType', 'job', 'utf-8'));
     $job->addField(Zend_Search_Lucene_Field::Keyword('id', $jobData['id'], 'utf-8'));
     $job->addField(Zend_Search_Lucene_Field::Text('title', $jobData['title'], 'utf-8'));
     $job->addField(Zend_Search_Lucene_Field::Text('description', $jobData['description'], 'utf-8'));
     $job->addField(Zend_Search_Lucene_Field::Text('company', $jobData['company'], 'utf-8'));
     $job->addField(Zend_Search_Lucene_Field::Keyword('categoryid', $jobData['categoryid'], 'utf-8'));
     $job->addField(Zend_Search_Lucene_Field::Text('location', $jobData['location'], 'utf-8'));
     $this->_index->addDocument($job);
     $this->_index->commit();
 }
コード例 #24
0
 /**
  * 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();
 }
コード例 #25
0
ファイル: Asso.class.php プロジェクト: TheoJD/portail
 /**
  * Method to use the zend framework for search
  * update the index file used for search
  */
 public function updateLuceneIndex()
 {
     $index = AssoTable::getInstance()->getLuceneIndex();
     // remove existing entries
     foreach ($index->find('pk:' . $this->getId()) as $hit) {
         $index->delete($hit->id);
     }
     $doc = new Zend_Search_Lucene_Document();
     // store asso primary key to identify it in the search results
     $doc->addField(Zend_Search_Lucene_Field::Keyword('pk', $this->getId()));
     // index asso fields
     $doc->addField(Zend_Search_Lucene_Field::UnStored('name', $this->getName(), 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::UnStored('description', $this->getDescription(), 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::UnStored('login', $this->getLogin(), 'utf-8'));
     // add asso to the index
     $index->addDocument($doc);
     $index->commit();
 }
コード例 #26
0
ファイル: NewItem.class.php プロジェクト: vcgato29/poff
 public function updateLuceneIndex()
 {
     //delete existing entries
     $index = $this->getTable()->getLuceneIndex();
     // remove existing entries
     foreach ($index->find('pk:' . $this->getId()) as $hit) {
         $index->delete($hit->id);
     }
     // create new Lucene document
     $doc = new Zend_Search_Lucene_Document();
     // store product primary key to identify it in the search results
     $doc->addField(Zend_Search_Lucene_Field::Keyword('pk', $this->getId()));
     $doc->addField(Zend_Search_Lucene_Field::UnStored('description', $this->getDescription(), 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::UnStored('content', strip_tags($this->getContent()), 'utf-8'));
     // add product to the index
     $index->addDocument($doc);
     $index->commit();
 }
コード例 #27
0
 /**
  * Updates the index for an object
  *
  * @param Doctrine_Record $object
  */
 public function updateIndex(Doctrine_Record $object, $delete = false)
 {
     /* error checking */
     if (!array_key_exists('models', $this->config) || empty($this->config['models'])) {
         throw new Exception(sprintf('No models set in search.yml', $name));
     }
     if (!array_key_exists($model = get_class($object), $this->config['models'])) {
         throw new Exception(sprintf('Model "%s" not defined in "%s" index in your search.yml', $model, $this->name));
     }
     $id = $this->generateId($object->getId(), $model);
     $config = $this->config['models'][$model];
     //delete existing entries
     foreach ($this->search('_id:"' . $id . '"') as $hit) {
         $this->getIndex()->delete($hit->id);
     }
     if ($delete) {
         return;
     }
     //only add to search if canSearch method on model returns true (search if no method exists)
     if (method_exists($object, 'canSearch')) {
         if (!call_user_func(array($object, 'canSearch'))) {
             return;
         }
     }
     $doc = new Zend_Search_Lucene_Document();
     // store a key for deleting in future
     $doc->addField(Zend_Search_Lucene_Field::Keyword('_id', $id));
     // store job primary key and model name to identify it in the search results
     $doc->addField(Zend_Search_Lucene_Field::Keyword('_pk', $object->getId()));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('_model', $model));
     // store title - used for search result title
     if (!array_key_exists('title', $config)) {
         throw new Exception(sprintf('A title must be set for model "%s" in search.yml', $model));
     }
     $doc->addField(Zend_Search_Lucene_Field::unIndexed('_title', call_user_func(array($object, 'get' . sfInflector::camelize($config['title'])))));
     // store description - used for search result description
     if (!array_key_exists('description', $config)) {
         throw new Exception(sprintf('A description must be set for model "%s" in search.yml', $model));
     }
     $doc->addField(Zend_Search_Lucene_Field::unIndexed('_description', call_user_func(array($object, 'get' . sfInflector::camelize($config['description'])))));
     // store url - @todo add more routing options
     if (!array_key_exists('route', $config)) {
         throw new Exception(sprintf('A route must be set for model "%s" in search.yml', $model));
     }
     sfContext::getInstance()->getConfiguration()->loadHelpers('Url');
     $url = url_for($config['route'], $object);
     $doc->addField(Zend_Search_Lucene_Field::unIndexed('_url', $url));
     //store fields
     if (array_key_exists('fields', $config)) {
         foreach ($config['fields'] as $field => $config) {
             $doc->addField(Zend_Search_Lucene_Field::UnStored($field, call_user_func(array($object, 'get' . sfInflector::camelize($field))), 'utf-8'));
         }
     }
     //save index
     $this->getIndex()->addDocument($doc);
     $this->getIndex()->commit();
 }
コード例 #28
0
ファイル: track.class.php プロジェクト: hielh/abjihproject
 public function updateLuceneIndex()
 {
     $index = trackTable::getLuceneIndex();
     // remove existing entries
     foreach ($index->find('pk:' . $this->getId()) as $hit) {
         $index->delete($hit->id);
     }
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Keyword('pk', $this->getId()));
     $doc->addField(Zend_Search_Lucene_Field::text('track_name', $this->getName(), 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('track_url', $this->getUrl(), 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('play_it_user_id', $this->getSfGuardUser()->getId()));
     $doc->addField(Zend_Search_Lucene_Field::text('track_name', $this->getName(), 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::text('track_type', $this->getPlayList()->getObjectType(), 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::text('playlist_name', $this->getPlayList()->getTitle(), 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('play_owner_id', $this->getPlayList()->getPlayOwner()->getId()));
     $doc->addField(Zend_Search_Lucene_Field::text('play_owner_name', $this->getPlayList()->getPlayOwner()->getName(), 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::UnStored('play_owner_name_fr', $this->getPlayList()->getPlayOwner()->getNameFr(), 'utf-8'));
     $index->addDocument($doc);
     $index->commit();
 }
コード例 #29
0
 public function build_index()
 {
     echo "Anfang<br>";
     // Index erstellen, bisheriger Index wird gelöscht
     $index = Zend_Search_Lucene::create($this->search_index);
     $this->db->where('online', 1);
     $query = $this->db->get('v_einsatz');
     foreach ($query->result() as $row) {
         // neues Suchindex-Dokument erzeugen
         $doc = new Zend_Search_Lucene_Document();
         // Titel für die Anzeige in der Ergebnisliste
         $doc->addField(Zend_Search_Lucene_Field::Text('title', htmlentities($row->name)));
         // mit diesem Pfad wird das Suchergebnis verknüpft
         $doc->addField(Zend_Search_Lucene_Field::Text('path', base_url('aktuelles/einsatz/' . $row->einsatzID)));
         // dieser Inhalt wird neben dem Titel indexiert
         $doc->addField(Zend_Search_Lucene_Field::UnStored('content', htmlentities($row->lage . $row->bericht . $row->weitere_kraefte . $row->ort)));
         $doc->addField(Zend_Search_Lucene_Field::unIndexed('content_type', 'Einsatz'));
         // zum Index hinzufügen
         $index->addDocument($doc);
         echo 'Einsatz ' . $row->name . ' zum Index hinzugefügt.<br />';
     }
     $query = $this->db->get('v_news');
     foreach ($query->result() as $row) {
         // neues Suchindex-Dokument erzeugen
         $doc = new Zend_Search_Lucene_Document();
         // Titel für die Anzeige in der Ergebnisliste
         $doc->addField(Zend_Search_Lucene_Field::Text('title', htmlentities($row->title)));
         // mit diesem Pfad wird das Suchergebnis verknüpft
         $doc->addField(Zend_Search_Lucene_Field::Text('path', base_url('aktuelles/news/' . $row->newsID)));
         // dieser Inhalt wird neben dem Titel indexiert
         $doc->addField(Zend_Search_Lucene_Field::UnStored('content', htmlentities($row->teaser . $row->text)));
         $doc->addField(Zend_Search_Lucene_Field::unIndexed('content_type', 'News'));
         // zum Index hinzufügen
         $index->addDocument($doc);
         echo 'News ' . $row->title . ' zum Index hinzugefügt.<br />';
     }
     // Index optimieren
     $index->optimize();
     echo "Ende";
 }
コード例 #30
0
 public function updateSearchIndex(Doctrine_Record $record)
 {
     $index = $this->getIndex();
     // remove existing entries
     foreach ($index->find('pk:' . $this->_getRecordSearchPrimaryKey($record)) as $hit) {
         $index->delete($hit->id);
     }
     $doc = new Zend_Search_Lucene_Document();
     // store job primary key to identify it in the search results
     $doc->addField(Zend_Search_Lucene_Field::Keyword('pk', $this->_getRecordSearchPrimaryKey($record)));
     if (method_exists($record, 'getSearchData')) {
         $data = $record->getSearchData();
     } else {
         $data = $record->toArray(false);
     }
     foreach ($data as $key => $value) {
         $doc->addField(Zend_Search_Lucene_Field::UnStored($key, $value, 'utf-8'));
     }
     // add job to the index
     $index->addDocument($doc);
     $index->commit();
 }