/**
  * Returns Zend_Search_Lucene instance for given subroot
  *
  * every subroot has it's own instance
  *
  * @param Kwf_Component_Data for this index
  * @return Zend_Search_Lucene_Interface
  */
 public static function getInstance(Kwf_Component_Data $subroot)
 {
     while ($subroot) {
         if (Kwc_Abstract::getFlag($subroot->componentClass, 'subroot')) {
             break;
         }
         $subroot = $subroot->parent;
     }
     if (!$subroot) {
         $subroot = Kwf_Component_Data_Root::getInstance();
     }
     static $instance = array();
     if (!isset($instance[$subroot->componentId])) {
         $analyzer = new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive();
         $analyzer->addFilter(new Zend_Search_Lucene_Analysis_TokenFilter_ShortWords(2));
         //$stopWords = explode(' ', 'der dir das einer eine ein und oder doch ist sind an in vor nicht wir ihr sie es ich');
         //$analyzer->addFilter(new Zend_Search_Lucene_Analysis_TokenFilter_StopWords($stopWords));
         Zend_Search_Lucene_Analysis_Analyzer::setDefault($analyzer);
         Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
         Zend_Search_Lucene_Storage_Directory_Filesystem::setDefaultFilePermissions(0666);
         $path = 'cache/fulltext';
         $path .= '/' . $subroot->componentId;
         try {
             $instance[$subroot->componentId] = Zend_Search_Lucene::open($path);
         } catch (Zend_Search_Lucene_Exception $e) {
             $instance[$subroot->componentId] = Zend_Search_Lucene::create($path);
         }
     }
     return $instance[$subroot->componentId];
 }
Exemple #2
0
 public function __construct()
 {
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
     //set default encoding
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_CJK());
     //set default Analyzer
 }
 /**
  * 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());
 }
Exemple #4
0
 public function __construct()
 {
     $this->_log()->info('Starting up');
     if (@preg_match('/\\pL/u', 'a') != 1) {
         $this->_log()->err("PCRE unicode support is turned off.\n");
     }
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding($this->_encoding);
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
 }
Exemple #5
0
 public function __construct()
 {
     try {
         parent::__construct(new Zend_Search_Lucene(self::INDEX_DIR, false));
     } catch (Zend_Search_Lucene_Exception $e) {
         parent::__construct(new Zend_Search_Lucene(self::INDEX_DIR, true));
     }
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding("UTF-8");
 }
Exemple #6
0
 public static function renewIndex($forceCreate = false)
 {
     $pages = Application_Model_Mappers_PageMapper::getInstance()->getPagesForSearchIndex();
     if (!is_array($pages)) {
         return false;
     }
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('UTF-8');
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
     self::removeIndex() && self::initIndex();
     array_walk($pages, array('Tools_Search_Tools', 'addPageToIndex'));
     self::$_index->optimize();
 }
 public static function registerZend()
 {
     if (self::$zendLoaded) {
         return;
     }
     set_include_path(sfConfig::get('sf_lib_dir') . '/vendor' . PATH_SEPARATOR . get_include_path());
     require_once sfConfig::get('sf_lib_dir') . '/vendor/Zend/Loader/Autoloader.php';
     Zend_Loader_Autoloader::getInstance();
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
     self::$zendLoaded = true;
 }
Exemple #8
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'));
     }
 }
Exemple #9
0
 function __construct($directory, $lang = 'en', $highlight = true)
 {
     switch ($lang) {
         case 'en':
         default:
             Zend_Search_Lucene_Analysis_Analyzer::setDefault(new StandardAnalyzer_Analyzer_Standard_English());
             Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('UTF-8');
     }
     Zend_Search_Lucene_Storage_Directory_Filesystem::setDefaultFilePermissions(0660);
     $this->directory = $directory;
     $this->lastModif = file_exists($directory) ? filemtime($directory) : 0;
     $this->highlight = (bool) $highlight;
 }
Exemple #10
0
 /**
  * Constructor method.
  */
 function SiteSearch()
 {
     if (!@file_exists($this->path . '/segments')) {
         $this->client = new Zend_Search_Lucene($this->path, true);
     } else {
         $this->client = new Zend_Search_Lucene($this->path);
     }
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
     ini_set('iconv.input_encoding', 'utf-8');
     ini_set('iconv.internal_encoding', 'utf-8');
     ini_set('iconv.output_encoding', 'utf-8');
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
     umask(00);
 }
