コード例 #1
1
 public function add($needFields = array(), $data = array(), $charset = 'UTF-8')
 {
     $index = new Zend_Search_Lucene(ZY_ROOT . '/index', true);
     $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;
 }
コード例 #2
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();
     }
 }
コード例 #3
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);
 }
コード例 #4
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);
 }
コード例 #5
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();
 }
コード例 #6
0
 public function __construct(Storefront_Resource_Product_Item_Interface $item, $category)
 {
     $this->addField(Zend_Search_Lucene_Field::keyword('productId', $item->productId, 'UTF-8'));
     $this->addField(Zend_Search_Lucene_Field::text('categories', $category, 'UTF-8'));
     $this->addField(Zend_Search_Lucene_Field::text('name', $item->name, 'UTF-8'));
     $this->addField(Zend_Search_Lucene_Field::unStored('description', $item->description, 'UTF-8'));
     $this->addField(Zend_Search_Lucene_Field::text('price', $this->_formatPrice($item->getPrice()), 'UTF-8'));
 }
コード例 #7
0
ファイル: Search.php プロジェクト: akeemphilbert/ifphp
 public function addPost(Post $post, $feed)
 {
     $index = Zend_Search_Lucene::open(Zend_Registry::getInstance()->config->search->post);
     $feed = $post->findParentFeeds();
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Text('pid', $post->id));
     $doc->addField(Zend_Search_Lucene_Field::Text('title', $post->title));
     $doc->addField(Zend_Search_Lucene_Field::Text('siteUrl', $feed->siteUrl));
     $doc->addField(Zend_Search_Lucene_Field::Text('link', $post->link));
     $doc->addField(Zend_Search_Lucene_Field::Text('feedTitle', $feed->title));
     $doc->addField(Zend_Search_Lucene_Field::Text('feedSlug', $feed->slug));
     $doc->addField(Zend_Search_Lucene_Field::Text('feedDescription', $feed->description));
     $doc->addField(Zend_Search_Lucene_Field::keyword('category', $feed->findParentCategories()->title));
     $doc->addField(Zend_Search_Lucene_Field::Text('description', $post->description));
     $doc->addField(Zend_Search_Lucene_Field::unIndexed('publishDate', $post->publishDate));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('type', 'post'));
     $index->addDocument($doc);
 }
コード例 #8
0
 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';
 }
コード例 #9
0
ファイル: Document.php プロジェクト: joshauza/baseapp
 public function __construct($class, $key, $title, $contents, $summary, $createdBy, $dateCreated, $keywords = array())
 {
     $this->addField(Zend_Search_Lucene_Field::Keyword('docRef', "{$class}:{$key}"));
     $this->addField(Zend_Search_Lucene_Field::UnIndexed('class', $class));
     $this->addField(Zend_Search_Lucene_Field::UnIndexed('key', $key));
     $this->addField(Zend_Search_Lucene_Field::Text('title', $title));
     $this->addField(Zend_Search_Lucene_Field::UnStored('contents', $contents));
     $this->addField(Zend_Search_Lucene_Field::UnIndexed('summary', $summary));
     $this->addField(Zend_Search_Lucene_Field::Keyword('createdBy', $createdBy));
     $this->addField(Zend_Search_Lucene_Field::Keyword('dateCreated', $dateCreated));
     if (!is_array($keywords)) {
         $keywords = explode('', $keywords);
     }
     foreach ($keywords as $name => $value) {
         if (!empty($name) && !empty($value)) {
             $this->addField(Zend_Search_Lucene_Field::keyword($name, $value));
         }
     }
 }
