Example #1
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());
 }
Example #2
0
 /**
  * Construct, create index
  *
  * @param string $indexPath[optional]
  * @param string $encoding[optional]
  * @throws Axis_Exception
  */
 public function __construct(array $params)
 {
     $encoding = $this->_encoding;
     $indexPath = array_shift($params);
     if (count($params)) {
         $encoding = array_shift($params);
     }
     if (null === $indexPath) {
         $site = Axis::getSite()->id;
         $locale = Axis::single('locale/language')->find(Axis_Locale::getLanguageId())->current()->locale;
         $indexPath = Axis::config()->system->path . '/var/index/' . $site . '/' . $locale;
     }
     if (!is_readable($indexPath)) {
         throw new Axis_Exception(Axis::translate('search')->__('Please, update search indexes, to enable search functionality'));
     }
     /*
     $mySimilarity = new Axis_Similarity();
     Zend_Search_Lucene_Search_Similarity::setDefault($mySimilarity);
     */
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding($encoding);
     // add filter by words
     $stopWords = array('a', 'an', 'at', 'the', 'and', 'or', 'is', 'am');
     $stopWordsFilter = new Zend_Search_Lucene_Analysis_TokenFilter_StopWords($stopWords);
     $analyzer = new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive();
     $analyzer->addFilter($stopWordsFilter);
     Zend_Search_Lucene_Analysis_Analyzer::setDefault($analyzer);
     $this->_index = Zend_Search_Lucene::open($indexPath);
     $this->_encoding = $encoding;
 }
Example #3
0
 public function resultAction()
 {
     if ($this->getRequest()->isGet()) {
         $page = $this->getRequest()->getParam('page') ? $this->getRequest()->getParam('page') : 1;
         $limit = 5;
         switch (strtolower($this->getRequest()->getParam('type'))) {
             case 'blog':
                 $index = Zend_Search_Lucene::open(Zend_Registry::getInstance()->config->search->feed);
                 break;
             default:
             case 'post':
                 $index = Zend_Search_Lucene::open(Zend_Registry::getInstance()->config->search->post);
                 break;
                 /*
                       require_once 'Zend/Search/Lucene/MultiSearcher.php';
                       $index = new Zend_Search_Lucene_Interface_MultiSearcher();
                       $index->addIndex(Zend_Search_Lucene::open(Zend_Registry::getInstance()->config->search->post));
                       $index->addIndex(Zend_Search_Lucene::open(Zend_Registry::getInstance()->config->search->feed));
                   break;
                 *
                 */
         }
         $this->view->term = $this->getRequest()->getParam('term');
         //todo filter term
         $this->view->results = $index->find($this->view->term);
         $this->view->paginator = Zend_Paginator::factory($this->view->results);
         $this->view->paginator->setCurrentPageNumber($page);
         $this->view->paginator->setItemCountPerPage($limit);
     }
 }
Example #4
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;
 }
Example #5
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>";
     }
 }
Example #6
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);
 }
 public function init()
 {
     if (is_file(TEMP_PATH . '/Search/write.lock.file')) {
         $this->_indexHandle = Zend_Search_Lucene::open(TEMP_PATH . '/Search');
     } else {
         $this->_indexHandle = Zend_Search_Lucene::create(TEMP_PATH . '/Search');
     }
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
 }
 /**
  * @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;
     }
 }
 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());
 }
Example #10
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);
 }
Example #11
0
 public function __construct(array $config)
 {
     if (isset($config['search'])) {
         try {
             $this->_index = Zend_Search_Lucene::open($config['search']['indexPath']);
         } catch (Zend_Search_Lucene_Exception $e) {
             $this->_index = Zend_Search_Lucene::create($config['search']['indexPath']);
         }
     }
 }
 /**
  * Initialise a writable database for updating the index
  * 
  * @param int flag allow setting the DB to be initialised with PluginSearchInterface::INIT_DB
  */
 public function open_writable_database($flag = 0)
 {
     Zend_Search_Lucene::setResultSetLimit(50);
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
     if (PluginSearchInterface::INIT_DB == $flag) {
         $this->_index = Zend_Search_Lucene::create($this->_index_path);
     } else {
         $this->_index = Zend_Search_Lucene::open($this->_index_path);
     }
 }
