예제 #1
0
파일: morphy.php 프로젝트: Blu2z/implsk
 /**
  * @throws nc_search_exception
  * @return phpMorphy
  */
 protected function get_morphy()
 {
     $language = $this->context->get('language');
     $language = $language . "_" . $language;
     // phpMorphy requires "ru_ru", "en_en"
     $this->language = $language;
     if (!isset(self::$instances[$language])) {
         if (!class_exists('phpMorphy', false)) {
             nc_search::load_3rdparty_script("phpmorphy/src/common.php");
         }
         if (nc_search::should('PhpMorphy_LoadDictsDuringIndexing') && $this->context->get('action') == 'indexing') {
             $storage = PHPMORPHY_STORAGE_MEM;
         } else {
             $storage = PHPMORPHY_STORAGE_FILE;
         }
         $options = array('storage' => $storage, 'predict_by_suffix' => true, 'predict_by_db' => true);
         // Path to directory where dictionaries are located
         $dict_path = nc_search::get_3rdparty_path() . '/phpmorphy/dicts';
         try {
             self::$instances[$language] = new phpMorphy($dict_path, $language, $options);
         } catch (phpMorphy_Exception $e) {
             throw new nc_search_exception("Error occurred while creating phpMorphy instance: {$e->getMessage()}");
         }
     }
     return self::$instances[$language];
 }