Exemple #11
0
 /**
  * 
  * @return Zend_Search_Lucene_Interface
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         $indexDir = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'lucene';
         Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
         Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
         try {
             $index = Zend_Search_Lucene::open($indexDir);
         } catch (Exception $e) {
             $index = Zend_Search_Lucene::create($indexDir);
         }
         self::$_instance = $index;
     }
     return self::$_instance;
 }
 public function __construct($config)
 {
     $this->indexFile = $config['indexFile'];
     $this->__setSources($config['source']);
     $this->indexDirectory = TMP;
     if (!empty($config['indexDirectory'])) {
         $this->indexDirectory = $config['indexDirectory'];
     }
     $this->__loadIndex($this->indexDirectory . $this->indexFile);
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding(strtolower(Configure::read('App.encoding')));
     if (!empty($config['analyzer'])) {
         Zend_Search_Lucene_Analysis_Analyzer::setDefault(new $config['analyzer']());
     }
     parent::__construct($config);
 }
Exemple #13
0
 public function __construct()
 {
     if (file_exists("Joobsbox/SearchIndexes/main")) {
         $this->_index = Zend_Search_Lucene::open("Joobsbox/SearchIndexes/main");
     } else {
         if (is_writable('Joobsbox/SearchIndexes')) {
             $this->_index = Zend_Search_Lucene::create("Joobsbox/SearchIndexes/main");
         } else {
             $this->_enabled = false;
         }
     }
     if ($this->_enabled) {
         Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
         Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
     }
 }
Exemple #14
0
 /**
  *  Initializes search model. If a Zend_Search_Lucene index is not found, one is created in /Joobsbox/SearchIndexes
  */
 public function __construct()
 {
     $this->_path = APPLICATION_DIRECTORY . "/Joobsbox/SearchIndexes/";
     if (file_exists($this->_path . "main")) {
         $this->index = Zend_Search_Lucene::open($this->_path . "main");
     } else {
         if (is_writable($this->_path)) {
             $this->index = Zend_Search_Lucene::create($this->_path . "main");
         } else {
             $this->enabled = false;
         }
     }
     if ($this->enabled) {
         Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
         Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
     }
 }
Exemple #15
0
 public function get_Zend_Search_Lucene($create_new_index = FALSE)
 {
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
     if (self::$_indexer != NULL) {
         return self::$_indexer;
     }
     $search_lucene_directory = $this->CI->config->item('search_lucene_directory');
     $dir_path = $_SERVER['DOCUMENT_ROOT'] . $search_lucene_directory;
     //var_dump($dir_path); exit;
     //ApplicationHook::logInfo($dir_path);
     $files = get_filenames($dir_path);
     if (count($files) <= 1) {
         //not found index files, index as new
         $create_new_index = TRUE;
     }
     if ($create_new_index) {
         self::$_indexer = Zend_Search_Lucene::create($dir_path, TRUE);
     } else {
         self::$_indexer = Zend_Search_Lucene::open($dir_path);
     }
     return self::$_indexer;
 }
if (isset($_ENV['CLEARDB_DATABASE_URL'])) {
    global $databaseConfig;
    $parts = parse_url($_ENV['CLEARDB_DATABASE_URL']);
    $databaseConfig['type'] = 'MySQLDatabase';
    $databaseConfig['server'] = $parts['host'];
    $databaseConfig['username'] = $parts['user'];
    $databaseConfig['password'] = $parts['pass'];
    $databaseConfig['database'] = trim($parts['path'], '/');
} else {
    require_once 'conf/ConfigureFromEnv.php';
}
MySQLDatabase::set_connection_charset('utf8');
SSViewer::set_theme('docs');
Config::inst()->update('DocumentationManifest', 'automatic_registration', false);
Config::inst()->update('DocumentationViewer', 'link_base', '');
Config::inst()->update('DocumentationViewer', 'check_permission', false);
DocumentationViewer::set_edit_link('framework', 'https://github.com/silverstripe/silverstripe-framework/edit/%version%/docs/%lang%/%path%', array('rewritetrunktomaster' => true));
if (Director::isLive()) {
    ControllerExtension::$google_analytics_code = 'UA-84547-8';
}
DocumentationSearch::set_meta_data(array('ShortName' => 'SilverStripe Documentation', 'Description' => 'Documentation for SilverStripe CMS / Framework', 'Tags' => 'silverstripe sapphire php framework cms content management system'));
// Changelogs have heaps of phrases, but are rarely relevant for content searches
Config::inst()->update('DocumentationSearch', 'boost_by_path', array('/^changelog/' => 0.05));
// Set shared index (avoid issues with different temp paths between CLI and web users)
if (file_exists(BASE_PATH . '/.lucene-index')) {
    Config::inst()->update('DocumentationSearch', 'index_location', BASE_PATH . '/.lucene-index');
}
// Fix invalid character in iconv
// see http://stackoverflow.com/questions/4723135/invalid-characters-for-lucene-text-search
Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
Exemple #17
0
<?php

