Ejemplo n.º 1
0
 public function search($keywords, $charset = 'utf-8')
 {
     $index = new Zend_Search_Lucene(ZY_ROOT . '/index');
     $query = Zend_Search_Lucene_Search_QueryParser::parse($keywords, $charset);
     $hits = $index->find($query);
     return $hits;
 }
Ejemplo n.º 2
0
 /**
  * Return the document object for this hit
  *
  * @return Zend_Search_Lucene_Document
  */
 public function getDocument()
 {
     if (!$this->_document instanceof Zend_Search_Lucene_Document) {
         $this->_document = $this->_index->getDocument($this->id);
     }
     return $this->_document;
 }
 function onSearchLucene($text, $phrase = '', $ordering = '', $areas = null)
 {
     if (is_array($areas) && count($areas) > 0) {
         if (!array_intersect($areas, array_keys($this->areas))) {
             return array();
         }
     } else {
         if (count($areas) == 0) {
             $areas = array();
             foreach ($this->areas as $k => $v) {
                 $areas[] = $k;
             }
         }
     }
     $results = array();
     $params = JComponentHelper::getParams('com_search_lucene');
     $indexpath = $params->get('indexpath');
     $pluginindex = $indexpath . DS . $this->pluginName;
     $index = new Zend_Search_Lucene($pluginindex);
     $search = '(';
     foreach ($areas as $area) {
         if (array_key_exists($area, $this->areas)) {
             $search .= ' type:' . $area;
         }
     }
     $search .= ')';
     if ($index && strlen($text) > 3) {
         $rows = $index->find($text . ' AND ' . $search);
     } else {
         $rows = array();
     }
     return $rows;
 }
Ejemplo n.º 4
0
 public function __construct($path = SEARCH_INDEX_PATH)
 {
     global $CFG, $db;
     $this->path = $path;
     //test to see if there is a valid index on disk, at the specified path
     try {
         $test_index = new Zend_Search_Lucene($this->path, false);
         $validindex = true;
     } catch (Exception $e) {
         $validindex = false;
     }
     //retrieve file system info about the index if it is valid
     if ($validindex) {
         $this->size = display_size(get_directory_size($this->path));
         $index_dir = get_directory_list($this->path, '', false, false);
         $this->filecount = count($index_dir);
         $this->indexcount = $test_index->count();
     } else {
         $this->size = 0;
         $this->filecount = 0;
         $this->indexcount = 0;
     }
     $db_exists = false;
     //for now
     //get all the current tables in moodle
     $admin_tables = $db->MetaTables();
     //TODO: use new IndexDBControl class for database checks?
     //check if our search table exists
     if (in_array($CFG->prefix . SEARCH_DATABASE_TABLE, $admin_tables)) {
         //retrieve database information if it does
         $db_exists = true;
         //total documents
         $this->dbcount = count_records(SEARCH_DATABASE_TABLE);
         //individual document types
         // $types = search_get_document_types();
         $types = search_collect_searchables(true, false);
         sort($types);
         foreach ($types as $type) {
             $c = count_records(SEARCH_DATABASE_TABLE, 'doctype', $type);
             $this->types[$type] = (int) $c;
         }
     } else {
         $this->dbcount = 0;
         $this->types = array();
     }
     //check if the busy flag is set
     if (isset($CFG->search_indexer_busy) && $CFG->search_indexer_busy == '1') {
         $this->complete = false;
     } else {
         $this->complete = true;
     }
     //get the last run date for the indexer
     if ($this->valid() && $CFG->search_indexer_run_date) {
         $this->time = $CFG->search_indexer_run_date;
     } else {
         $this->time = 0;
     }
 }
Ejemplo n.º 5
0
 private function search($terms)
 {
     Yii::import('application.vendor.*');
     require_once 'Zend/Search/Lucene.php';
     $index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.index'));
     $result = $index->find($terms);
     $query = Zend_Search_Lucene_Search_QueryParser::parse($terms);
     return $result;
 }
