/**
  * Constructor to set initial values.
  *
  * @param string $location The index location
  */
 public function __construct($location)
 {
     $this->location = $location;
     $this->analyzer = new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive();
     require_once 'Zend/Search/Lucene/Storage/Directory/Filesystem.php';
     Zend_Search_Lucene_Storage_Directory_Filesystem::setDefaultFilePermissions(0666);
 }
Пример #2
0
 /**
  * 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];
 }
Пример #3
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;
 }
  private static function prepareZendSearchLucene()
  {
    Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());

    $stopWords = sfConfig::get('app_sf_propel_luceneable_behavior_stopWords', false);
    $stopWordsFilter = new Zend_Search_Lucene_Analysis_TokenFilter_StopWords(false === $stopWords ? array() : explode(',', $stopWords));
    Zend_Search_Lucene_Analysis_Analyzer::getDefault()->addFilter($stopWordsFilter);

    $shortWords = sfConfig::get('app_sf_propel_luceneable_behavior_shortWords', 3);
    $shortWordsFilter = new Zend_Search_Lucene_Analysis_TokenFilter_ShortWords($shortWords);
    Zend_Search_Lucene_Analysis_Analyzer::getDefault()->addFilter($shortWordsFilter);

    Zend_Search_Lucene_Storage_Directory_Filesystem::setDefaultFilePermissions(0777);
  }
Пример #5
0
 /**
  * Indexer Constructor.
  * 
  * @global type $webDir
  */
 public function __construct()
 {
     global $webDir;
     if (!get_config('enable_indexing')) {
         return;
     }
     $index_path = $webDir . self::$_index_dir;
     // Give read-writing permissions only for current user and group
     Zend_Search_Lucene_Storage_Directory_Filesystem::setDefaultFilePermissions(0600);
     // Utilize UTF-8 compatible text analyzer
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
     try {
         if (file_exists($index_path)) {
             $this->__index = Zend_Search_Lucene::open($index_path);
             // Open index
         } else {
             $this->__index = Zend_Search_Lucene::create($index_path);
             // Create index
         }
     } catch (Zend_Search_Lucene_Exception $e) {
         require_once 'fatal_error.php';
     }
     $this->__index->setFormatVersion(Zend_Search_Lucene::FORMAT_2_3);
     // Set Index Format Version
     Zend_Search_Lucene::setResultSetLimit(self::$_resultSetLimit);
     // Set Result Set Limit
     // write an .htaccess to prevent raw access to index files
     $htaccess = $index_path . '/.htaccess';
     if (!file_exists($htaccess)) {
         $fd = fopen($htaccess, "w");
         fwrite($fd, "deny from all\n");
         fclose($fd);
     }
     if (!file_exists($index_path . '/index.php')) {
         touch($index_path . '/index.php');
     }
 }
Пример #6
0
 /**
  * Instanciate the Lucene index
  * 
  * The index will be created if it doesn't exist yet.
  * 
  * @return \Zend_Search_Lucene_Interface							Lucene index instance
  * @throws Exception											If the index cannot be created
  */
 protected function _index()
 {
     // One-time instanciation or creation of the lucene index
     if ($this->_index === null) {
         // Try to instanciate an existing lucene index
         try {
             $this->_index = \Zend_Search_Lucene::open($this->_indexDirectory);
             // If an error occurs ...
         } catch (\Zend_Search_Lucene_Exception $e) {
             // Try to create a new lucene index ...
             try {
                 $this->_index = \Zend_Search_Lucene::create($this->_indexDirectory);
                 // If an error occurs: Failure
             } catch (\Zend_Search_Lucene_Exception $e) {
                 throw new Exception(sprintf('Error creating lucene index in "%1$s", reason: "%2$s"', $this->_indexDirectory, $e->getMessage()));
             }
         }
         // Index setup
         \Zend_Search_Lucene_Storage_Directory_Filesystem::setDefaultFilePermissions(0664);
         \Zend_Search_Lucene_Analysis_Analyzer::setDefault(new \Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive());
         \Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('UTF-8');
         // Minimize memory consumption
         $this->_index->setMaxBufferedDocs(1);
         // Set optimization frequency
         $this->_index->setMergeFactor(max(1, intval($GLOBALS['TYPO3_CONF_VARS']['EXT']['extParams']['tw_lucenesearch']['mergeFactor'])));
         // If applicable: Optimize index
         if ($this->_indexOptimize) {
             $this->_index->optimize();
         }
         $this->_index->commit();
         if (TYPO3_MODE == 'FE') {
             \Zend_Search_Lucene::setTermsPerQueryLimit(\Tollwerk\TwLucenesearch\Utility\Indexer::indexConfig($GLOBALS['TSFE'], 'search.limits.query'));
         }
     }
     return $this->_index;
 }
Пример #7
0
 private function getIndex()
 {
     global $prefs;
     Zend_Search_Lucene_Storage_Directory_Filesystem::setDefaultFilePermissions(0660);
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new StandardAnalyzer_Analyzer_Standard_English());
     if ($this->indexNeedsRebuilding()) {
         return $this->rebuildIndex();
     }
     return Zend_Search_Lucene::open($this->file);
 }