コード例 #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
 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();
 }
コード例 #3
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);
 }
コード例 #4
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'));
 }
コード例 #5
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();
 }
コード例 #6
0
ファイル: search.php プロジェクト: VUW-SIM-FIS/emiemi
function searchImportFragment($fragment, $index)
{
    if ($fragment->getType() != "text") {
        return;
    }
    $doc = new Zend_Search_Lucene_Document();
    $doc->addField(Zend_Search_Lucene_Field::text('uri', $fragment->getUri(), INDEX_CHARSET));
    $doc->addField(Zend_Search_Lucene_Field::text('user', $fragment->getCreatorId(), INDEX_CHARSET));
    $doc->addField(Zend_Search_Lucene_Field::text('created', $fragment->getCreateDate(), INDEX_CHARSET));
    $doc->addField(Zend_Search_Lucene_Field::text('modified', $fragment->getModifyDate(), INDEX_CHARSET));
    $doc->addField(Zend_Search_Lucene_Field::text('title', $fragment->getTitle(), INDEX_CHARSET));
    $doc->addField(Zend_Search_Lucene_Field::text('content', $fragment->getSaveContent(), INDEX_CHARSET));
    $doc->addField(Zend_Search_Lucene_Field::text('searchtext', $fragment->getTitle() . " " . $fragment->getContent(), INDEX_CHARSET));
    $ret = $index->addDocument($doc);
}
コード例 #7
0
 function index($title, $content, $url, $keywords, $user_id)
 {
     $this->initLuceneEngine();
     $id = $this->getId($url);
     $indexer = $this->zend->get_Zend_Search_Lucene();
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Keyword('id', $id));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('userid', $user_id));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('url', $url));
     $doc->addField(Zend_Search_Lucene_Field::UnStored("content", $content, 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::text("title", $title, 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::text("keywords", $keywords, 'utf-8'));
     $indexer->addDocument($doc);
     $indexer->commit();
     //$indexer->optimize();
     return TRUE;
 }
コード例 #8
0
ファイル: Lucene.php プロジェクト: BGCX261/zoocms-svn-to-git
 /**
  * Add node to index
  *
  * @param Zoo_Content_Interface $item
  */
 protected function _build(Zoo_Content_Interface $item)
 {
     // Delete existing document, if exists
     $hits = $this->index->find('nid:' . $item->id);
     foreach ($hits as $hit) {
         $this->index->delete($hit->id);
     }
     // (Re-)Index document
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::text('nid', $item->id));
     $doc->addField(Zend_Search_Lucene_Field::unIndexed('link', $item->url()));
     $doc->addField(Zend_Search_Lucene_Field::unStored('title', $item->title));
     $doc->addField(Zend_Search_Lucene_Field::unStored('type', $item->type));
     $doc->addField(Zend_Search_Lucene_Field::unStored('published', $item->published));
     $doc->addField(Zend_Search_Lucene_Field::unStored('uid', $item->uid));
     list($content) = Zoo::getService('content')->getRenderedContent($item->id, 'Display');
     $doc->addField(Zend_Search_Lucene_Field::unStored('contents', strip_tags($content)));
     return $doc;
 }
コード例 #9
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();
 }
