/**
     * 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)
                        . '&' . $urlAction . '=' . $docu->path, $encoding));

        return $doc;
    }
 /**
  * This is the default 'index' action that is invoked
  * when an action is not explicitly requested by users.
  */
 public function actionIndexing()
 {
     ini_set('max_execution_time', 0);
     ob_start();
     $index = new Zend_Search_Lucene(Yii::getPathOfAlias($this->_indexFilesPath), true);
     $criteria = new CDbCriteria();
     $criteria->compare('t.publish', 1);
     $criteria->order = 'album_id DESC';
     //$criteria->limit = 10;
     $model = Albums::model()->findAll($criteria);
     foreach ($model as $key => $item) {
         if ($item->media_id != 0) {
             $images = Yii::app()->request->baseUrl . '/public/album/' . $item->album_id . '/' . $item->cover->media;
         } else {
             $images = '';
         }
         $doc = new Zend_Search_Lucene_Document();
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('id', CHtml::encode($item->album_id), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('media', CHtml::encode($images), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('title', CHtml::encode($item->title), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('body', CHtml::encode(Utility::hardDecode(Utility::softDecode($item->body))), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::Text('url', CHtml::encode(Utility::getProtocol() . '://' . Yii::app()->request->serverName . Yii::app()->createUrl('album/site/view', array('id' => $item->album_id, 't' => Utility::getUrlTitle($item->title)))), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('date', CHtml::encode(Utility::dateFormat($item->creation_date, true) . ' WIB'), 'utf-8'));
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('creation', CHtml::encode($item->user->displayname), 'utf-8'));
         $index->addDocument($doc);
     }
     echo 'Album Lucene index created';
     $index->commit();
     $this->redirect(Yii::app()->createUrl('article/search/indexing'));
     ob_end_flush();
 }
 protected function _indexate($url)
 {
     if (!stristr($url, 'http://')) {
         $url = HTTP_HOST . $url;
     }
     $url = substr($url, -1) == '/' ? substr($url, 0, -1) : $url;
     if (!in_array($url, $this->_indexedUrl)) {
         if (stristr($url, HTTP_HOST)) {
             array_push($this->_indexedUrl, $url);
             $html = file_get_contents($url);
             libxml_use_internal_errors(true);
             $doc = Zend_Search_Lucene_Document_Html::loadHTML($html);
             libxml_use_internal_errors(false);
             if (preg_match('/<\\!--index-->(.*)<\\!--\\/index-->/isu', $html, $matches)) {
                 $html = $matches[1];
             }
             $html = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $html);
             $html = strip_tags($html);
             $doc->addField(Zend_Search_Lucene_Field::Text('content', $html, 'utf-8'));
             $doc->addField(Zend_Search_Lucene_Field::UnIndexed('body', '', 'utf-8'));
             $doc->addField(Zend_Search_Lucene_Field::Text('url', $url, 'utf-8'));
             $this->_indexHandle->addDocument($doc);
             Zend_Registry::get('Logger')->info('Search index is created: ' . $url, Zend_Log::INFO);
             foreach ($doc->getLinks() as $link) {
                 $temp = explode('.', $link);
                 $ext = end($temp);
                 if ($link == $ext || in_array($ext, array('php', 'html', 'txt', 'htm'))) {
                     $this->_indexate($link);
                 }
             }
         }
     }
 }
Example #4
0
 /**
  * Adds attributes to be indexed
  * 
  * @return string
  **/
 protected function addAttributes()
 {
     $this->addField(Zend_Search_Lucene_Field::Text('name', $this->getSourceModel()->getName(), self::ENCODING));
     $this->addField(Zend_Search_Lucene_Field::UnIndexed('short_content', $this->getSourceModel()->getShortDescription(), self::ENCODING));
     $this->addField(Zend_Search_Lucene_Field::UnIndexed('url', $this->getSourceModel()->getProductUrl(), self::ENCODING));
     $this->addFilterableAttributes();
     $this->addSearchableAttributes();
 }
Example #5
0
 /**
  * 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()));
 }
Example #6
0
 protected function _indexDocument($doc, $fields)
 {
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('checkSum', md5($doc->body)));
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('lastIndexed', time()));
     foreach ($fields as $name => $value) {
         $doc->addField(Zend_Search_Lucene_Field::Text($name, $value));
     }
     $this->_index->addDocument($doc);
     Bbx_Log::write('Added ' . urldecode($doc->url) . ' to index', null, self::LOG);
 }
Example #7
0
 private static function _insert($index, $item, $tags)
 {
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::Text('title', $item->name));
     $doc->addField(Zend_Search_Lucene_Field::Text('item_id', strval($item->id)));
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('image_id', strval($item->image_id)));
     $doc->addField(Zend_Search_Lucene_Field::Text('description', $item->description));
     $doc->addField(Zend_Search_Lucene_Field::Text('tag', $tags));
     $index->addDocument($doc);
     $index->commit();
 }
Example #8
0
 public function testUnIndexed()
 {
     $field = Zend_Search_Lucene_Field::UnIndexed('field', 'value');
     $this->assertEquals($field->boost, 1);
     $this->assertEquals($field->encoding, '');
     $this->assertEquals($field->isBinary, false);
     $this->assertEquals($field->isIndexed, false);
     $this->assertEquals($field->isStored, true);
     $this->assertEquals($field->isTokenized, false);
     $this->assertEquals($field->name, 'field');
     $this->assertEquals($field->value, 'value');
 }
Example #9
0
 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));
         }
     }
 }
Example #10
0
 /**
  * @param Zend_Feed_Atom $atom
  */
 private function processAtom($atom)
 {
     $this->addField(Zend_Search_Lucene_Field::UnIndexed('id', $this->id));
     $this->addField(Zend_Search_Lucene_Field::UnIndexed('url', $this->url));
     $this->addField(Zend_Search_Lucene_Field::Text('title', $atom->title()));
     // Loop over each channel item and store relevant data
     $text = '';
     foreach ($atom as $item) {
         $text .= $item->title();
         $text .= ' ';
         $text .= $item->content();
     }
     $this->addField(Zend_Search_Lucene_Field::Text('body', $text));
 }
Example #11
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;
    }
Example #12
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;
    }