define('SEARCH_INDEX_LOCATION', APPLICATION_PATH . '/data/loomp-index');
define('SEARCH_IMPORT_SIZE', 100);
define('SEARCH_RESULTS_SIZE', 50);
define('INDEX_CHARSET', 'utf-8');
setlocale(LC_CTYPE, 'de_DE.utf-8') or die('unable to set locale');
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding(INDEX_CHARSET);
function searchGetIndex()
{
    $index = null;
    try {
        $index = Zend_Search_Lucene::open(SEARCH_INDEX_LOCATION);
    } catch (Exception $e) {
        try {
            $index = Zend_Search_Lucene::create(SEARCH_INDEX_LOCATION);
            searchImportAll($index);
        } catch (Exception $e) {
            print "something really bad happened.";
        }
    }
    return $index;
}
function searchQuery($query, $size = SEARCH_RESULTS_SIZE)
{
    $index = searchGetIndex();
    Zend_Search_Lucene::setResultSetLimit($size);
    return $index->find($query);
}
function searchMashups($query, $start = 0, $limit = 20)
Exemple #18
0
/**
 * This method is used to generate search results field that are passed to the view
 * for displaying to the end-user
 * @param $query
 * @param $ordering
 */
function plgSearchJucene($query, $ordering = '')
{
    //import helpers
    require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_jucene' . DS . 'helpers' . DS . 'jucene.php';
    require_once JPATH_SITE . DS . 'components' . DS . 'com_content' . DS . 'helpers' . DS . 'route.php';
    //set up some variables
    global $mainframe;
    $user =& JFactory::getUser();
    $time = time();
    try {
        //retrieve the Lucene Index if exists
        $index =& JuceneHelper::getIndex();
    } catch (Exception $e) {
        JFactory::getApplication()->enqueueMessage(JText::_($e->getMessage()), 'error');
    }
    //It is time to define the parameters! First get the right plugin; 'search' (the group), 'nameofplugin'.
    $plugin =& JPluginHelper::getPlugin('search', 'jucene');
    //load the parameters of the plugin
    $pluginParams = new JParameter($plugin->params);
    $limit = $pluginParams->def('search_limit', 0);
    //TODO log search query
    //Set query
    try {
        $query = JuceneHelper::prepareNumber($query);
    } catch (Exception $e) {
    }
    Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('UTF-8');
    try {
        Zend_Search_Lucene_Search_QueryParser::parse($query);
    } catch (Exception $e) {
        JFactory::getApplication()->enqueueMessage(JText::_($e->getMessage()), 'error');
    }
    $query = str_replace('-', ':', $query);
    if (JDEBUG) {
        JFactory::getApplication()->enqueueMessage(JText::_($query, 'error'));
    }
    //query time
    $_SESSION['jucene_timer'] = time();
    try {
        $results = $index->find($query, 'score', SORT_NUMERIC, SORT_DESC, 'rating', SORT_NUMERIC, SORT_DESC);
    } catch (Exception $e) {
        JFactory::getApplication()->enqueueMessage(JText::_($e->getMessage()), 'error');
    }
    //TODO find better solution to create links, perhaps to create router like it the com_content
    // Create a user access object for the current user
    $access = new stdClass();
    $access->canEdit = $user->authorize('com_content', 'edit', 'content', 'all');
    $access->canEditOwn = $user->authorize('com_content', 'edit', 'content', 'own');
    $access->canPublish = $user->authorize('com_content', 'publish', 'content', 'all');
    // Check to see if the user has access to view the full article
    $aid = $user->get('aid');
    //pk is the value of the primary key of the record, because we cannot call id - lucene would return id WITHIN index.. not database primary key
    foreach ($results as $key => $val) {
        if ($val->access <= $aid) {
            $results[$key]->href = JRoute::_(ContentHelperRoute::getArticleRoute($val->alias, $val->catid, $val->sectionid));
            //ContentHelperRoute::getArticleRoute ( $val->pk );
        } else {
            $params =& JComponentHelper::getParams('com_jucene');
            $leave_out = $params->get('leave_out', 1);
            // Create login URL or leave out private content
            if ($leave_out == 1) {
                unset($results[$key]);
            } else {
                $uri = JFactory::getURI();
                $return = $uri->toString();
                $url = 'index.php?option=com_user&view=login';
                $url .= '&return=' . base64_encode($return);
                $results[$key]->href = $url;
            }
        }
        $results[$key]->count = '';
        $results[$key]->time = $time;
    }
    //Return the search results in an array
    return $results;
}
Exemple #19
0
 public function searchAction()
 {
     Zend_Registry::set('theaction', 'content');
     $this->toTpl('theInclude', 'search');
     Zend_Registry::set('module', 'Search Results');
     //error_reporting(E_ALL);
     $data = $this->_request->getParams();
     $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) {
         $cid = $this->getIdBySlug($hit->slug);
         $content = $this->getContent($hit->type_id, $cid);
         $content['id'] = $cid;
         $content['type_id'] = $hit->type_id;
         $content['type'] = $this->getContentType($hit->type_id);
         $resu[] = $content;
     }
     $this->toTpl('theList', $resu);
 }