Ejemplo n.º 6
0
 /**
  * The sum of squared weights of contained query clauses.
  *
  * @return float
  */
 public function sumOfSquaredWeights()
 {
     // compute idf
     $this->_idf = $this->_reader->getSimilarity()->idf($this->_term, $this->_reader);
     // compute query weight
     $this->_queryWeight = $this->_idf * $this->_query->getBoost();
     // square it
     return $this->_queryWeight * $this->_queryWeight;
 }
 public function generateSitemap()
 {
     $this->prepareSiteMapFolder();
     if (!is_null($this->sitemapDir)) {
         $hosts = $this->getValidHosts();
         if (is_array($hosts)) {
             foreach ($hosts as $hostName) {
                 $query = new \Zend_Search_Lucene_Search_Query_Boolean();
                 $hostTerm = new \Zend_Search_Lucene_Index_Term($hostName, 'host');
                 $hostQuery = new \Zend_Search_Lucene_Search_Query_Term($hostTerm);
                 $query->addSubquery($hostQuery, TRUE);
                 $hostTerm = new \Zend_Search_Lucene_Index_Term(TRUE, 'restrictionGroup_default');
                 $hostQuery = new \Zend_Search_Lucene_Search_Query_Term($hostTerm);
                 $query->addSubquery($hostQuery, TRUE);
                 $hits = $this->index->find($query);
                 $name = str_replace('.', '-', $hostName);
                 $filePath = $this->sitemapDir . '/sitemap-' . $name . '.xml';
                 $fh = fopen($filePath, 'w');
                 fwrite($fh, '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n");
                 fwrite($fh, '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
                 fwrite($fh, "\r\n");
                 for ($i = 0; $i < count($hits); $i++) {
                     $url = $hits[$i]->getDocument()->getField('url');
                     $uri = str_replace(array('?pimcore_outputfilters_disabled=1', '&pimcore_outputfilters_disabled=1'), '', $url->value);
                     fwrite($fh, '<url>' . "\r\n");
                     fwrite($fh, '    <loc>' . htmlspecialchars($uri, ENT_QUOTES) . '</loc>' . "\r\n");
                     fwrite($fh, '</url>' . "\r\n");
                 }
                 fwrite($fh, '</urlset>' . "\r\n");
                 fclose($fh);
             }
             $filePath = $this->sitemapDir . '/sitemap.xml';
             $fh = fopen($filePath, 'w');
             fwrite($fh, '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n");
             fwrite($fh, '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
             fwrite($fh, "\r\n");
             foreach ($hosts as $hostName) {
                 $name = str_replace('.', '-', $hostName);
                 //first host must be main domain - see hint in plugin settings
                 $currenthost = $hosts[0];
                 fwrite($fh, '<sitemap>' . "\r\n");
                 fwrite($fh, '    <loc>http://' . $currenthost . '/plugin/LuceneSearch/frontend/sitemap/?sitemap=sitemap-' . $name . '.xml' . '</loc>' . "\r\n");
                 fwrite($fh, '</sitemap>' . "\r\n");
                 \Pimcore\Logger::debug('LuceneSearch: ' . $hostName . ' for sitemap.xml added.');
             }
             fwrite($fh, '</sitemapindex>' . "\r\n");
             fclose($fh);
         } else {
             \Pimcore\Logger::debug('LuceneSearch: could not generate sitemaps, did not find any hosts in index.');
         }
     } else {
         \Pimcore\Logger::emerg('LuceneSearch: Cannot generate sitemap. Sitemap directory [ ' . $this->sitemapDir . ' ]  not available/not writeable and cannot be created');
     }
 }
 public function actionSearch()
 {
     //working.
     $this->layout = 'column2';
     if (($term = Yii::app()->getRequest()->getParam('q', null)) !== null) {
         Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
         $index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles));
         $results = $index->find($term);
         $query = Zend_Search_Lucene_Search_QueryParser::parse($term);
         $this->render('search', compact('results', 'term', 'query'));
     }
 }
Ejemplo n.º 9
0
 public function actionSearch()
 {
     $indexFiles = Yii::app()->getModule('zendsearch')->indexFiles;
     SetLocale(LC_ALL, 'ru_RU.UTF-8');
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('UTF-8');
     if (($term = Yii::app()->getRequest()->getQuery('q', null)) !== null) {
         $index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $indexFiles));
         $results = $index->find($term);
         $query = Zend_Search_Lucene_Search_QueryParser::parse($term);
         $this->render('search', compact('results', 'term', 'query'));
     }
 }
