コード例 #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
ファイル: Pmml.php プロジェクト: KIZI/sewebar-cms
 private function __construct($rule, $additional, $storeContent)
 {
     /*$dom = new DOMDocument ();
     		$dom->preserveWhiteSpace = false;
     		$dom->loadXML ( $rule );*/
     //walk through the association rule and index it
     //$this->_parse ( $rule, 1 );
     $quantifiers = $rule->childNodes;
     foreach ($quantifiers as $quantifier) {
         if ($quantifier->nodeName == '#text' || $quantifier->nodeValue == '') {
             continue;
         }
         //print $quantifier->nodeName.' : '. trim($quantifier->nodeValue).'<br/>';
         $val = trim($quantifier->nodeValue);
         if (is_numeric($val)) {
             $val = JuceneHelper::prepareNumber($val);
         } else {
             $val = (string) $val;
             $val = str_replace("-", "", $val);
         }
         if ($quantifier->nodeName == 'Text') {
             $type = 'Unindexed';
         } else {
             $type = 'Text';
         }
         $this->addField(Zend_Search_Lucene_Field::$type($quantifier->nodeName, $val, JUCENE_ENCODING));
     }
     foreach ($additional as $field => $value) {
         if (is_numeric($value)) {
             $val = JuceneHelper::prepareNumber($value);
         }
         $this->addField(Zend_Search_Lucene_Field::Keyword('service_' . $field, $value, JUCENE_ENCODING));
     }
 }
コード例 #3
0
ファイル: search_engine.php プロジェクト: rsesek/Bugdar2
 public function IndexBug($bug)
 {
     $this->RemoveBug($bug->bug_id);
     $doc = new Zend_Search_Lucene_Document();
     $doc->AddField(Zend_Search_Lucene_Field::Keyword('bug_id', $bug->bug_id));
     $doc->AddField(Zend_Search_Lucene_Field::Text('title', $bug->title));
     $doc->AddField(Zend_Search_Lucene_Field::Keyword('reporting_user_id', $bug->reporting_user_id));
     $doc->AddField(Zend_Search_Lucene_Field::Keyword('reporting_date', $bug->reporting_date));
     // We concatenate all comments into a single text blob. We only show
     // hits as bugs, but we want comment content to matter.
     $comment_blob = '';
     $stmt = Bugdar::$db->Prepare("SELECT body FROM " . TABLE_PREFIX . "comments WHERE bug_id = ? ORDER BY comment_id");
     $stmt->Execute(array($bug->bug_id));
     while ($comment = $stmt->FetchObject()) {
         $comment_blob .= $comment->body . "\n\n";
     }
     $doc->AddField(Zend_Search_Lucene_Field::UnStored('comments', $comment_blob));
     // Add all attributes.
     $stmt = Bugdar::$db->Prepare("SELECT * FROM " . TABLE_PREFIX . "bug_attributes WHERE bug_id = ?");
     $stmt->Execute(array($bug->bug_id));
     $tags = array();
     while ($attr = $stmt->FetchObject()) {
         if ($attr->attribute_title) {
             $doc->AddField(Zend_Search_Lucene_Field::Keyword($attr->attribute_title, $attr->value));
         } else {
             $tags[] = $attr->value;
         }
     }
     $doc->AddField(Zend_Search_Lucene_Field::Text('tag', implode(' ', $tags)));
     $this->lucene->AddDocument($doc);
 }
コード例 #4
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();
 }
コード例 #5
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;
 }
コード例 #6
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";
}
コード例 #7
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();
 }