Exemple #20
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');
     }
 }
Exemple #21
0
 /**
  * search function
  * searches the index
  *
  * @param mixed $Model
  * @param mixed $query
  * @param int $limit
  * @param int $page
  * @access public
  * @return void
  */
 function search(&$Model, $query, $limit = 20, $page = 1)
 {
     // open the index
     if (!$this->open_index($Model)) {
         return false;
     }
     try {
         // set the default encoding
         Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
         // zend search results limiting (We will use the LimitIterator)
         // we can use it for some maximum value like 1000 if its likely that there could be more results
         Zend_Search_Lucene::setResultSetLimit(1000);
         // set the parser default operator to AND
         Zend_Search_Lucene_Search_QueryParser::setDefaultOperator(Zend_Search_Lucene_Search_QueryParser::B_AND);
         // utf-8 num analyzer
         Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
         // parse the query
         $Query = Zend_Search_Lucene_Search_QueryParser::parse($query);
         $Terms = $Query->getQueryTerms();
         foreach ($Terms as $Term) {
             $this->terms[] = $Term->text;
         }
         // do the search
         $Hits = new ArrayObject($this->Index->find($Query));
     } catch (Zend_Search_Lucene_Exception $e) {
         $this->log("Zend_Search_Lucene error: " . $e->getMessage(), 'searchable');
     }
     $this->hits_count = count($Hits);
     if (!count($Hits)) {
         return null;
     }
     $Hits = new LimitIterator($Hits->getIterator(), ($page - 1) * $limit, $limit);
     $results = array();
     foreach ($Hits as $Hit) {
         $Document = $Hit->getDocument();
         $fields = $Document->getFieldNames();
         $result = array();
         foreach ($fields as $field) {
             $result['Result'][$field] = $Document->{$field};
         }
         $results[] = $result;
     }
     return $results;
 }