コード例 #10
0
ファイル: IndexDb.php プロジェクト: uniqid/lucene
 /**
  * php index.php db index
  *
  */
 public function index()
 {
     $query = "SELECT * FROM Products AS p JOIN Categories AS c ON p.CategoryID = c.CategoryId JOIN Suppliers AS s ON p.SupplierID = s.SupplierID";
     $stmt = $this->db->prepare($query);
     $stmt->execute();
     $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $indexDir = APP_PATH . '/' . self::INDEX_DIR;
     is_dir($indexDir) || mkdir($indexDir, 0777, true);
     $index = self::create($indexDir);
     foreach ($rows as $row) {
         $doc = new Zend_Search_Lucene_Document();
         $doc->addField(Zend_Search_Lucene_Field::keyword('ProductName', $row['ProductName']));
         $doc->addField(Zend_Search_Lucene_Field::text('Quantity', $row['QuantityPerUnit']));
         $doc->addField(Zend_Search_Lucene_Field::keyword('Category', $row['CategoryName']));
         $doc->addField(Zend_Search_Lucene_Field::unIndexed('Description', $row['Description']));
         $doc->addField(Zend_Search_Lucene_Field::unStored('City', $row['City']));
         $doc->addField(Zend_Search_Lucene_Field::keyword('CompanyName', $row['CompanyName']));
         $doc->addField(Zend_Search_Lucene_Field::binary('Picture', $row['Picture']));
         $index->addDocument($doc);
     }
 }
コード例 #11
0
ファイル: Job.php プロジェクト: rikon/jobeet
 /**
  * @ORM\PostPersist
  */
 public function updateLuceneIndex()
 {
     $index = self::getLuceneIndex();
     //remove existing entries
     foreach ($index->find('pk:' . $this->getId()) as $hit) {
         $index->delete($hit->id);
     }
     if ($this->isExpired() || !$this->getIsActivated()) {
         return;
     }
     $doc = new \Zend_Search_Lucene_Document();
     $doc->addField(\Zend_Search_Lucene_Field::keyword('pk', $this->getId()));
     //index job fields
     $doc->addField(\Zend_Search_Lucene_Field::unStored('position', $this->getPosition(), 'utf-8'));
     $doc->addField(\Zend_Search_Lucene_Field::unStored('company', $this->getCompany(), 'utf-8'));
     $doc->addField(\Zend_Search_Lucene_Field::unStored('location', $this->getLocation(), 'utf-8'));
     $doc->addField(\Zend_Search_Lucene_Field::unStored('description', $this->getDescription(), 'utf-8'));
     $index->addDocument($doc);
     $index->commit();
 }
コード例 #12
0
ファイル: Abstract.php プロジェクト: Konstnantin/zf-app
 protected function addToIndex($data)
 {
     if (trim($this->z_indexate) == '') {
         return;
     }
     if (!isset($data['id'])) {
         return;
     }
     $fields = explode(';', trim($this->z_indexate));
     $searchIndex = Z_Search::getInstance();
     //создаем документ
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::keyword('_id', $data['id']));
     $doc->addField(Zend_Search_Lucene_Field::unIndexed('_type', $this->z_model->info('name')));
     foreach ($fields as $field) {
         if (isset($data[$field])) {
             $doc->addField(Zend_Search_Lucene_Field::text($field, $data[$field]));
         }
     }
     //удаляем старый документ
     $hits = $searchIndex->find('_id:' . $data['id']);
     foreach ($hits as $hit) {
         $searchIndex->delete($hit->id);
     }
     //добавляем документ
     $searchIndex->addDocument($doc);
 }