コード例 #8
0
    /**
     * Construct a Zend_Search_Lucene_Document object out of a document db row.
     * 
     * @global string $urlServer
     * @param  object  $docu
     * @return Zend_Search_Lucene_Document
     */
    protected function makeDoc($docu) {
        global $urlServer;
        $encoding = 'utf-8';

        $doc = new Zend_Search_Lucene_Document();
        $doc->addField(Zend_Search_Lucene_Field::Keyword('pk', 'doc_' . $docu->id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('pkid', $docu->id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('doctype', 'doc', $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('courseid', $docu->course_id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('title', Indexer::phonetics($docu->title), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('content', Indexer::phonetics($docu->description), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('filename', Indexer::phonetics($docu->filename), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('comment', Indexer::phonetics($docu->comment), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('creator', Indexer::phonetics($docu->creator), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('subject', Indexer::phonetics($docu->subject), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('author', Indexer::phonetics($docu->author), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('visible', $docu->visible, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('public', $docu->public, $encoding));

        $urlAction = ($docu->format == '.dir') ? 'openDir' : 'download';
        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('url', $urlServer
                        . 'modules/document/index.php?course=' . course_id_to_code($docu->course_id)
                        . '&amp;' . $urlAction . '=' . $docu->path, $encoding));

        return $doc;
    }
コード例 #9
0
ファイル: buildIndex.php プロジェクト: ringmaster/my.brain
 /**
  * Constructor. Creates our indexable document and adds all
  * necessary fields to it using the passed in document
  */
 public function __construct($document)
 {
     $this->addField(Zend_Search_Lucene_Field::UnIndexed('id_entry', $document->getId()));
     $this->addField(Zend_Search_Lucene_Field::Keyword('url', $document->getUrl()));
     $this->addField(Zend_Search_Lucene_Field::UnIndexed('creation_date', $document->getCreationDate()));
     $this->addField(Zend_Search_Lucene_Field::Text('name', $document->getName()), 'utf-8');
     $this->addField(Zend_Search_Lucene_Field::Text('content', $document->getDetails()));
     $this->addField(Zend_Search_Lucene_Field::Text('tag', $document->getImplodedTags()));
 }
コード例 #10
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();
 }
コード例 #11
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);
 }
コード例 #12
0
ファイル: Abstract.php プロジェクト: rickboyau/magento-lucene
 /**
  * Index entity of document with given id.
  * 
  * @param Mage_Core_Model_Abstract
  *
  * @return Mage_Lucene_Model_Index_Document_Abstract
  **/
 public function index($sourceModel)
 {
     $this->_sourceModel = $sourceModel;
     $this->_id = $sourceModel->getId();
     $this->delete();
     $this->addField(Zend_Search_Lucene_Field::Keyword('doctype', $this->getDoctype()));
     $this->addField(Zend_Search_Lucene_Field::Keyword('entity_id', $this->_id));
     $this->addField(Zend_Search_Lucene_Field::Keyword(self::STORE_ATTRIBUTE_CODE, $this->getStore()->getId()));
     $this->addAttributes();
     $this->addDocument();
     return $this;
 }
コード例 #13
0
ファイル: FieldTest.php プロジェクト: omusico/logica
 public function testKeyword()
 {
     $field = Zend_Search_Lucene_Field::Keyword('field', 'value');
     $this->assertEquals($field->boost, 1);
     $this->assertEquals($field->encoding, '');
     $this->assertEquals($field->isBinary, false);
     $this->assertEquals($field->isIndexed, true);
     $this->assertEquals($field->isStored, true);
     $this->assertEquals($field->isTokenized, false);
     $this->assertEquals($field->name, 'field');
     $this->assertEquals($field->value, 'value');
 }
コード例 #14
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));
     }
 }
コード例 #15
0
ファイル: document.php プロジェクト: JackCanada/moodle-hacks
 public function __construct(&$doc, &$data, $course_id, $group_id, $user_id, $path, $additional_keyset = null)
 {
     $encoding = 'UTF-8';
     //document identification and indexing
     $this->addField(Zend_Search_Lucene_Field::Keyword('docid', $doc->docid, $encoding));
     //document type : the name of the Moodle element that manages it
     $this->addField(Zend_Search_Lucene_Field::Keyword('doctype', $doc->documenttype, $encoding));
     //allows subclassing information from complex modules.
     $this->addField(Zend_Search_Lucene_Field::Keyword('itemtype', $doc->itemtype, $encoding));
     //caches the course context.
     $this->addField(Zend_Search_Lucene_Field::Keyword('course_id', $course_id, $encoding));
     //caches the originator's group.
     $this->addField(Zend_Search_Lucene_Field::Keyword('group_id', $group_id, $encoding));
     //caches the originator if any
     $this->addField(Zend_Search_Lucene_Field::Keyword('user_id', $user_id, $encoding));
     // caches the context of this information. i-e, the context in which this information
     // is being produced/attached. Speeds up the "check for access" process as context in
     // which the information resides (a course, a module, a block, the site) is stable.
     $this->addField(Zend_Search_Lucene_Field::UnIndexed('context_id', $doc->contextid, $encoding));
     //data for document
     $this->addField(Zend_Search_Lucene_Field::Text('title', $doc->title, $encoding));
     $this->addField(Zend_Search_Lucene_Field::Text('author', $doc->author, $encoding));
     $this->addField(Zend_Search_Lucene_Field::UnStored('contents', $doc->contents, $encoding));
     $this->addField(Zend_Search_Lucene_Field::UnIndexed('url', $doc->url, $encoding));
     $this->addField(Zend_Search_Lucene_Field::UnIndexed('date', $doc->date, $encoding));
     //additional data added on a per-module basis
     $this->addField(Zend_Search_Lucene_Field::Binary('data', serialize($data)));
     // adding a path allows the document to know where to find specific library calls
     // for checking access to a module or block content. The Lucene records should only
     // be responsible to bring back to that call sufficient and consistent information
     // in order to perform the check.
     $this->addField(Zend_Search_Lucene_Field::UnIndexed('path', $path, $encoding));
     /*
     // adding a capability set required for viewing. -1 if no capability required.
     // the capability required for viewing is depending on the local situation
     // of the document. each module should provide this information when pushing
     // out search document structure. Although capability model should be kept flat
     // there is no exclusion some module or block developpers use logical combinations
     // of multiple capabilities in their code. This possibility should be left open here.
     $this->addField(Zend_Search_Lucene_Field::UnIndexed('capabilities', $caps));
     */
     /*
     // Additional key set allows a module to ask for extensible criteria based search
     // depending on the module internal needs.
     */
     if (!empty($additional_keyset)) {
         foreach ($additional_keyset as $keyname => $keyvalue) {
             $this->addField(Zend_Search_Lucene_Field::Keyword($keyname, $keyvalue, $encoding));
         }
     }
 }
コード例 #16
0
ファイル: indexer.php プロジェクト: CDN-Sparks/owncloud
 /**
  * index a file
  *
  * @author Jörn Dreyer <*****@*****.**>
  *
  * @param string $path the path of the file
  *
  * @return bool
  */
 public static function indexFile($path = '', $user = null)
 {
     if (!Filesystem::isValidPath($path)) {
         return;
     }
     if ($path === '') {
         //ignore the empty path element
         return false;
     }
     if (is_null($user)) {
         $view = Filesystem::getView();
         $user = \OCP\User::getUser();
     } else {
         $view = new \OC\Files\View('/' . $user . '/files');
     }
     if (!$view) {
         Util::writeLog('search_lucene', 'could not resolve filesystem view', Util::WARN);
         return false;
     }
     $root = $view->getRoot();
     $pk = md5($root . $path);
     // the cache already knows mime and other basic stuff
     $data = $view->getFileInfo($path);
     if (isset($data['mimetype'])) {
         $mimetype = $data['mimetype'];
         if ('text/html' === $mimetype) {
             $doc = \Zend_Search_Lucene_Document_Html::loadHTML($view->file_get_contents($path));
         } else {
             if ('application/msword' === $mimetype) {
                 // FIXME uses ZipArchive ... make compatible with OC\Files\Filesystem
                 //$doc = Zend_Search_Lucene_Document_Docx::loadDocxFile(OC\Files\Filesystem::file_get_contents($path));
                 //no special treatment yet
                 $doc = new \Zend_Search_Lucene_Document();
             } else {
                 $doc = new \Zend_Search_Lucene_Document();
             }
         }
         // store fscacheid as unique id to lookup by when deleting
         $doc->addField(\Zend_Search_Lucene_Field::Keyword('pk', $pk));
         // Store document URL to identify it in the search results
         $doc->addField(\Zend_Search_Lucene_Field::Text('path', $path));
         $doc->addField(\Zend_Search_Lucene_Field::unIndexed('size', $data['size']));
         $doc->addField(\Zend_Search_Lucene_Field::unIndexed('mimetype', $mimetype));
         self::extractMetadata($doc, $path, $view, $mimetype);
         Lucene::updateFile($doc, $path, $user);
         return true;
     } else {
         Util::writeLog('search_lucene', 'need mimetype for content extraction', Util::ERROR);
         return false;
     }
 }
コード例 #17
0
    /**
     * Construct a Zend_Search_Lucene_Document object out of a link db row.
     * 
     * @global string $urlServer
     * @param  object  $link
     * @return Zend_Search_Lucene_Document
     */
    protected function makeDoc($link) {
        $encoding = 'utf-8';

        $doc = new Zend_Search_Lucene_Document();
        $doc->addField(Zend_Search_Lucene_Field::Keyword('pk', 'link_' . $link->id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('pkid', $link->id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('doctype', 'link', $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('courseid', $link->course_id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('title', Indexer::phonetics($link->title), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('content', Indexer::phonetics(strip_tags($link->description)), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('url', $link->url, $encoding));

        return $doc;
    }
コード例 #18
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();
 }
コード例 #19
0
    /**
     * Construct a Zend_Search_Lucene_Document object out of a video db row.
     * 
     * @global string $urlServer
     * @param  object  $video
     * @return Zend_Search_Lucene_Document
     */
    protected function makeDoc($video) {
        global $urlServer;
        $encoding = 'utf-8';

        $doc = new Zend_Search_Lucene_Document();
        $doc->addField(Zend_Search_Lucene_Field::Keyword('pk', 'video_' . $video->id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('pkid', $video->id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('doctype', 'video', $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('courseid', $video->course_id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('title', Indexer::phonetics($video->title), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('content', Indexer::phonetics($video->description), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('url', $urlServer . 'modules/video/file.php?course=' . course_id_to_code($video->course_id) . '&amp;id=' . $video->id, $encoding));

        return $doc;
    }
コード例 #20
0
    /**
     * Construct a Zend_Search_Lucene_Document object out of an exercise db row.
     * 
     * @global string $urlServer
     * @param  object  $exercise
     * @return Zend_Search_Lucene_Document
     */
    protected function makeDoc($exercise) {
        global $urlServer;
        $encoding = 'utf-8';

        $doc = new Zend_Search_Lucene_Document();
        $doc->addField(Zend_Search_Lucene_Field::Keyword('pk', 'exercise_' . $exercise->id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('pkid', $exercise->id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('doctype', 'exercise', $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('courseid', $exercise->course_id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('title', Indexer::phonetics($exercise->title), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('content', Indexer::phonetics(strip_tags($exercise->description)), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('visible', $exercise->active, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('url', $urlServer . 'modules/exercise/exercise_submit.php?course=' . course_id_to_code($exercise->course_id) . '&amp;exerciseId=' . $exercise->id, $encoding));

        return $doc;
    }
コード例 #21
0
    /**
     * Construct a Zend_Search_Lucene_Document object out of a forum topic db row.
     * 
     * @global string $urlServer
     * @param  object  $ftopic
     * @return Zend_Search_Lucene_Document
     */
    protected function makeDoc($ftopic) {
        global $urlServer;
        $encoding = 'utf-8';

        $doc = new Zend_Search_Lucene_Document();
        $doc->addField(Zend_Search_Lucene_Field::Keyword('pk', 'ftopic_' . $ftopic->id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('pkid', $ftopic->id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('doctype', 'ftopic', $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('courseid', $ftopic->course_id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('forumid', $ftopic->forum_id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('title', Indexer::phonetics($ftopic->title), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('url', $urlServer . 'modules/forum/viewforum.php?course=' . course_id_to_code($ftopic->course_id)
                        . '&amp;forum=' . intval($ftopic->forum_id), $encoding));

        return $doc;
    }
コード例 #22
0
    /**
     * Construct a Zend_Search_Lucene_Document object out of an announcement db row.
     * 
     * @global string $urlServer
     * @param  object  $announce
     * @return Zend_Search_Lucene_Document
     */
    protected function makeDoc($announce) {
        global $urlServer;
        $encoding = 'utf-8';

        $doc = new Zend_Search_Lucene_Document();
        $doc->addField(Zend_Search_Lucene_Field::Keyword('pk', 'announce_' . $announce->id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('pkid', $announce->id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('doctype', 'announce', $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('courseid', $announce->course_id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('title', Indexer::phonetics($announce->title), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('content', Indexer::phonetics(strip_tags($announce->content)), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('visible', $announce->visible, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('url', $urlServer . 'modules/announcements/index.php?course=' . course_id_to_code($announce->course_id) . '&amp;an_id=' . $announce->id, $encoding));

        return $doc;
    }
コード例 #23
0
 static function AddToIndex(SearchableObject $object, $commitOnEnd = true)
 {
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Keyword('combinedid', $object->getRelObjectManager() . $object->getRelObjectId()));
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('objectid', $object->getRelObjectId()));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('manager', $object->getRelObjectManager()));
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('column', $object->getColumnName()));
     $doc->addField(Zend_Search_Lucene_Field::UnStored('text', $object->getContent()));
     $doc->addField(Zend_Search_Lucene_Field::Text('workspaces', "ws" . $object->getProjectId() . " "));
     $doc->addField(Zend_Search_Lucene_Field::Text('isprivate', ($object->getIsPrivate() ? '1' : '0') . " "));
     self::GetIndex()->addDocument($doc);
     if ($commitOnEnd) {
         self::GetIndex()->commit();
     }
     return true;
 }
コード例 #24
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;
 }
コード例 #25
0
ファイル: Category.php プロジェクト: rickboyau/magento-lucene
 /**
  * Adds all values of related category to the search document.
  *
  * @return void
  **/
 protected function addAttributes()
 {
     $content = strip_tags($this->getStaticBlock());
     $this->addField(Zend_Search_Lucene_Field::UnStored('content', $content, self::ENCODING));
     $this->addField(Zend_Search_Lucene_Field::Text('name', $this->getSourceModel()->getName(), self::ENCODING));
     $this->addField(Zend_Search_Lucene_Field::Keyword('category', $this->getSourceModel()->getParentCategory()->getName(), self::ENCODING));
     $this->addField(Zend_Search_Lucene_Field::UnIndexed('short_content', substr($content, 0, self::SHORT_CONTENT_CHAR_COUNT), self::ENCODING));
     $this->addField(Zend_Search_Lucene_Field::UnIndexed('url', $this->getSourceModel()->getUrl(), self::ENCODING));
     if ($this->getSourceModel()->getImage()) {
         try {
             $image = Mage::getModel('catalog/product_image')->setBaseFile('../category/' . $this->getSourceModel()->getImage())->setHeight(100)->setWidth(100)->resize()->saveFile()->getUrl();
             $this->addField(Zend_Search_Lucene_Field::UnIndexed('image', $image, self::ENCODING));
         } catch (Exception $e) {
             /* no image for category, so none will be added to index */
         }
     }
 }
コード例 #26
0
    /**
     * Construct a Zend_Search_Lucene_Document object out of a forum post row.
     * 
     * @global string $urlServer
     * @param  object  $fpost
     * @return Zend_Search_Lucene_Document
     */
    protected function makeDoc($fpost) {
        global $urlServer;
        $encoding = 'utf-8';

        $doc = new Zend_Search_Lucene_Document();
        $doc->addField(Zend_Search_Lucene_Field::Keyword('pk', 'fpost_' . $fpost->id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('pkid', $fpost->id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('doctype', 'fpost', $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('courseid', $fpost->course_id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('topicid', $fpost->topic_id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('content', Indexer::phonetics(strip_tags($fpost->post_text)), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('url', $urlServer . 'modules/forum/viewtopic.php?course=' . course_id_to_code($fpost->course_id)
                        . '&amp;topic=' . intval($fpost->topic_id)
                        . '&amp;forum=' . intval($fpost->forum_id), $encoding));

        return $doc;
    }
コード例 #27
0
ファイル: quickstart_index.php プロジェクト: bklein01/prado
 public function add($content, $section, $mtime)
 {
     foreach ($this->split_headings($content) as $headers) {
         $doc = new Zend_Search_Lucene_Document();
         $link = "index.php?page=" . preg_replace('/\\/|\\\\/', '.', $section);
         $link = str_replace('.page', '', $link) . '#' . $headers['section'];
         //unsearchable text
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('link', $link));
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('mtime', $mtime));
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('title', $headers['title']));
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('text', $headers['content']));
         //searchable text
         $doc->addField(Zend_Search_Lucene_Field::Keyword('page', strtolower($headers['title'])));
         $body = strtolower($this->sanitize($headers['content'])) . ' ' . strtolower($headers['title']);
         $doc->addField(Zend_Search_Lucene_Field::Unstored('contents', $body));
         $this->_index->addDocument($doc);
     }
 }
コード例 #28
0
 public static function indexationAdd($indexationData)
 {
     $directory = Zend_Registry::get('lucene_index');
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Keyword('pageID', $indexationData['pageID']));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('moduleID', $indexationData['moduleID']));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('contentID', $indexationData['contentID']));
     $doc->addField(Zend_Search_Lucene_Field::Keyword('languageID', $indexationData['languageID']));
     $doc->addField(Zend_Search_Lucene_Field::Text('title', Cible_FunctionsGeneral::html2text($indexationData['title'])));
     $doc->addField(Zend_Search_Lucene_Field::Text('text', Cible_FunctionsGeneral::html2text($indexationData['text'])));
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('link', $indexationData['link']));
     $doc->addField(Zend_Search_Lucene_Field::UnStored('contents', strtolower(Cible_FunctionsGeneral::removeAccents(Cible_FunctionsGeneral::html2text($indexationData['contents'])))));
     $newIndex = !is_dir($directory);
     $index = new Zend_Search_Lucene($directory, $newIndex);
     $index->addDocument($doc);
     $index->commit();
 }
コード例 #29
0
ファイル: item.inc.php プロジェクト: cjbayliss/alloc
 function update_search_index_doc(&$index)
 {
     $p =& get_cached_table("person");
     $personID = $this->get_value("personID");
     $person_field = $personID . " " . $p[$personID]["username"] . " " . $p[$personID]["name"];
     $itemModifiedUser = $this->get_value("itemModifiedUser");
     $itemModifiedUser_field = $itemModifiedUser . " " . $p[$itemModifiedUser]["username"] . " " . $p[$itemModifiedUser]["name"];
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Keyword('id', $this->get_id()));
     $doc->addField(Zend_Search_Lucene_Field::Text('name', $this->get_value("itemName"), "utf-8"));
     $doc->addField(Zend_Search_Lucene_Field::Text('desc', $this->get_value("itemNotes"), "utf-8"));
     $doc->addField(Zend_Search_Lucene_Field::Text('type', $this->get_value("itemType"), "utf-8"));
     $doc->addField(Zend_Search_Lucene_Field::Text('author', $this->get_value("itemAuthor"), "utf-8"));
     $doc->addField(Zend_Search_Lucene_Field::Text('creator', $person_field, "utf-8"));
     $doc->addField(Zend_Search_Lucene_Field::Text('modifier', $itemModifiedUser_field, "utf-8"));
     $doc->addField(Zend_Search_Lucene_Field::Text('dateModified', str_replace("-", "", $this->get_value("itemModifiedTime")), "utf-8"));
     $index->addDocument($doc);
 }
コード例 #30
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);
 }