Exemple #22
0
 /**
  * Open the lucene search index and return it.
  *
  * @return \Zend_Search_Lucene_Interface
  */
 protected function getIndex()
 {
     \Zend_Search_Lucene_Analysis_Analyzer::setDefault(new \Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
     \Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
     $path = PathHelper::path($this['projectPath'], 'data', 'searchindex');
     return \Zend_Search_Lucene::open($path);
 }
Exemple #23
0
 public function getHits($keyword, $params = array())
 {
     //Open the index to search in.
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('UTF-8');
     $query = Zend_Search_Lucene_Search_QueryParser::parse($keyword, 'UTF-8');
     $Index = Zend_Search_Lucene::open('../application/searchindex');
     Zend_Search_Lucene::setResultSetLimit(350);
     //Search.
     if (isset($params['search_full']) == 1) {
         $query = '"' . $query . '"';
     }
     $hits = $Index->find($query);
     //Filter
     $results = array();
     if (isset($params['types']) && !empty($params['types'])) {
         if (!is_array($params['types'])) {
             $params['types'] = (array) $params['types'];
         }
         foreach ($hits as $hit) {
             if (in_array($hit->type, $params['types'])) {
                 $results[] = $hit;
             }
         }
     } else {
         $results = $hits;
     }
     return $results;
 }
 public function searchAction()
 {
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
     //		$request = Zend_Controller_Front::getInstance()->getRequest();
     $cfg = Zend_Registry::get('cfg');
     $indexPath = $cfg['search']['indexpath'];
     //		$pagesize = $this->getRequest()->getParam('pagesize', $cfg['search']['pagesize']);
     $hits = array();
     $queryStr = trim($this->getRequest()->getParam('query'));
     $index = Zend_Search_Lucene::open($indexPath);
     if (strlen($queryStr) > 0) {
         $index = Zend_Search_Lucene::open($indexPath);
         $userQuery = Zend_Search_Lucene_Search_QueryParser::parse($queryStr);
         $query = new Zend_Search_Lucene_Search_Query_Boolean();
         $query->addSubquery($userQuery, true);
         try {
             $hits = $index->find($query);
         } catch (Zend_Search_Lucene_Exception $ex) {
             $hits = array();
         }
     }
     $view = $this->view;
     //		$view->assign('hits', $hits);
     $view->assign('query', $queryStr);
     //		$view->assign('pagesize', $pagesize);
     $paginator = Zend_Paginator::factory($hits);
     //new Zend_Paginator(new Zend_Paginator_Adapter_Array($hits));
     $paginator->setCurrentPageNumber($this->getRequest()->getParam('page', 0));
     $paginator->setItemCountPerPage($this->getRequest()->getParam('pagesize', $cfg['search']['pagesize']));
     Zend_Paginator::setDefaultScrollingStyle('Sliding');
     Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_search_control.phtml');
     $view->assign('paginator', $paginator);
     $view->queryParams = $this->getRequest()->getParams();
     /*		$req = Zend_Controller_Front::getInstance()->getRequest();
     		$paginator->setCurrentPageNumber($req->getParam('page', 0));
     		$paginator->setItemCountPerPage($req->getParam('itemsperpage', $items_on_page));*/
     //		return $paginator;
 }
Exemple #25
0
 /**
  * Returns the index
  *
  * @return type
  */
 public function getIndex()
 {
     //   var_dump("in get index");
     if ($this->index != null) {
         return $this->index;
     }
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
     // Important also for GUID Searches (e.g. delete)
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
     Zend_Search_Lucene_Search_QueryParser::setDefaultOperator(Zend_Search_Lucene_Search_QueryParser::B_AND);
     $searchIndexPath = Yii::app()->getRuntimePath() . DIRECTORY_SEPARATOR . "searchdb" . DIRECTORY_SEPARATOR;
     //var_dump($searchIndexPath);
     try {
         $index = Zend_Search_Lucene::open($searchIndexPath);
     } catch (Exception $ex) {
         $index = Zend_Search_Lucene::create($searchIndexPath);
     }
     $this->index = $index;
     return $index;
 }
Exemple #26
0
 /**
  *
  * @return Zend_Search_Lucene_Search_Query $query
  * @param string $queryString
  */
 public function createFuzzyQuery($queryString)
 {
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding($this->_encoding);
     $userQuery = Zend_Search_Lucene_Search_QueryParser::parse($queryString, $this->_encoding);
     $query = new Zend_Search_Lucene_Search_Query_Boolean();
     $query->addSubquery($userQuery);
     $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($queryString, $this->_encoding);
     if (2 > count($tokens)) {
         $term = new Zend_Search_Lucene_Index_Term($queryString, 'name');
         $fuzzy = new Zend_Search_Lucene_Search_Query_Fuzzy($term, 0.4);
         $query->addSubquery($fuzzy);
     }
     return $query;
 }
 public function testAction()
 {
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('UTF-8');
     $index = Zend_Search_Lucene::open(APPLICATION_ROOT . '/data/my-index');
     $phrase = 'альфа';
     if ($this->_getParam('query')) {
         $phrase = $this->_getParam('query');
     }
     $query = Zend_Search_Lucene_Search_QueryParser::parse($phrase);
     $hits = $index->find(strtolower($query));
     //var_dump($hits);
     foreach ($hits as $hit) {
         // возвращает объект для этого "хита"
         $document = $hit->getDocument();
         // возвращает объект Zend_Search_Lucene_Field
         // из Zend_Search_Lucene_Document
         $document->getField('title');
         var_dump($document->getField('title'));
         echo '<br>';
         echo '<br>';
         // возвращает строковое значение объекта Zend_Search_Lucene_Field
         /*echo $document->getFieldValue('title');
         
                     // делает то же самое, что и getFieldValue()
                     echo $document->title;*/
     }
 }
 /**
  * Enable the default configuration of Zend Search Lucene searching on the 
  * given data classes.
  * 
  * @param   Array   $searchableClasses  An array of classnames to scan.  Can 
  *                                      choose from SiteTree and/or File.
  *                                      To not scan any classes, for example
  *                                      if we will define custom fields to scan,
  *                                      pass in an empty array.
  *                                      Defaults to scan SiteTree and File.
  */
 public static function enable($searchableClasses = array('SiteTree', 'File'))
 {
     // We can't enable the search engine if we don't have QueuedJobs installed.
     if (!ClassInfo::exists('QueuedJobService')) {
         die('<strong>' . _t('ZendSearchLucene.ERROR', 'Error') . '</strong>: ' . _t('ZendSearchLucene.QueuedJobsRequired', 'Lucene requires the Queued jobs module.  See ' . '<a href="http://www.silverstripe.org/queued-jobs-module/">' . 'http://www.silverstripe.org/queued-jobs-module/</a>.'));
     }
     if (!is_array($searchableClasses)) {
         $searchableClasses = array($searchableClasses);
     }
     foreach ($searchableClasses as $class) {
         if (isset(self::$defaultColumns[$class])) {
             Object::add_extension($class, "ZendSearchLuceneSearchable('" . self::$defaultColumns[$class] . "')");
         } else {
             user_error("I don't know the default search columns for class '{$class}'");
             return;
         }
     }
     Object::add_extension('ContentController', 'ZendSearchLuceneContentController');
     DataObject::add_extension('SiteConfig', 'ZendSearchLuceneSiteConfig');
     Object::add_extension('LeftAndMain', 'ZendSearchLuceneCMSDecorator');
     Object::add_extension('StringField', 'ZendSearchLuceneTextHighlightDecorator');
     // Set up default encoding and analyzer
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding(ZendSearchLuceneSearchable::$encoding);
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new StandardAnalyzer_Analyzer_Standard_English());
 }
