Beispiel #1
0
 /**
  * Пытается убрать кавычки из запроса
  * @param nc_search_language_corrector_phrase $phrase
  * @return boolean
  */
 public function correct(nc_search_language_corrector_phrase $phrase)
 {
     if (!nc_search::should('RemovePhrasesOnEmptyResult')) {
         return false;
     }
     $orignal_phrase_text = $phrase_text = $phrase->to_string();
     if (strpos($phrase_text, '"') !== false && !preg_match('/"\\S+"/u', $phrase_text)) {
         $phrase_text = preg_replace('/"~[\\d\\.]+/', '"', $phrase_text);
         // remove distance search
         if (nc_search_util::is_boolean_query($phrase_text) || preg_match('/[-+]/', $phrase_text)) {
             // there is a a phrase with several words!
             $phrase_text = preg_replace('/"(\\S)/u', "(\$1", $phrase_text);
             $phrase_text = str_replace('"', ")", $phrase_text);
         } else {
             $phrase_text = str_replace('"', "", $phrase_text);
         }
         $message = sprintf(NETCAT_MODULE_SEARCH_CORRECTION_QUOTES, $orignal_phrase_text, $phrase_text);
         $phrase->set_phrase($phrase_text, $message);
         return true;
     }
     return false;
 }
Beispiel #2
0
 /**
  * Возвращает массив со словами, которых нет в индексе и в словаре
  * @param nc_search_language_corrector_phrase $phrase
  * @return array|false
  */
 protected function get_unknown_terms(nc_search_language_corrector_phrase $phrase)
 {
     $all_terms = $phrase->get_not_corrected_terms();
     if (!sizeof($all_terms)) {
         return false;
     }
     $stopwords_analyzer = false;
     if (nc_search::should('RemoveStopwords')) {
         $stopwords_analyzer = new nc_search_language_filter_stopwords($this->context);
     }
     $unknown_terms = array();
     foreach ($all_terms as $term) {
         // строка должна быть в правильном регистре, чтобы анализатор мог её корректно обработать
         $string = $term->get('term');
         // выкинем стоп-слова для начала
         if ($stopwords_analyzer && !$stopwords_analyzer->filter(array($string))) {
             continue;
         }
         // проверка по индексу
         if (!$this->provider_lookup($string)) {
             $unknown_terms[] = $term;
             $term->set('is_incorrect', true);
             continue;
             // go to next term
         }
         // проверка по словарю
         $analyzer_result = $this->analyzer_lookup($string);
         if ($analyzer_result !== true) {
             // FALSE или STRING
             $unknown_terms[] = $term;
             $term->set('is_incorrect', true);
             if (is_string($analyzer_result)) {
                 $term->set('corrected_term', $analyzer_result);
             }
         }
     }
     return $unknown_terms;
 }