Example #13
0
 public function searchAction()
 {
     if ($this->_request->isPost() && Digitalus_Filter_Post::has('submitSearchForm')) {
         $index = Zend_Search_Lucene::open('./application/modules/search/data/index');
         $queryString = Digitalus_Filter_Post::get('keywords');
         $query = Zend_Search_Lucene_Search_QueryParser::parse($queryString);
         $this->view->searchResults = $index->find($query);
         $this->view->keywords = $queryString;
     }
 }
Example #14
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;
 }
Example #15
0
 public static function getLuceneIndex()
 {
     ProjectConfiguration::registerZend();
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
     if (file_exists($index = self::getLuceneIndexFile())) {
         return Zend_Search_Lucene::open($index);
     } else {
         return Zend_Search_Lucene::create($index);
     }
 }
Example #16
0
	/**
	 * Returns the search index
	 *
	 * @return Zend_Search_Lucene_Interface
	 */
	static function GetIndex(){
		if (!self::$index) {
			try {
				self::$index = Zend_Search_Lucene::open(SEARCH_DB_PATH);
			} catch (Exception $err) {
				self::$index = new Zend_Search_Lucene(SEARCH_DB_PATH, true); 
			}
		}
		return self::$index;
	}
Example #17
0
 /**
  * Open Lucene
  *
  * @return void
  **/
 private function open()
 {
     if ($this->lucene == null) {
         try {
             $this->lucene = Zend_Search_Lucene::open($this->cache_path . 'search-unleashed');
         } catch (Zend_Search_Lucene_Exception $e) {
             return false;
         }
     }
     return $this->lucene;
 }
Example #18
0
 public function getIndex()
 {
     if (!$this->_index) {
         $index = sfConfig::get('sf_data_dir') . '/sympal_' . sfConfig::get('sf_environment') . '_search.index';
         if (file_exists($index)) {
             $this->_index = Zend_Search_Lucene::open($index);
         } else {
             $this->_index = Zend_Search_Lucene::create($index);
         }
     }
     return $this->_index;
 }
Example #19
0
 function result()
 {
     $data['results'] = array();
     // falls der "search_query"-Parameter übergeben wurde Suche ausführen
     if ($this->input->post('search_query')) {
         // Index analysieren; Suchergebnisse auslesen
         $index = Zend_Search_Lucene::open($this->search_index);
         $data['results'] = $index->find(htmlentities($this->input->post('search_query')));
     }
     // View mit Suchergebnissen anzeigen
     $this->load->view('frontend/searchengine/searchresults', $data);
 }
 /**
  * The default action - show the home page
  */
 public function indexAction()
 {
     $query = $this->getRequest()->getParam('q');
     if ($query) {
         $index = Zend_Search_Lucene::open('../lucene/index');
         $hits = $index->find($query);
         $this->view->query = $query;
         if (!empty($hits)) {
             $this->view->results = $hits;
         }
     }
 }
Example #21
0
 public function indexAction()
 {
     $request = $this->getRequest();
     $q = trim($request->getQuery('q'));
     $search = array('performed' => false, 'limit' => 5, 'total' => 0, 'start' => 0, 'finish' => 0, 'page' => (int) $request->getQuery('p'), 'pages' => 1, 'result' => array());
     try {
         if (strlen($q) == 0) {
             throw new Exception('No search term specified');
         }
         $path = DatabaseObject_BlogPost::getIndexFullpath();
         $index = Zend_Search_Lucene::open($path);
         $hits = $index->find($q);
         $search['performed'] = true;
         $search['total'] = count($hits);
         $search['pages'] = ceil($search['total'] / $search['limit']);
         $search['page'] = max(1, min($search['pages'], $search['page']));
         $offset = ($search['page'] - 1) * $search['limit'];
         $search['start'] = $offset + 1;
         $search['finish'] = min($search['total'], $search['start'] + $search['limit'] - 1);
         $hits = array_slice($hits, $offset, $search['limit']);
         $post_ids = array();
         foreach ($hits as $hit) {
             $post_ids[] = (int) $hit->post_id;
         }
         $options = array('status' => DatabaseObject_BlogPost::STATUS_LIVE, 'post_id' => $post_ids);
         $posts = DatabaseObject_BlogPost::GetPosts($this->db, $options);
         foreach ($post_ids as $post_id) {
             if (array_key_exists($post_id, $posts)) {
                 $search['results'][$post_id] = $posts[$post_id];
             }
         }
         $user_ids = array();
         foreach ($posts as $post) {
             $user_ids[$post->user_id] = $post->user_id;
         }
         if (count($user_ids) > 0) {
             $options = array('user_id' => $user_ids);
             $users = DatabaseObject_User::GetUsers($this->db, $options);
         } else {
             $users = array();
         }
     } catch (Exception $ex) {
         $users = array();
     }
     if ($search['performed']) {
         $this->breadcrumbs->addStep('Search Results for ' . $q);
     } else {
         $this->breadcrumbs->addStep('Search');
     }
     $this->view->q = $q;
     $this->view->search = $search;
     $this->view->users = $users;
 }
