Пример #1
0
 /**
  * 1) Обрабатвает термин текстовыми фильтрами, преобразовывает полученные
  *    формы в коды терминов.
  * 2) Добавляет запрос на ранжирование по этому термину (если необходимо).
  * 3) Возвращает массив с кодами, соответствующими всем формам термина (базовые
  *    формы, синонимы).
  *
  * Возвращает массив (zero-based) с кодами всех форм, соответствующих термину.
  * Если термин является стоп-словом, возвращает массив с единственным элементом "" (пустая строка).
  * Если в индексе нет ни одной формы термина, возвращает массив с элементом "____".
  *
  * Таким образом, в возвращаемом массиве всегда должен быть по крайней мере один
  * элемент.
  *
  * @param nc_search_query_expression_term $expression
  * @return array
  */
 protected function process_term(nc_search_query_expression_term $expression)
 {
     $string = $expression->get_value();
     // convert term to base forms
     $base_forms = $this->text_filters->apply('filter', array($string));
     if (!count($base_forms)) {
         // it's a stop-word obviously
         return array("");
     }
     // get codes
     $codes = array_unique($this->provider->get_term_codes($base_forms, false));
     // add the term to the ranking if it is not excluded
     $is_excluded = $this->is_inside("not") || $expression->is_excluded();
     // check whether there is at least one code
     if (count($codes) == 0) {
         // is this term required for all documents?
         $is_required = !$is_excluded && ($this->is_root() || $expression->is_required() || $this->parent_is("phrase") || $this->parent_is("and") && !$this->is_inside("or"));
         if ($is_required) {
             // this query won't produce any results anyway, so we could
             // spare a database request later
             $this->unknown_required_terms[] = $string;
         }
         $codes[] = "____";
         // dummy "non-existent term" code
     } elseif (!$is_excluded) {
         $this->query_builder->add_term_ranking($expression->get_field(), $codes, $expression->get_boost());
     }
     return $codes;
 }