Exemple #29
0
 function AOD_Index()
 {
     parent::AOD_Index_sugar();
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
 }
 /**
  * Zend Search Lucene makes it awfully hard to have multiple Lucene indexes
  * open at the same time. This method combats that by configuring all the
  * static variables for this instance.
  */
 public function configure()
 {
     sfLuceneToolkit::loadZend();
     $this->getEventDispatcher()->notify(new sfEvent($this, 'lucene.configure.pre'));
     Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding($this->getParameter('encoding'));
     switch (strtolower($this->getParameter('analyzer'))) {
         default:
             throw new sfLuceneException('Unknown analyzer: ' . $this->getParameter('analzyer'));
         case 'text':
             $analyzer = new Zend_Search_Lucene_Analysis_Analyzer_Common_Text();
             break;
         case 'textnum':
             $analyzer = new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum();
             break;
         case 'utf8':
         case 'utf-8':
             $analyzer = new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8();
             break;
         case 'utf8num':
         case 'utf-8num':
             $analyzer = new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num();
             break;
     }
     if (!$this->getParameter('case_sensitive', false)) {
         $analyzer->addFilter(new sfLuceneLowerCaseFilter($this->getParameter('mb_string', false)));
     }
     if (count($this->getParameter('stop_words'))) {
         $analyzer->addFilter(new Zend_Search_Lucene_Analysis_TokenFilter_StopWords($this->getParameter('stop_words')));
     }
     if ($this->getParameter('short_words') > 0) {
         $analyzer->addFilter(new Zend_Search_Lucene_Analysis_TokenFilter_ShortWords($this->getParameter('short_words')));
     }
     Zend_Search_Lucene_Analysis_Analyzer::setDefault($analyzer);
     $this->getEventDispatcher()->notify(new sfEvent($this, 'lucene.configure.post'));
 }