コード例 #13
0
ファイル: Search.php プロジェクト: boxfrommars/bankirtest
 /**
  * создаёет LuceneDoc из SearchDoc
  *
  * @param Application_Model_SearchDoc $searchDoc
  * @return Zend_Search_Lucene_Document
  */
 public function createLuceneDoc(Application_Model_SearchDoc $searchDoc)
 {
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Text('title', $searchDoc->title, 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::Text('content', $searchDoc->content, 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('type', $searchDoc->type, 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::keyword('docid', $searchDoc->id));
     return $doc;
 }
コード例 #14
0
ファイル: SearchProvider.php プロジェクト: aprondak/ifphp
 /**
  * Build the post search index
  * 
  * @param boolean $isCount
  * @return boolean
  */
 protected function buildPostSearch($isCount = false)
 {
     $index = Zend_Search_Lucene::create(Zend_Registry::getInstance()->config->search->post);
     require_once 'Ifphp/models/Posts.php';
     require_once 'Ifphp/models/Feeds.php';
     require_once 'Ifphp/models/Categories.php';
     $posts = new Posts();
     $allPosts = $posts->getRecent(1, 0);
     if ($isCount) {
         echo $allPosts->count() . ' posts would have been added to the post index';
         exit;
     }
     foreach ($allPosts as $post) {
         $feed = $post->findParentFeeds();
         $doc = new Zend_Search_Lucene_Document();
         $doc->addField(Zend_Search_Lucene_Field::Text('pid', $post->id));
         $doc->addField(Zend_Search_Lucene_Field::Text('title', $post->title));
         $doc->addField(Zend_Search_Lucene_Field::Text('siteUrl', $post->siteUrl));
         $doc->addField(Zend_Search_Lucene_Field::Text('link', $post->link));
         $doc->addField(Zend_Search_Lucene_Field::Text('feedTitle', $feed->title));
         $doc->addField(Zend_Search_Lucene_Field::Text('feedSlug', $feed->slug));
         $doc->addField(Zend_Search_Lucene_Field::Text('feedDescription', $feed->description));
         $doc->addField(Zend_Search_Lucene_Field::keyword('category', $feed->findParentCategories()->title));
         $doc->addField(Zend_Search_Lucene_Field::Text('description', $post->description));
         $doc->addField(Zend_Search_Lucene_Field::unIndexed('publishDate', $post->publishDate));
         $doc->addField(Zend_Search_Lucene_Field::Keyword('type', 'post'));
         $index->addDocument($doc);
     }
     chown(Zend_Registry::getInstance()->search['post'], 'www-data');
     return true;
 }
コード例 #15
0
ファイル: sfPakeIndexDocuments.php プロジェクト: kotow/work
function run_index_documents($task, $args)
{
    try {
        define('SF_ROOT_DIR', sfConfig::get('sf_root_dir'));
        define('SF_APP', 'backend');
        define('SF_ENVIRONMENT', 'prod');
        define('SF_DEBUG', false);
        require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
        ini_set("memory_limit", "2048M");
        ini_set("display_errors", 1);
        $databaseManager = new sfDatabaseManager();
        $databaseManager->initialize();
        $search_config_file = SF_ROOT_DIR . '/config/search.xml';
        $documents = simplexml_load_file($search_config_file);
        $all = 0;
        $search_index_path = SF_ROOT_DIR . '/cache/search/';
        if (is_dir($search_index_path)) {
            $index_files = glob($search_index_path . '/*');
            foreach ($index_files as $index_file) {
                if (is_file($index_file)) {
                    unlink($index_file);
                }
            }
        }
        $search_index = Zend_Search_Lucene::create($search_index_path);
        $search_index->setMaxBufferedDocs(20000);
        Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
        $ndoc = 0;
        foreach ($documents as $document) {
            $document_name = $document->attributes();
            if (array_key_exists(0, $args) && $document_name != $args[0]) {
                continue;
            }
            echo "Indexing " . $document_name . "\n";
            $classPeer = $document_name . 'Peer';
            $c = new Criteria();
            $document_instances = call_user_func(array($classPeer, 'doSelect'), $c);
            foreach ($document_instances as $document_instance) {
                $common_field_val = "";
                $id = $document_instance->getId();
                $search_doc = new Zend_Search_Lucene_Document();
                $date = $document_instance->getCreatedAt();
                $search_doc->addField(Zend_Search_Lucene_Field::UnIndexed('did', $id, 'utf-8'));
                $search_doc->addField(Zend_Search_Lucene_Field::UnIndexed('ddate', $date, 'utf-8'));
                $search_doc->addField(Zend_Search_Lucene_Field::UnIndexed('dtype', $document_name, 'utf-8'));
                $search_doc->addField(Zend_Search_Lucene_Field::UnIndexed('dstatus', $document_instance->getPublicationStatus(), 'utf-8'));
                foreach ($document as $field_name) {
                    $attr = get_object_vars($field_name);
                    $attributes = $attr['@attributes'];
                    $getFunction = 'get' . $attributes['name'];
                    $fieldContent = "";
                    $fieldContent = $document_instance->{$getFunction}();
                    if ($attributes['name'] == "Label" and substr($fieldContent, 0, 8) == "no label") {
                        $fieldContent = "";
                    }
                    if ($attributes['name'] == "ViennaClasses" || $attributes['name'] == "NiceClasses") {
                        $parts = explode(",", $fieldContent);
                        $nbr = count($parts);
                        //echo "============>".$nbr."\n";
                        $search_doc->addField(Zend_Search_Lucene_Field::UnIndexed($attributes['name'] . "_cnt", $nbr, 'utf-8'));
                        //$e = 1;
                        for ($e = 0; $e < 15; $e++) {
                            if (empty($parts[$e])) {
                                $parts[$e] = "---";
                            }
                            $search_doc->addField(Zend_Search_Lucene_Field::keyword($attributes['name'] . $e, trim($parts[$e]), 'utf-8'));
                            $e++;
                        }
                    } elseif ($attributes['name'] == "ApplicationNumber" || $attributes['name'] == "RegisterNumber") {
                        $search_doc->addField(Zend_Search_Lucene_Field::keyword($attributes['name'], $fieldContent, 'utf-8'));
                    } else {
                        $search_doc->addField(Zend_Search_Lucene_Field::text($attributes['name'], UtilsHelper::cyrillicConvert($fieldContent), 'utf-8'));
                    }
                }
                $search_index->addDocument($search_doc);
                $ndoc++;
                echo $ndoc . "\t\t\r";
            }
        }
        echo echo_cms_line(" " . $ndoc . " documents indexed\n");
        $search_index->commit();
        $search_index->optimize();
    } catch (Exception $e) {
        echo_cms_error("ERROR ADD_DOCUMENT : " . $e->getMessage());
    }
    echo echo_cms_sep();
    exit;
}
コード例 #16
0
 /**
  * addToIndex
  * @param string $strIndexPath
  * @param string $strKey
  * @author Thomas Schedler <*****@*****.**>
  * @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);
     }
 }
コード例 #17
0
 /**
  * indexFieldNow
  * @param GenericElementField $objField
  * @param string $strField
  * @param integer $intFieldType
  * @param string|array|object $mixedFieldValue
  * @param Zend_Search_Lucene_Document $objDoc
  * @return void
  * @author Thomas Schedler <*****@*****.**>
  */
 protected final function indexFieldNow($objField, $strField, $intFieldType, $mixedFieldValue, Zend_Search_Lucene_Document &$objDoc)
 {
     try {
         $strValue = '';
         $strValueIds = '';
         if ($objField->typeId == GenericSetup::FIELD_TYPE_ID_TAG) {
             $mixedValue = $mixedFieldValue;
             if (is_object($mixedValue) || is_array($mixedValue)) {
                 foreach ($mixedValue as $objTag) {
                     $strValue .= $objTag->title . ', ';
                     $strValueIds .= '[' . $objTag->id . ']';
                 }
                 $strValue = rtrim($strValue, ', ');
             }
         } elseif (!is_object($mixedFieldValue) && $objField->sqlSelect != '') {
             $sqlSelect = $objField->sqlSelect;
             $arrIds = array();
             if (is_array($mixedFieldValue)) {
                 $arrIds = $mixedFieldValue;
             } else {
                 if ($mixedFieldValue != '') {
                     if (strpos($mixedFieldValue, '[') !== false) {
                         $mixedFieldValue = trim($mixedFieldValue, '[]');
                         $arrIds = explode('][', $mixedFieldValue);
                     } else {
                         $arrIds = array($mixedFieldValue);
                     }
                 }
             }
             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 . ', ';
                             $strValueIds .= '[' . $objCategories->id . ']';
                         }
                         $strValue = rtrim($strValue, ', ');
                     }
                 }
             }
         } else {
             $strValue = html_entity_decode($mixedFieldValue, ENT_COMPAT, $this->core->sysConfig->encoding->default);
         }
         if (is_string($strValue) && $strValue != '') {
             if ($intFieldType == GenericSetup::FILE_FIELD) {
                 $objFiles = $this->getModelFiles()->loadFilesById($strValue);
                 $arrValues = array();
                 if (count($objFiles) > 0) {
                     foreach ($objFiles as $objFile) {
                         $arrValues[] = array('path' => $objFile->path, 'filename' => $objFile->filename, 'version' => $objFile->version);
                     }
                 }
                 $strValueIds = $strValue;
                 $strValue = serialize($arrValues);
             }
             if ($strValueIds != '') {
                 $objDoc->addField(Zend_Search_Lucene_Field::unIndexed($strField . 'Ids', $strValueIds, $this->core->sysConfig->encoding->default));
             }
             $this->core->logger->debug($strField . ': ' . $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;
             }
         }
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
     }
 }