Ejemplo n.º 10
0
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'));
Ejemplo n.º 12
0
 function search($query)
 {
     $this->load->library('zend', 'Zend/Search/Lucene');
     $this->load->library('zend');
     $this->zend->load('Zend/Search/Lucene');
     $index = new Zend_Search_Lucene('C:\\xampp\\xampp\\htdocs\\controle_frota\\lucene\\feeds_index');
     $hits = $index->find($query);
     echo 'Index contains ' . $index->count() . ' documents.<br /><br />';
     echo 'Search for "' . $query . '" returned ' . count($hits) . ' hits<br /><br />';
     foreach ($hits as $hit) {
         echo $hit->title . '<br />';
         echo 'Score: ' . sprintf('%.2f', $hit->score) . '<br />';
         echo $hit->link . '<br /><br />';
     }
 }
Ejemplo n.º 13
0
 private function getLucene()
 {
     if ($this->lucene) {
         return $this->lucene;
     }
     try {
         $this->lucene = Zend_Search_Lucene::open($this->directory);
     } catch (Zend_Search_Lucene_Exception $e) {
         $this->lucene = Zend_Search_Lucene::create($this->directory);
     }
     global $prefs;
     if (!empty($prefs['unified_lucene_max_buffered_docs'])) {
         // these break indexing if set empty
         $this->lucene->setMaxBufferedDocs($prefs['unified_lucene_max_buffered_docs']);
         // default is 10
     }
     if (!empty($prefs['unified_lucene_max_merge_docs'])) {
         $this->lucene->setMaxMergeDocs($prefs['unified_lucene_max_merge_docs']);
         // default is PHP_INT_MAX (effectively "infinite")
     }
     if (!empty($prefs['unified_lucene_merge_factor'])) {
         $this->lucene->setMergeFactor($prefs['unified_lucene_merge_factor']);
         // default is 10
     }
     $this->lucene->setResultSetLimit($this->resultSetLimit);
     return $this->lucene;
 }
Ejemplo n.º 14
0
 /**
  * Enter description here...
  *
  * @param string $query
  * @return array
  */
 public function query($query)
 {
     $results = array();
     $queryDiscussion = stripos($query, 'discussion') !== false;
     $queryContent = stripos($query, 'content') !== false;
     $query = Zend_Search_Lucene_Search_QueryParser::parse($query);
     $hits = $this->lucene->find($query);
     foreach ($hits as $hit) {
         $document = $hit->getDocument();
         $document_id = PHPLuceneIndexer::stringToLong($document->DocumentID);
         $coreText = '';
         if ($queryContent) {
             $coreText .= $document->Content;
         }
         if ($queryDiscussion) {
             $coreText .= $document->Discussion;
         }
         $content = $query->highlightMatches($coreText);
         $title = $document->Title;
         $score = $hit->score;
         // avoid adding duplicates. If it is in already, it has higher priority.
         if (!array_key_exists($document_id, $results) || $score > $results[$document_id]->Score) {
             $item = new QueryResultItem($document_id, $score, $title, $content);
             if ($item->CanBeReadByUser) {
                 $results[$document_id] = $item;
             }
         }
     }
     return $results;
 }
Ejemplo n.º 15
0
 protected function initLuceneEngine()
 {
     $this->load->library('zend', 'Zend/Search/Lucene');
     $this->load->library('zend');
     $this->zend->load('Zend/Search/Lucene');
     Zend_Search_Lucene::setDefaultSearchField('content');
 }
Ejemplo n.º 16
0
 public function luceneSearchAction()
 {
     $this->view->layout()->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $path = PUBLIC_PATH . '/tmp/lucene';
     $index = Zend_Search_Lucene::open($path);
     //        $term  = new Zend_Search_Lucene_Index_Term('ritesh','title');
     //        $subquery1 = new Zend_Search_Lucene_Search_Query_Term($term);
     //
     //        $from = new Zend_Search_Lucene_Index_Term('0', 'empcode');
     //        $to   = new Zend_Search_Lucene_Index_Term('53', 'empcode');
     //        $subquery2 = new Zend_Search_Lucene_Search_Query_Range($from, $to, true);
     //
     //        $query = new Zend_Search_Lucene_Search_Query_Boolean();
     //        $query->addSubquery($subquery1, true  );
     //        $query->addSubquery($subquery2, null );
     //        Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
     //        $hits  = $index->find($query);
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
     Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(1);
     $hits = $index->find("empcode:[000 TO 200]");
     foreach ($hits as $h) {
         echo "Title:" . $h->title;
         echo "-------EmpCode:" . $h->empcode;
         echo "<br>";
     }
 }
