Example #1
0
 /**
  * Скопировать свойства поля документа в свойства поля индекса
  * @param nc_search_field $field
  * @return nc_search_provider_index_field
  */
 public function copy_options(nc_search_field $field)
 {
     foreach ($this->properties as $o => $v) {
         if ($o != 'id') {
             $this->set($o, $field->get($o));
         }
     }
     return $this;
 }
Example #2
0
 /**
  * @param $doc_id
  * @param nc_search_field $field
  * @param nc_search_context $doc_context
  * @return string
  */
 protected function store_field($doc_id, nc_search_field $field, nc_search_context $doc_context)
 {
     $text = $field->get('value');
     if (strlen($text) == 0) {
         return '';
     }
     // empty fields are not stored
     $content = '';
     $raw_data = '';
     $is_stored = $field->get('is_stored') || $field->get('is_sortable');
     // 'is_indexed' → store in the `Content` field
     if ($field->get('is_indexed')) {
         $content = "";
         $filters = nc_search_extension_manager::get('nc_search_language_filter', $doc_context)->except('nc_search_language_filter_case')->stop_on(array());
         // Processing in chunks - compromise between performance (less
         // method call overhead) and memory usage
         $n = 0;
         $current_position = 0;
         $text_length = strlen($text);
         $batch_length = $this->text_batch_length;
         while ($current_position < $text_length) {
             if ($text_length < $batch_length) {
                 $batch = $text;
                 $current_position = $text_length;
             } else {
                 $space_position = strpos($text, " ", min($text_length, $current_position + $batch_length));
                 if (!$space_position) {
                     $batch = substr($text, $current_position);
                     $current_position = $text_length;
                 } else {
                     $batch = substr($text, $current_position, $space_position - $current_position);
                     $current_position = $space_position + 1;
                 }
             }
             $tokens = $this->tokenize_text(mb_convert_case($batch, nc_search::get_setting('FilterStringCase'), 'UTF-8'));
             if ($field->get('is_normalized')) {
                 // apply filters
                 $tokens = $filters->apply('filter', $tokens);
             }
             $content .= ($n ? ' ' : '') . join(' ', $this->get_term_codes($tokens, true));
             $n++;
         }
     }
     // 'is_stored' → store raw text as well
     if ($is_stored) {
         $raw_data = $text;
     }
     // save data in the DB
     $this->store_index_data($this->get_field_table_name($field), $doc_id, $content, $raw_data);
     return $content;
 }
Example #3
0
 /**
  *
  * @param nc_search_field $field
  * @throws nc_search_exception
  */
 protected function extract_field_value(nc_search_field $field)
 {
     $source_name = $field->get('query_scope');
     $recipient_name = $field->get('name');
     if (!isset($this->parts[$source_name])) {
         throw new nc_search_exception("Cannot extract field value: '{$source_name}' part does not exist");
     }
     $source = $this->parts[$source_name];
     if (!isset($this->parts[$recipient_name])) {
         $this->parts[$recipient_name] = new nc_search_document_parser_html_fragment();
     }
     $recipient = $this->parts[$recipient_name];
     $this->execute_queries($field->get('query'), $source, $recipient, $field->get('remove_from_parent'), $field->get('query_use_first_matched'));
     // filter
     if ($field->get('filter_content')) {
         $this->execute_queries($field->get('filter_content'), $recipient, null, true, false);
     }
 }
Example #4
0
 /**
  * Добавляет поле (для индекса).
  *
  * Внимание, может перезаписать существующее поле без предупреждения
  * (it’s a feature / by design)
  *
  * @param nc_search_field $field
  * @return nc_search_document
  */
 public function add_field(nc_search_field $field)
 {
     $field_name = $field->get('name');
     $this->fields[$field_name] = $field;
     if (!isset($this->field_mapping[$field_name])) {
         // required for option_to_field and vice versa
         $this->field_mapping[$field_name] = array("name" => $field_name);
     }
     return $this;
 }
Example #5
0
 /**
  * Получить составной ключ по определяющим свойствами поля (используется для
  * индексации элементов в коллекции данного типа с целью быстрого поиска полей)
  *
  * @param nc_search_field|nc_search_provider_index_field $field
  * @return string
  */
 public static function get_key_options($field)
 {
     return $field->get('name') . "#" . sprintf("%.2F", $field->get('weight')) . '#' . $field->get('type') . '#' . (int) $field->get('is_sortable');
 }