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); } } } } }
public function luceneIndexAction() { $this->view->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $path = PUBLIC_PATH . '/tmp/lucene'; try { $index = Zend_Search_Lucene::open($path); } catch (Zend_Search_Lucene_Exception $e) { try { $index = Zend_Search_Lucene::create($path); } catch (Zend_Search_Lucene_Exception $e) { echo "Unable to open or create index : {$e->getMessage()}"; } } for ($i = 0; $i < $index->maxDoc(); $i++) { $index->delete($i); } $users = new Application_Model_User(); $users = $users->fetchAll(); foreach ($users as $_user) { Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive()); $doc = new Zend_Search_Lucene_Document(); $doc->addField(Zend_Search_Lucene_Field::Text('title', $_user->getFirstName())); $doc->addField(Zend_Search_Lucene_Field::keyword('empcode', $_user->getEmployeeCode())); $index->addDocument($doc); $index->commit(); $index->optimize(); } }
/** * 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; }
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(); }
/** * 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(); }
public function testAddFieldMethodChaining() { $document = new Zend_Search_Lucene_Document(); $this->assertTrue($document->addField(Zend_Search_Lucene_Field::Text('title', 'Title')) instanceof Zend_Search_Lucene_Document); $document = new Zend_Search_Lucene_Document(); $document->addField(Zend_Search_Lucene_Field::Text('title', 'Title'))->addField(Zend_Search_Lucene_Field::Text('annotation', 'Annotation'))->addField(Zend_Search_Lucene_Field::Text('body', 'Document body, document body, document body...')); }
public function updateAction() { Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive()); // Создание индекса $index = Zend_Search_Lucene::create(APPLICATION_ROOT . '/data/my-index'); $mediaMapper = new Media_Model_Mapper_Media(); $select = $mediaMapper->getDbTable()->select(); $select->where('deleted != ?', 1)->where('active != ?', 0)->where('category_id IN(?)', array(2, 3, 4))->order('timestamp DESC'); $mediaItems = $mediaMapper->fetchAll($select); if (!empty($mediaItems)) { foreach ($mediaItems as $mediaItem) { $doc = new Zend_Search_Lucene_Document(); // Сохранение Name документа для того, чтобы идентифицировать его // в результатах поиска $doc->addField(Zend_Search_Lucene_Field::Text('title', strtolower($mediaItem->getName()), 'UTF-8')); // Сохранение URL документа для того, чтобы идентифицировать его // в результатах поиска $doc->addField(Zend_Search_Lucene_Field::Text('url', '/media/' . $mediaItem->getFullPath(), 'UTF-8')); // Сохранение Description документа для того, чтобы идентифицировать его // в результатах поиска // $doc->addField(Zend_Search_Lucene_Field::Text('description', strtolower($mediaItem->getSContent()),'UTF-8')); // Индексирование keyWords содержимого документа $doc->addField(Zend_Search_Lucene_Field::UnStored('keyword', strtolower($mediaItem->getMetaKeywords()), 'UTF-8')); // Индексирование содержимого документа $doc->addField(Zend_Search_Lucene_Field::UnStored('contents', strtolower($mediaItem->getContent()), 'UTF-8')); // Добавление документа в индекс $index->addDocument($doc); } } }
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); }
/** * Object constructor * * @param string $data * @param boolean $storeContent */ private function __construct($data, $storeContent) { try { $zendpdf = \Zend_Pdf::parse($data); // Store meta data properties if (isset($zendpdf->properties['Title'])) { $this->addField(\Zend_Search_Lucene_Field::UnStored('title', $zendpdf->properties['Title'])); } if (isset($zendpdf->properties['Author'])) { $this->addField(\Zend_Search_Lucene_Field::UnStored('author', $zendpdf->properties['Author'])); } if (isset($zendpdf->properties['Subject'])) { $this->addField(\Zend_Search_Lucene_Field::UnStored('subject', $zendpdf->properties['Subject'])); } if (isset($zendpdf->properties['Keywords'])) { $this->addField(\Zend_Search_Lucene_Field::UnStored('keywords', $zendpdf->properties['Keywords'])); } //TODO handle PDF 1.6 metadata Zend_Pdf::getMetadata() //do the content extraction $pdfParse = new \App_Search_Helper_PdfParser(); $body = $pdfParse->pdf2txt($zendpdf->render()); if ($body != '') { // Store contents if ($storeContent) { $this->addField(\Zend_Search_Lucene_Field::Text('body', $body, 'UTF-8')); } else { $this->addField(\Zend_Search_Lucene_Field::UnStored('body', $body, 'UTF-8')); } } } catch (\Exception $e) { Util::writeLog('search_lucene', $e->getMessage() . ' Trace:\\n' . $e->getTraceAsString(), Util::ERROR); } }
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; }
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"; }
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 />'; }
/** * 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(); }
public function testEncoding() { $field = Zend_Search_Lucene_Field::Text('field', 'Words with umlauts: εγό...', 'ISO-8859-1'); $this->assertEquals($field->encoding, 'ISO-8859-1'); $this->assertEquals($field->name, 'field'); $this->assertEquals($field->value, 'Words with umlauts: εγό...'); $this->assertEquals($field->getUtf8Value(), 'Words with umlauts: Γ₯ãü...'); }
private function __construct($fileName, $storeContent) { // Document data holders $documentBody = array(); $coreProperties = array(); // Open OpenXML package $package = new ZipArchive(); $package->open($fileName); // Read relations and search for officeDocument $relations = simplexml_load_string($package->getFromName('_rels/.rels')); foreach ($relations->Relationship as $rel) { if ($rel["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_OFFICEDOCUMENT) { // Found office document! Read in contents... $contents = simplexml_load_string($package->getFromName($this->absoluteZipPath(dirname($rel['Target']) . '/' . basename($rel['Target'])))); $contents->registerXPathNamespace('w', Zend_Search_Lucene_Document_Docx::SCHEMA_WORDPROCESSINGML); $paragraphs = $contents->xpath('//w:body/w:p'); foreach ($paragraphs as $paragraph) { $runs = $paragraph->xpath('.//w:r/*[name() = "w:t" or name() = "w:br"]'); if ($runs === false) { // Paragraph doesn't contain any text or breaks continue; } foreach ($runs as $run) { if ($run->getName() == 'br') { // Break element $documentBody[] = ' '; } else { $documentBody[] = (string) $run; } } // Add space after each paragraph. So they are not bound together. $documentBody[] = ' '; } break; } } // Read core properties $coreProperties = $this->extractMetaData($package); // Close file $package->close(); // Store filename $this->addField(Zend_Search_Lucene_Field::Text('filename', $fileName, 'UTF-8')); // Store contents if ($storeContent) { $this->addField(Zend_Search_Lucene_Field::Text('body', implode('', $documentBody), 'UTF-8')); } else { $this->addField(Zend_Search_Lucene_Field::UnStored('body', implode('', $documentBody), 'UTF-8')); } // Store meta data properties foreach ($coreProperties as $key => $value) { $this->addField(Zend_Search_Lucene_Field::Text($key, $value, 'UTF-8')); } // Store title (if not present in meta data) if (!isset($coreProperties['title'])) { $this->addField(Zend_Search_Lucene_Field::Text('title', $fileName, 'UTF-8')); } }
/** * 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())); }
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); }
public function asLuceneDocument() { $doc = new Zend_Search_Lucene_Document(); $doc->addField(Zend_Search_Lucene_Field::Text('page_title', $this->title, $this->_charset)); $doc->addField(Zend_Search_Lucene_Field::Text('page_link', $this->path, $this->_charset)); $doc->addField(Zend_Search_Lucene_Field::Text('page_teaser', $this->teaser, $this->_charset)); $doc->addField(Zend_Search_Lucene_Field::unstored('page_content', $this->content, $this->_charset)); $doc->addField(Zend_Search_Lucene_Field::UnStored('search_tags', $this->searchTags, $this->_charset)); return $doc; }
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); }
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(); }
public function __construct($fileName, $storeContent) { // Store filename $this->addField(Zend_Search_Lucene_Field::Text('filename', $fileName, 'UTF-8')); $this->_filename = $fileName; // Store contents if ($storeContent) { $this->addField(Zend_Search_Lucene_Field::Text('body', implode(' ', $this->getBody()), 'UTF-8')); } else { $this->addField(Zend_Search_Lucene_Field::UnStored('body', implode(' ', $this->getBody()), 'UTF-8')); } }
public function addFeed(Feed $feed) { $index = Zend_Search_Lucene::open(Zend_Registry::getInstance()->search->feed); $doc = new Zend_Search_Lucene_Document(); $doc->addField(Zend_Search_Lucene_Field::Text('title', $feed->title)); $doc->addField(Zend_Search_Lucene_Field::Text('siteUrl', $feed->siteUrl)); $doc->addField(Zend_Search_Lucene_Field::Text('feedUrl', $feed->url)); $doc->addField(Zend_Search_Lucene_Field::Text('language', $feed->language)); $doc->addField(Zend_Search_Lucene_Field::Text('category', $feed->category)); $doc->addField(Zend_Search_Lucene_Field::Text('title', $feed->title)); $doc->addField(Zend_Search_Lucene_Field::UnStored('description', $feed->description)); $index->addDocument($doc); }
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)); } } }
function fill_index() { for ($i = 0; $i < 10; $i++) { $index = new Zend_Search_Lucene('./data/index', true); $index->find("test"); $doc = new Zend_Search_Lucene_Document(); $doc->addField(Zend_Search_Lucene_Field::Text("test", getword())); $doc->addField(Zend_Search_Lucene_Field::UnStored("contents", getword())); $index->addDocument($doc); $index->commit(); $index->getDirectory()->close(); //comment this to see another bug :-| } }
$results = $index->find($term); $query = Zend_Search_Lucene_Search_QueryParser::parse($term); $this->render('/sParameter/search', compact('results', 'term', 'query')); } } /** * Search index creation */ public function actionCreate() { $index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles), true); $posts = tAccount::model()->findAll(); foreach ($posts as $post) { $doc = new Zend_Search_Lucene_Document(); $doc->addField(Zend_Search_Lucene_Field::Text('account_no', CHtml::encode($post->account_no), 'utf-8'));
/** * 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; }
/** * @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)); }
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(); }
/** * 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) . '&id=' . $video->id, $encoding)); return $doc; }
private function __construct($data, $isFile, $storeContent) { $this->_doc = new DOMDocument(); $this->_doc->substituteEntities = true; if ($isFile) { $htmlData = file_get_contents($data); } else { $htmlData = $data; } @$this->_doc->loadHTML($htmlData); $xpath = new DOMXPath($this->_doc); $docTitle = ''; $titleNodes = $xpath->query('/html/head/title'); foreach ($titleNodes as $titleNode) { // title should always have only one entry, but we process all nodeset entries $docTitle .= $titleNode->nodeValue . ' '; } $this->addField(Zend_Search_Lucene_Field::Text('title', $docTitle, $this->_doc->actualEncoding)); $metaNodes = $xpath->query('/html/head/meta[@name]'); foreach ($metaNodes as $metaNode) { $this->addField(Zend_Search_Lucene_Field::Text($metaNode->getAttribute('name'), $metaNode->getAttribute('content'), $this->_doc->actualEncoding)); } $docBody = ''; $bodyNodes = $xpath->query('/html/body'); foreach ($bodyNodes as $bodyNode) { // body should always have only one entry, but we process all nodeset entries $this->_retrieveNodeText($bodyNode, $docBody); } if ($storeContent) { $this->addField(Zend_Search_Lucene_Field::Text('body', $docBody, $this->_doc->actualEncoding)); } else { $this->addField(Zend_Search_Lucene_Field::UnStored('body', $docBody, $this->_doc->actualEncoding)); } $linkNodes = $this->_doc->getElementsByTagName('a'); foreach ($linkNodes as $linkNode) { if (($href = $linkNode->getAttribute('href')) != '' && (!self::$_excludeNoFollowLinks || strtolower($linkNode->getAttribute('rel')) != 'nofollow')) { $this->_links[] = $href; } } $this->_links = array_unique($this->_links); $linkNodes = $xpath->query('/html/head/link'); foreach ($linkNodes as $linkNode) { if (($href = $linkNode->getAttribute('href')) != '') { $this->_headerLinks[] = $href; } } $this->_headerLinks = array_unique($this->_headerLinks); }