Ejemplo n.º 17
0
 public function buildAction()
 {
     // create the index
     $index = Zend_Search_Lucene::create(APPLICATION_PATH . '/indexes');
     // fetch all of the current pages
     $mdlPage = new Model_Page();
     $currentPages = $mdlPage->fetchAll();
     if ($currentPages->count() > 0) {
         // create a new search document for each page
         foreach ($currentPages as $p) {
             $page = new CMS_Content_Item_Page($p->id);
             $doc = new Zend_Search_Lucene_Document();
             // you use an unindexed field for the id because you want the id to be
             // included in the search results but not searchable
             $doc->addField(Zend_Search_Lucene_Field::unIndexed('page_id', $page->id));
             // you use text fields here because you want the content to be searchable
             // and to be returned in search results
             $doc->addField(Zend_Search_Lucene_Field::text('page_name', $page->name));
             $doc->addField(Zend_Search_Lucene_Field::text('page_headline', $page->headline));
             $doc->addField(Zend_Search_Lucene_Field::text('page_description', $page->description));
             $doc->addField(Zend_Search_Lucene_Field::text('page_content', $page->content));
             // add the document to the index
             $index->addDocument($doc);
         }
     }
     // optimize the index
     $index->optimize();
     // pass the view data for reporting
     $this->view->indexSize = $index->numDocs();
 }
Ejemplo n.º 18
0
 /**
  * Creates a new ZendLucene handler connection
  *
  * @param string $location
  */
 public function __construct($location)
 {
     /**
      * We're using realpath here because Zend_Search_Lucene does not do
      * that itself. It can cause issues because their destructor uses the
      * same filename but the cwd could have been changed.
      */
     $location = realpath($location);
     /* If the $location doesn't exist, ZSL throws a *generic* exception. We
      * don't care here though and just always assume it is because the
      * index does not exist. If it doesn't exist, we create it.
      */
     try {
         $this->connection = Zend_Search_Lucene::open($location);
     } catch (Zend_Search_Lucene_Exception $e) {
         $this->connection = Zend_Search_Lucene::create($location);
     }
     $this->inTransaction = 0;
     if (!$this->connection) {
         throw new ezcSearchCanNotConnectException('zendlucene', $location);
     }
     // Set proper default encoding for query parser
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('UTF-8');
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
 }
Ejemplo n.º 19
0
 public function searchAction()
 {
     Zend_Registry::set('theaction', 'content');
     $this->toTpl('theInclude', 'list');
     Zend_Registry::set('module', 'Search Results');
     //error_reporting(E_ALL);
     $data = $this->_request->getParams();
     if (trim($data['q'])) {
         $dirs = $this->dirs;
         $word = strtolower($data['q']);
         $index = new Zend_Search_Lucene(APPL_PATH . $dirs['structure']['indexes'] . DIR_SEP . "objects");
         $exp = explode(" ", $word);
         $query = new Zend_Search_Lucene_Search_Query_Phrase($exp);
         $query->setSlop(2);
         //get all available indexed
         Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
         Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
         Zend_Search_Lucene::setResultSetLimit(10);
         $result = $index->find($query);
         foreach ($result as $hit) {
             $obj = $this->getAllBySlug($hit->slug);
             $type = $this->getContentType($obj['type_id']);
             $content = $this->getContent($type['title'], $obj['id']);
             $resu[] = $content;
         }
         $resu = $this->doQoolHook('front_pre_assign_search_results', $resu);
         $this->toTpl('content', $resu);
     } else {
         $params = array("message" => $this->t("Please fill in a search term"), "msgtype" => 'error');
         $this->addMessage($params);
         $this->_helper->redirector('index', 'index', 'default');
     }
 }
Ejemplo n.º 20
0
 public function buildplaces()
 {
     ini_set('memory_limit', '1000M');
     set_time_limit(0);
     $time = time();
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
     /**
      * Create index
      */
     $index = Zend_Search_Lucene::create($this->_indexPath);
     /**
      * Get all users
      */
     $sql = $this->_db->select()->from($this->_name, array('id', 'name', 'placepic'))->limit(7500);
     $result = $this->_db->fetchAssoc($sql);
     foreach ($result as $values) {
         $doc = new Zend_Search_Lucene_Document();
         $doc->addField(Zend_Search_Lucene_Field::keyword('placeid', $values['id']));
         $doc->addField(Zend_Search_Lucene_Field::text('placename', $values['name']));
         $doc->addField(Zend_Search_Lucene_Field::unStored('placepic', $values['placepic']));
         $index->addDocument($doc);
     }
     $index->commit();
     $elapsed = time() - $time;
     print_r($elapsed);
 }