Example #13
0
 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();
 }
 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;
 }
    /**
     * 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;
    }
    /**
     * 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;
    }
    /**
     * 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;
    }
    /**
     * 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;
    }
Example #19
0
 /**
  * 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 */
         }
     }
 }
Example #20
0
    /**
     * Construct a Zend_Search_Lucene_Document object out of a note db row.
     * 
     * @global string $urlServer
     * @param  object  $note
     * @return Zend_Search_Lucene_Document
     */
    protected function makeDoc($note) {
        global $urlServer;
        $encoding = 'utf-8';

        $doc = new Zend_Search_Lucene_Document();
        $doc->addField(Zend_Search_Lucene_Field::Keyword('pk', 'note_' . $note->id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('pkid', $note->id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('doctype', 'note', $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('userid', $note->user_id, $encoding));
        if(isset($note->course_id)){
            $doc->addField(Zend_Search_Lucene_Field::Keyword('courseid', $note->course_id, $encoding));
        }
        $doc->addField(Zend_Search_Lucene_Field::Text('title', Indexer::phonetics($note->title), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('content', Indexer::phonetics(strip_tags($note->content)), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('url', $urlServer . 'modules/notes/index.php?an_id=' . $note->id, $encoding));

        return $doc;
    }
Example #21
0
 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);
     }
 }
Example #22
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();
 }
Example #23
0
 public function updateLuceneIndex()
 {
     $index = GcMailboxPeer::getLuceneIndex();
     //borrar las entradas existentes
     if ($hit = $index->find('pk:' . $this->getId())) {
         $index->delete($hit->id);
     }
     //no indexar buzones expirados
     $doc = new Zend_Search_Lucene_Document();
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('pk', $this->getId()));
     $doc->addField(Zend_Search_Lucene_Field::unStored('username', $this->getUsername(), 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::unStored('name', $this->getName(), 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::unStored('email', $this->getEmail(), 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::unStored('domain', $this->getDomainName(), 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::unStored('area', $this->getGcArea(), 'utf-8'));
     $doc->addField(Zend_Search_Lucene_Field::unStored('group', $this->getGcGroup(), 'utf-8'));
     $index->addDocument($doc);
     $index->commit();
 }
Example #24
0
 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));
         }
     }
 }