コード例 #18
0
ファイル: Users.php プロジェクト: abdulnizam/zend-freniz
 private function insertPageDocument($user, $doc)
 {
     $doc->addField(Zend_Search_Lucene_Field::keyword('userid', $user['userid']));
     $doc->addField(Zend_Search_Lucene_Field::keyword('type', $user['type']));
     $doc->addField(Zend_Search_Lucene_Field::text('username', $user['username']));
     $doc->addField(Zend_Search_Lucene_Field::unIndexed('user_url', $user['user_url']));
     $doc->addField(Zend_Search_Lucene_Field::unIndexed('propic', $user['pagepic_url']));
     $doc->addField(Zend_Search_Lucene_Field::unIndexed('vote', $user['page_vote']));
     $doc->addField(Zend_Search_Lucene_Field::keyword('category', $user['category']));
     $doc->addField(Zend_Search_Lucene_Field::keyword('subcategory', $user['subcategory']));
     $doc->addField(Zend_Search_Lucene_Field::keyword('bids', $user['bids']));
     return $doc;
 }
コード例 #19
0
ファイル: forum.php プロジェクト: abdulnizam/zend-freniz
 public function buildforum()
 {
     ini_set('memory_limit', '1000M');
     set_time_limit(0);
     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('forum_questions', array('tags', 'question', 'id'));
     $result = $this->_db->fetchAssoc($sql);
     /**
      * Create a document for each user and add it to the index
      */
     /*foreach ($users as $user) {
     		 $doc = new Zend_Search_Lucene_Document();
     	
     		/**
     		* Fill document with data
     		*/
     /*  $doc->addField(Zend_Search_Lucene_Field::unIndexed('title', $user->id));
     		 $doc->addField(Zend_Search_Lucene_Field::text('contents', $user->name));
     		//$doc->addField(Zend_Search_Lucene_Field::unIndexed('birthday', $user['dob'], 'UTF-8'));
     	
     		/**
     		* Add document
     		*/
     /*$index->addDocument($doc);
     		 }
     	
     		$index->optimize();
     		$index->commit();*/
     foreach ($result as $values) {
         $doc = new Zend_Search_Lucene_Document();
         $doc->addField(Zend_Search_Lucene_Field::keyword('questionid', $values['id']));
         $doc->addField(Zend_Search_Lucene_Field::unStored('questions', $values['question']));
         $tag = explode(',', $values['tags']);
         $tags = implode(' ', $tag);
         $doc->addField(Zend_Search_Lucene_Field::text('tags', $tags));
         $index->addDocument($doc);
     }
     $index->commit();
 }