Example #22
0
 /**
  * open index
  */
 public function openIndex()
 {
     $profile = $this->getProfile();
     // Open existing index
     try {
         $index = Zend_Search_Lucene::open($profile['path']);
     } catch (Exception $e) {
         msg("cannot open index", 'error');
         $index = false;
     }
     return $index;
 }
Example #23
0
 public function searchAction()
 {
     $query = $this->getRequest()->getParam('q');
     if ($query) {
         $qo = Zend_Search_Lucene_Search_QueryParser::parse($query);
         $options = $this->getInvokeArg('bootstrap')->getOption('lucene');
         $luceneDir = $options['dir'];
         $index = Zend_Search_Lucene::open($luceneDir);
         $results = $index->find($query);
         $this->view->matches = $results;
         $this->view->query = $qo;
     }
 }
Example #24
0
 public function getResults(Zend_Controller_Request_Http $request)
 {
     $this->setTemplate('searchlucene/result.phtml');
     $query = $request->getParam('q', false);
     $queryEscaped = htmlspecialchars($query);
     Mage::app()->getFrontController()->getAction()->getLayout()->getBlock('head.meta')->setTitle(Mage::helper('searchlucene')->__('Search results for: %s', $queryEscaped));
     $var = Mage::getBaseDir('var');
     $index_dir = $var . DS . 'search' . DS . 'index';
     $index = Zend_Search_Lucene::open($index_dir);
     $hits = $index->find($query);
     $this->assign('hits', $hits);
     $this->assign('query', $queryEscaped);
 }
Example #25
0
 public function indexAction()
 {
     if ($this->_request->isPost()) {
         $keywords = $this->_request->getParam('keywords');
         $query = Zend_Search_Lucene_Search_QueryParser::parse($keywords);
         $index = Zend_Search_Lucene::open(APPLICATION_PATH . '/indexes');
         $hits = $index->find($query);
         $this->view->results = $hits;
         $this->view->keywords = $keywords;
     } else {
         $this->view->results = null;
     }
 }
Example #26
0
 protected function createLuceneIndex()
 {
     if (file_exists(dmOs::join($this->getFullPath(), 'segments.gen'))) {
         try {
             $this->luceneIndex = Zend_Search_Lucene::open($this->getFullPath());
             $this->luceneIndex->setFormatVersion(Zend_Search_Lucene::FORMAT_2_3);
         } catch (Zend_Search_Lucene_Exception $e) {
             $this->erase();
         }
     } else {
         $this->luceneIndex = Zend_Search_Lucene::create($this->getFullPath());
     }
 }
Example #27
0
 public function __construct($indexDir = null)
 {
     if (empty($indexDir)) {
         throw new Zend_Exception('Index Directory can not be empty!');
     }
     try {
         $indexDir = KUTU_ROOT_DIR . $indexDir;
         $this->_index = Zend_Search_Lucene::open($indexDir);
     } catch (Exception $e) {
         $this->_index = Zend_Search_Lucene::create($indexDir);
     }
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
 }
Example #28
0
 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);
 }
Example #29
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $dataPath = DATA_PATH . '/search';
     if (!is_writable(DATA_PATH)) {
         die('The directory ' . DATA_PATH . ' is not writable');
     }
     try {
         $this->_data = Zend_Search_Lucene::open($dataPath);
     } catch (Exception $error) {
         $this->_data = Zend_Search_Lucene::create($dataPath);
     }
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
 }
Example #30
0
 public function __construct($indexDir = null)
 {
     if (empty($indexDir)) {
         $registry = Zend_Registry::getInstance();
         $conf = $registry->get('config');
         $indexDir = KUTU_ROOT_DIR . $conf->indexing->dir;
     }
     try {
         $this->_index = Zend_Search_Lucene::open($indexDir);
     } catch (Exception $e) {
         $this->_index = Zend_Search_Lucene::create($indexDir);
     }
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
 }