Ejemplo n.º 21
0
 /**
  * Build the post search index
  * 
  * @param boolean $isCount
  * @return boolean
  */
 protected function buildPostSearch($isCount = false)
 {
     $index = Zend_Search_Lucene::create(Zend_Registry::getInstance()->config->search->post);
     require_once 'Ifphp/models/Posts.php';
     require_once 'Ifphp/models/Feeds.php';
     require_once 'Ifphp/models/Categories.php';
     $posts = new Posts();
     $allPosts = $posts->getRecent(1, 0);
     if ($isCount) {
         echo $allPosts->count() . ' posts would have been added to the post index';
         exit;
     }
     foreach ($allPosts as $post) {
         $feed = $post->findParentFeeds();
         $doc = new Zend_Search_Lucene_Document();
         $doc->addField(Zend_Search_Lucene_Field::Text('pid', $post->id));
         $doc->addField(Zend_Search_Lucene_Field::Text('title', $post->title));
         $doc->addField(Zend_Search_Lucene_Field::Text('siteUrl', $post->siteUrl));
         $doc->addField(Zend_Search_Lucene_Field::Text('link', $post->link));
         $doc->addField(Zend_Search_Lucene_Field::Text('feedTitle', $feed->title));
         $doc->addField(Zend_Search_Lucene_Field::Text('feedSlug', $feed->slug));
         $doc->addField(Zend_Search_Lucene_Field::Text('feedDescription', $feed->description));
         $doc->addField(Zend_Search_Lucene_Field::keyword('category', $feed->findParentCategories()->title));
         $doc->addField(Zend_Search_Lucene_Field::Text('description', $post->description));
         $doc->addField(Zend_Search_Lucene_Field::unIndexed('publishDate', $post->publishDate));
         $doc->addField(Zend_Search_Lucene_Field::Keyword('type', 'post'));
         $index->addDocument($doc);
     }
     chown(Zend_Registry::getInstance()->search['post'], 'www-data');
     return true;
 }
Ejemplo n.º 22
0
 /**
  * Creates a new ZendLucene handler connection
  *
  * @param string $location
  */
 public function __construct($location)
 {
     $this->connection = Zend_Search_Lucene::create($location);
     $this->inTransaction = 0;
     if (!$this->connection) {
         throw new ezcSearchCanNotConnectException('zendlucene', $location);
     }
 }
Ejemplo n.º 23
0
 /**
  * Creates a new Lucene index.
  * 
  * @param	string	name
  * @param	array	fields
  * @return	Lucene
  */
 public static function create($name, $fields)
 {
     $luceneID = self::insert($name);
     $luceneObj = new Lucene($luceneID);
     $luceneObj->getEditor()->addField($fields);
     Zend_Search_Lucene::create(LW_DIR . 'lucene/' . $name);
     return $luceneObj;
 }
Ejemplo n.º 24
0
 public static function getLuceneIndex()
 {
     ProjectConfiguration::registerZend();
     if (file_exists($index = self::getLuceneIndexFile())) {
         return Zend_Search_Lucene::open($index);
     }
     return Zend_Search_Lucene::create($index);
 }
Ejemplo n.º 25
0
 /**
  * @param $path
  * @return \Zend_Search_Lucene_Interface|null
  */
 public function getIndex($path)
 {
     try {
         return Search::open($path);
     } catch (SearchException $e) {
         error_log($e->getMessage());
         return null;
     }
 }
Ejemplo n.º 26
0
 public function searchTag($tag, $value)
 {
     if (!$this->_enabled) {
         return array();
     }
     Zend_Search_Lucene::setDefaultSearchField($tag);
     $query = Zend_Search_Lucene_Search_QueryParser::parse($value);
     return $this->_index->find($query);
 }
 function onSearchLucene($text, $phrase = '', $ordering = '', $areas = null)
 {
     if (is_array($areas) && count($areas) > 0) {
         if (!array_intersect($areas, array_keys($this->areas))) {
             return array();
         }
     }
     $params = JComponentHelper::getParams('com_search_lucene');
     $indexpath = $params->get('indexpath');
     $pluginindex = $indexpath . DS . $this->pluginName;
     $index = new Zend_Search_Lucene($pluginindex);
     if ($index) {
         $rows = $index->find($text);
     } else {
         $rows = array();
     }
     return $rows;
 }