コード例 #20
0
 /**
  * Add a post to the index. 
  * 
  * @param Post $post the post being inserted
  */
 public function index_post($post)
 {
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Text('url', $post->permalink));
     $title = Zend_Search_Lucene_Field::Text('title', strtolower($post->title), 'utf-8');
     $title->boost = 50;
     $doc->addField($title);
     $doc->addField(Zend_Search_Lucene_Field::UnStored('contents', strtolower($post->content), 'utf-8'));
     // Add tags
     $tags = $post->tags;
     $tagstring = '';
     foreach ($tags as $tag) {
         $tagstring .= $tag . ' ';
     }
     $dtag = Zend_Search_Lucene_Field::UnStored('tags', strtolower($tagstring), 'utf-8');
     $dtag->boost = 10;
     $doc->addField($dtag);
     // Add ID
     $doc->addField(Zend_Search_Lucene_Field::keyword('postid', $post->id));
     $this->_index->addDocument($doc);
 }
コード例 #21
0
             if (!is_null($document)) {
                 $filesBody .= ' ' . $document->body;
             }
         }
         $document = new Zend_Search_Lucene_Document();
         $document->addField(Zend_Search_Lucene_Field::text('title', $result['event_title']));
         $document->addField(Zend_Search_Lucene_Field::keyword('event_id', $result['event_id']));
         $document->addField(Zend_Search_Lucene_Field::unStored('description', $result['event_description']));
         $document->addField(Zend_Search_Lucene_Field::unStored('goals', $result['event_goals']));
         $document->addField(Zend_Search_Lucene_Field::unStored('objectives', $result['event_objectives']));
         $document->addField(Zend_Search_Lucene_Field::unStored('message', $result['event_message']));
         $document->addField(Zend_Search_Lucene_Field::keyword('audience_type', $result['audience_type']));
         $document->addField(Zend_Search_Lucene_Field::keyword('audience_value', $result['event_cohort']));
         $document->addField(Zend_Search_Lucene_Field::keyword('event_start', $result['event_start']));
         $document->addField(Zend_Search_Lucene_Field::unStored('files_body', $filesBody));
         $document->addField(Zend_Search_Lucene_Field::keyword('organisation_id', $result['organisation_id']));
         $index->addDocument($document);
     }
     break;
 case 'optimize':
     $index = Zend_Search_Lucene::open($path . '/' . $input->index);
     $index->optimize();
     break;
 case 'search':
     $index = Zend_Search_Lucene::open($path . '/' . $input->index);
     $userQuery = Zend_Search_Lucene_Search_QueryParser::parse($input->term);
     $results = $index->find($userQuery);
     $textTable = new Zend_Text_Table(array('columnWidths' => array(12, 12, 5, 45)));
     $textTable->appendRow(array('Document ID', 'Database ID', 'Score', 'Title'));
     foreach ($results as $hit) {
         $textTable->appendRow(array((string) $hit->id, (string) $hit->event_id, (string) round($hit->score, 2), $hit->title));
コード例 #22
0
 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'));
 }
コード例 #23
0
ファイル: Document.php プロジェクト: robzienert/Drake
 /**
  * Adds defualt fields to the document
  *
  * @param string $class
  * @param mixed $key
  */
 public function __construct($class, $key)
 {
     $this->addField(Zend_Search_Lucene_Field::keyword('docRef', "{$class}:{$key}"));
     $this->addField(Zend_Search_Lucene_Field::unIndexed('class', $class));
     $this->addField(Zend_Search_Lucene_Field::unIndexed('key', $key));
 }
コード例 #24
0
ファイル: BlogPost.php プロジェクト: kalroot/phpweb20demo
 public function getIndexableDocument()
 {
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::keyword('post_id', $this->getId()));
     $fields = array('title' => $this->profile->title, 'content' => strip_tags($this->profile->content), 'published' => $this->profile->ts_published, 'tags' => join(' ', $this->getTags()));
     foreach ($fields as $name => $field) {
         $doc->addField(Zend_Search_Lucene_Field::unStored($name, $field));
     }
     return $doc;
 }