Example #25
0
    /**
     * Construct a Zend_Search_Lucene_Document object out of a course db row.
     * 
     * @global string $urlServer
     * @param  object  $course
     * @return Zend_Search_Lucene_Document
     */
    protected function makeDoc($course) {
        global $urlServer;
        $encoding = 'utf-8';

        $doc = new Zend_Search_Lucene_Document();
        $doc->addField(Zend_Search_Lucene_Field::Keyword('pk', 'course_' . $course->id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('pkid', $course->id, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Keyword('doctype', 'course', $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('code', Indexer::phonetics($course->code), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('title', Indexer::phonetics($course->title), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('keywords', Indexer::phonetics($course->keywords), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('visible', $course->visible, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('prof_names', Indexer::phonetics($course->prof_names), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('public_code', Indexer::phonetics($course->public_code), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::Text('units', Indexer::phonetics(strip_tags($course->units)), $encoding));
        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('created', $course->created, $encoding));
        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('url', $urlServer . 'courses/' . $course->code, $encoding));

        return $doc;
    }
Example #26
0
 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();
 }
Example #27
0
 function create_index()
 {
     echo "Building search index...\n";
     $files = $this->get_files($this->_api);
     $count = 0;
     foreach ($files as $file) {
         $content = $this->get_details($file, $this->_api);
         $doc = new Zend_Search_Lucene_Document();
         $title = $content['class'];
         echo "  Adding " . $title . "\n";
         //unsearchable text
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('link', $content['link']));
         $doc->addField(Zend_Search_Lucene_Field::UnIndexed('title', $title));
         //$doc->addField(Zend_Search_Lucene_Field::UnIndexed('text', $content['content']));
         //searchable
         $body = strtolower($this->sanitize($content['content'])) . ' ' . strtolower($title);
         $doc->addField(Zend_Search_Lucene_Field::Keyword('page', strtolower(str_replace('.', ' ', $title))));
         $doc->addField(Zend_Search_Lucene_Field::Unstored('contents', $body));
         $this->_index->addDocument($doc);
         $count++;
     }
     $this->_index->commit();
     echo "\n {$count} files indexed.\n";
 }
 /**
  * Method to add a record to the search index
  *
  * @param string $docId Unique Document Id - Should be in the format of {module}_{type}_{id}
  * @param string $docDate Date and Time document has been created or should become available
  * @param string $url URL to the page
  * @param string $title Title of the Document
  * @param string $contents Contents of the Document
  * @param string $teaser Short Overview of Contents - Appears in Search Results
  * @param string $module Module Item is coming from
  * @param string $userId User adding the item
  * @param array $tags Tags for the story
  * @param string $license License applicable to the content
  * @param string $context Context content is being created in, duplicate if used in various contexts
  * @param string $workgroup Workgroup content is being created in, duplicate if used in various workgroups
  * @param string $permissions Permissions to be checked before being displayed in Search Results. module|action, which could then be used as $this->isValid('action', 'module')
  * @param date/time $dateAvailable Date story becomes available
  * @param date/time $dateUnavailable Date story expires
  * @param array $extra Any extra fields that might be peculiar to a module, in the format of $item=>$value,
  * @param boolean $doOptimize Should Index be automatically optimized
  *
  * The last one is useful for categories, eg. forum. $extra = array('forum'=>'id') allows one to do a search in a particular forum
  */
 public function luceneIndex($docId, $docDate, $url, $title, $contents, $teaser, $module, $userId, $tags = NULL, $license = NULL, $context = 'nocontext', $workgroup = 'noworkgroup', $permissions = NULL, $dateAvailable = NULL, $dateUnavailable = NULL, $extra = NULL, $doOptimize = TRUE)
 {
     if (!$this->enableLucene) {
         return;
     }
     // Remove Index if it exists
     $this->removeIndex($docId);
     // Get Indexer Object
     $this->index = $this->checkIndexPath();
     // Setup Lucene Document
     $document = new Zend_Search_Lucene_Document();
     // Set the properties that we want to use in our index
     // Document
     $document->addField(Zend_Search_Lucene_Field::Keyword('docid', $docId));
     // Date
     $document->addField(Zend_Search_Lucene_Field::Keyword('date', $docDate));
     // URL
     $document->addField(Zend_Search_Lucene_Field::UnIndexed('url', $url));
     // Title
     $document->addField(Zend_Search_Lucene_Field::Text('title', iconv('ISO-8859-1', 'ASCII//TRANSLIT', $title)));
     // Contents
     $document->addField(Zend_Search_Lucene_Field::UnStored('contents', iconv('ISO-8859-1', 'ASCII//TRANSLIT', mb_strtolower(stripslashes(strip_tags($title . ' ' . $contents))))));
     // Teaser
     $document->addField(Zend_Search_Lucene_Field::Text('teaser', $teaser));
     // Module
     $document->addField(Zend_Search_Lucene_Field::Keyword('module', $module));
     // UserId
     $document->addField(Zend_Search_Lucene_Field::Keyword('userId', $userId));
     // Tags // Check if Array - if yes, convert to string
     if (is_array($tags) && count($tags) > 0) {
         $newTags = '';
         $divider = '';
         foreach ($tags as $tag) {
             $newTags .= $divider . ' ' . $tag;
             $divider = ',';
         }
         $tags = $newTags;
     }
     // Add Tags
     $document->addField(Zend_Search_Lucene_Field::UnStored('tags', iconv('ISO-8859-1', 'ASCII//TRANSLIT', mb_strtolower(stripslashes(strip_tags($tags))))));
     // License
     $document->addField(Zend_Search_Lucene_Field::Keyword('license', $license));
     // Context
     $document->addField(Zend_Search_Lucene_Field::Keyword('context', $context));
     // Workgroup
     $document->addField(Zend_Search_Lucene_Field::Keyword('workgroup', $workgroup));
     // Permissions
     $document->addField(Zend_Search_Lucene_Field::UnIndexed('permissions', $permissions));
     // Date Available
     $document->addField(Zend_Search_Lucene_Field::UnIndexed('dateavailable', $dateAvailable));
     // Date Unavailable
     $document->addField(Zend_Search_Lucene_Field::UnIndexed('dateunavailable', $dateUnavailable));
     // Add Extra items into arrray
     if (is_array($extra)) {
         // Todo: check that fields dont clash with existing
         foreach ($extra as $item => $value) {
             $document->addField(Zend_Search_Lucene_Field::Keyword($item, $value));
         }
     }
     // Add the document to the index
     $this->index->addDocument($document);
     //optimize the thing
     if ($doOptimize) {
         $this->index->optimize();
     }
 }
Example #29
0
 * @package    Zend_Search_Lucene
 * @subpackage Demos
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
/**
 * @see Zend_Feed
 */
require_once 'Zend/Feed.php';
/**
 * @see Zend_Search_Lucene
 */
require_once 'Zend/Search/Lucene.php';
//create the index
$index = new Zend_Search_Lucene('/tmp/feeds_index', true);
// index each item
$rss = Zend_Feed::import('http://feeds.feedburner.com/ZendDeveloperZone');
foreach ($rss->items as $item) {
    $doc = new Zend_Search_Lucene_Document();
    if ($item->link && $item->title && $item->description) {
        $link = htmlentities(strip_tags($item->link()));
        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('link', $link));
        $title = htmlentities(strip_tags($item->title()));
        $doc->addField(Zend_Search_Lucene_Field::Text('title', $title));
        $contents = htmlentities(strip_tags($item->description()));
        $doc->addField(Zend_Search_Lucene_Field::Text('contents', $contents));
        echo "Adding {$item->title()}...\n";
        $index->addDocument($doc);
    }
}
$index->commit();
Example #30
0
 /**
  * Add an entry
  *
  * @param Searchable	$item Model	implememting Searchable interface
  * @param bool			$create_new	whether or not to create new index when adding item - only used when index is rebuilt
  * @return Search		return this instance for method chaining
  */
 public function add($item, $create_new = FALSE)
 {
     // ensure item implements Searchable interface
     if (!is_a($item, "Searchable")) {
         throw new Kohana_User_Exception('Invalid Object', 'Object must implement Searchable Interface');
     }
     if (!$create_new) {
         $this->open_index();
     }
     $doc = new Zend_Search_Lucene_Document();
     // get indexable fields;
     $fields = $item->get_indexable_fields();
     // index the object type - this allows search results to be grouped/searched by type
     $doc->addField(Zend_Search_Lucene_Field::Keyword('type', $item->get_type()));
     // index the object's id - to avoid any confusion, we call it 'identifier' as Lucene uses 'id' attribute internally.
     $doc->addField(Zend_Search_Lucene_Field::UnIndexed('identifier', $item->get_identifier()));
     // store, but don't index or tokenize
     // index the object type plus identifier - this gives us a unique identifier for later retrieval - e.g. to delete
     $doc->addField(Zend_Search_Lucene_Field::Keyword('uid', $item->get_unique_identifier()));
     // index all fields that have been identified by Interface
     foreach ($fields as $field) {
         // get attribute value from model
         $value = $item->__get($field->name);
         // html decode value if required
         $value = $field->html_decode ? htmlspecialchars_decode($value) : $value;
         // add field value based on type
         switch ($field->type) {
             case Searchable::KEYWORD:
                 $doc->addField(Zend_Search_Lucene_Field::Keyword($field->name, $value));
                 break;
             case Searchable::UNINDEXED:
                 $doc->addField(Zend_Search_Lucene_Field::UnIndexed($field->name, $value));
                 break;
             case Searchable::BINARY:
                 $doc->addField(Zend_Search_Lucene_Field::Binary($field->name, $value));
                 break;
             case Searchable::TEXT:
                 $doc->addField(Zend_Search_Lucene_Field::Text($field->name, $value));
                 break;
             case Searchable::UNSTORED:
                 $doc->addField(Zend_Search_Lucene_Field::UnStored($field->name, $value));
                 break;
         }
     }
     $this->index->addDocument($doc);
     // return this so we can have chainable methods
     return $this;
 }