/** * * @param array $terms * @return string */ public function get_highlight_regexp(array $terms) { $res = array(); foreach ($this->get_base_forms($terms) as $base) { $res[] = $base . "[\\pL\\d]{0,{$this->max_remainder_length}}"; } return nc_search_util::word_regexp("(" . join("|", $res) . ")", "Si"); }
/** * */ protected function get_highlight_regexp($language) { if (!$this->highlight_regexp) { $query_string = $this->get_query_string(); $context = new nc_search_context(array('language' => $language, 'action' => 'searching')); // Получить слова из запроса. // (Удалять из запроса термины с префиксом "-" и "NOT" не имеет особого смысла, // поскольку в результат они как правило не попадают.) $query_string = preg_replace("/[\\^~][\\d\\.]+/", '', $query_string); // операторы ^1, ~1 preg_match_all("/[\\pL\\d\\?\\*]+/u", $query_string, $matches); $terms = $matches[0]; if (strpos($query_string, "*") !== false || strpos($query_string, "?") !== false) { $wildcards_replacement = nc_search::should('AllowWildcardSearch') ? array("?" => ".", "*" => "[\\S]+") : array("?" => "", "*" => ""); foreach ($terms as $i => $term) { $terms[$i] = strtr($term, $wildcards_replacement); } } //if ( nc_Core::get_object()->NC_UNICODE ) { $terms = nc_search_extension_manager::get('nc_search_language_filter', $context)->except('nc_search_language_filter_stopwords')->apply('filter', $terms); //} $analyzer = nc_search_extension_manager::get('nc_search_language_analyzer', $context)->first(); if ($analyzer) { $regexp = $analyzer->get_highlight_regexp($terms); } else { $regexp = nc_search_util::word_regexp("(" . join("|", $terms) . ")", "Si"); } $this->highlight_regexp = $regexp; } // of "there was no 'highlight_regexp'" return $this->highlight_regexp; }
/** * * @param array $terms * @return string */ public function get_highlight_regexp(array $terms) { $morphy = $this->get_morphy(); $result = array(); foreach ($terms as $term) { $paradigms = $morphy->findWord($term); if ($paradigms) { foreach ($paradigms as $paradigm) { $result = array_merge($result, $paradigm->getAllForms()); } } else { // phpMorphy doesn't know what to do with that term $result[] = $term; } } $regexp = "(" . join("|", array_unique($result)) . ")"; return nc_search_util::word_regexp($regexp, "Si"); }