Ejemplo n.º 28
0
 public function indexAction()
 {
     if (is_file(TEMP_PATH . '/Search/write.lock.file')) {
         $_indexHandle = Zend_Search_Lucene::open(TEMP_PATH . '/Search');
     } else {
         $_indexHandle = Zend_Search_Lucene::create(TEMP_PATH . '/Search');
     }
     $this->view->count = intval($_indexHandle->maxDoc());
 }
Ejemplo n.º 29
0
 public static function buildIndex()
 {
     Zend_Registry::get('LOG')->log("--------------------------------", Zend_Log::NOTICE);
     Zend_Registry::get('LOG')->log("", Zend_Log::NOTICE);
     $articles_index = Uni_Search::articlesIndex();
     if (!file_exists($articles_index)) {
         Zend_Registry::get('LOG')->log("Creating index: {$articles_index}", Zend_Log::NOTICE);
         $index = Zend_Search_Lucene::create($articles_index);
     } else {
         Zend_Registry::get('LOG')->log("Updating index: {$articles_index}", Zend_Log::NOTICE);
         $index = Zend_Search_Lucene::open($articles_index);
         // Clear index
         Zend_Registry::get('LOG')->log("Clearing index", Zend_Log::NOTICE);
         $pattern = new Zend_Search_Lucene_Index_Term('*', 'title');
         $query = new Zend_Search_Lucene_Search_Query_Wildcard($pattern);
         $hits = $index->find($query);
         foreach ($hits as $hit) {
             $index->delete($hit->id);
         }
     }
     Zend_Registry::get('LOG')->log("Loading Articles", Zend_Log::NOTICE);
     $table = Zend_Registry::get('DOCTRINE_CONNECTION')->getTable('Article');
     $articles = $table->findAll();
     foreach ($articles as $article) {
         Zend_Registry::get('LOG')->log("  Adding article to index: {$article->title}", Zend_Log::NOTICE);
         $doc = Uni_Search::createDocFromArticle($article);
         $index->addDocument($doc);
     }
     Zend_Registry::get('LOG')->log("", Zend_Log::NOTICE);
     Zend_Registry::get('LOG')->log("--------------------------------", Zend_Log::NOTICE);
     $tips_index = Uni_Search::tipsIndex();
     if (!file_exists($tips_index)) {
         Zend_Registry::get('LOG')->log("Creating index: {$tips_index}", Zend_Log::NOTICE);
         $index = Zend_Search_Lucene::create($tips_index);
     } else {
         Zend_Registry::get('LOG')->log("Updating index: {$tips_index}", Zend_Log::NOTICE);
         $index = Zend_Search_Lucene::open($tips_index);
         // Clear index
         Zend_Registry::get('LOG')->log("Clearing index", Zend_Log::NOTICE);
         $pattern = new Zend_Search_Lucene_Index_Term('*', 'title');
         $query = new Zend_Search_Lucene_Search_Query_Wildcard($pattern);
         $hits = $index->find($query);
         foreach ($hits as $hit) {
             $index->delete($hit->id);
         }
     }
     Zend_Registry::get('LOG')->log("Loading Tips", Zend_Log::NOTICE);
     $table = Zend_Registry::get('DOCTRINE_CONNECTION')->getTable('Tip');
     $tips = $table->findAll();
     foreach ($tips as $tip) {
         Zend_Registry::get('LOG')->log("  Adding tip to index: {$tip->title}", Zend_Log::NOTICE);
         $index->addDocument(Uni_Search::createDocFromTip($tip));
     }
     Zend_Registry::get('LOG')->log("", Zend_Log::NOTICE);
     Zend_Registry::get('LOG')->log("--------------------------------", Zend_Log::NOTICE);
 }
Ejemplo n.º 30
0
 public static function getInstances()
 {
     $ret = array();
     foreach (new DirectoryIterator('cache/fulltext') as $i) {
         if ($i->isDir() && !$i->isDot()) {
             $ret[$i->getFilename()] = Zend_Search_Lucene::open('cache/fulltext/' . $i->getFilename());
         }
     }
     return $ret;
 }