コード例 #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
ファイル: js_data_model.php プロジェクト: cyberformed/i2tree
 function insert($dataObj, $user_id = 0, $object_type = JS_TEXT_DATA, $indexedContent = '', $isIndexed = TRUE, $keyHints = '')
 {
     $this->initLuceneEngine();
     $id = $this->getId($keyHints);
     $dataObjStr = '';
     if (!is_string($dataObj)) {
         $dataObjStr = json_encode($dataObj);
     }
     $data = PREFIX_JS_DATA . ' ' . $dataObjStr . ' ' . SUFFIX_JS_DATA;
     if (write_file('./js-data/' . $id . '.js', $data)) {
         $indexer = $this->zend->get_Zend_Search_Lucene();
         $doc = new Zend_Search_Lucene_Document();
         $doc->addField(Zend_Search_Lucene_Field::Keyword('id', $id));
         $doc->addField(Zend_Search_Lucene_Field::Keyword('userid', $user_id));
         $doc->addField(Zend_Search_Lucene_Field::Keyword('object_type', $object_type));
         if ($isIndexed) {
             if ($object_type === JS_TEXT_DATA) {
                 $doc->addField(Zend_Search_Lucene_Field::UnStored("content", $indexedContent, 'utf-8'));
                 $doc->addField(Zend_Search_Lucene_Field::text("title", $dataObj['title'], 'utf-8'));
             } else {
                 if ($object_type === JS_STRUCTURED_DATA && is_string($dataObj)) {
                     $dataObj = json_decode($dataObj);
                     //unset Reserved Fields
                     unset($dataObj['id']);
                     unset($dataObj['userid']);
                     unset($dataObj['object_type']);
                     foreach ($dataObj as $key => $value) {
                         $doc->addField(Zend_Search_Lucene_Field::UnStored($key, $value, 'utf-8'));
                     }
                 }
             }
         }
         $indexer->addDocument($doc);
         $indexer->commit();
         //$indexer->optimize();
         return TRUE;
     }
     return FALSE;
 }
コード例 #12
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();
 }
コード例 #13
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);
 }
コード例 #14
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;
 }
コード例 #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
ファイル: AOD_Index.php プロジェクト: omusico/SelkirkCRM
 /**
  * @param $revision
  * @return bool|Zend_Search_Lucene_Document
  */
 private function getDocumentForRevision($revision)
 {
     $path = getDocumentRevisionPath($revision->id);
     if (!file_exists($path)) {
         return array("error" => "File not found");
     }
     //Convert the file to a lucene document
     $mime = $revision->file_mime_type;
     switch ($mime) {
         case 'application/pdf':
             $document = createPDFDocument($path);
             break;
         case 'application/msword':
             $document = createDocDocument($path);
             break;
         case 'application/vnd.oasis.opendocument.text':
             $document = createOdtDocument($path);
             break;
         case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
             $document = createDocXDocument($path);
             break;
         case 'text/html':
             $document = createHTMLDocument($path);
             break;
         case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
             $document = createXLSXDocument($path);
             break;
         case 'application/rtf':
             $document = createRTFDocument($path);
         case 'text/csv':
         case 'text/plain':
             $document = createTextDocument($path);
             break;
         case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
             $document = createPPTXDocument($path);
             break;
         case 'application/vnd.oasis.opendocument.spreadsheet':
         case 'application/vnd.ms-powerpoint':
         case 'application/vnd.ms-excel':
         default:
             return array("error" => "Mime type {$mime} not supported");
     }
     if (!$document) {
         return array("error" => "Failed to parse document");
     }
     $document->addField(Zend_Search_Lucene_Field::text("filename", $revision->filename));
     return array("error" => false, "document" => $document);
 }
コード例 #17
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);
 }
コード例 #18
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'));
 }
コード例 #19
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);
     }
 }
コード例 #20
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);
     }
 }
コード例 #21
0
         $query = "\tSELECT a.*, MAX(b.`timestamp`) AS `last_visited`\n\t\t\t\t\t\tFROM `event_files` AS a\n\t\t\t\t\t\tLEFT JOIN `statistics` AS b\n\t\t\t\t\t\tON b.`module` = 'events'\n\t\t\t\t\t\tAND b.`action` = 'file_download'\n\t\t\t\t\t\tAND b.`action_field` = 'file_id'\n\t\t\t\t\t\tAND b.`action_value` = a.`efile_id`\n\t\t\t\t\t\tWHERE a.`event_id` = " . $db->qstr($result['event_id']);
         $event_files = $db->GetAll($query);
         //var_dump($event_files);die();
         $filesBody = null;
         foreach ($event_files as $file) {
             if (is_null($file['file_name'])) {
                 continue;
             }
             $path = pathinfo($file['file_name']);
             $document = Entrada_Search_Lucene_Document::factory(FILE_STORAGE_PATH . "/" . $file['efile_id'], $path['extension']);
             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);