示例#1
0
文件: field.php 项目: Blu2z/implsk
 /**
  * Скопировать свойства поля документа в свойства поля индекса
  * @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;
 }
示例#2
0
文件: index.php 项目: Blu2z/implsk
 /**
  * @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;
 }
示例#3
0
文件: html.php 项目: Blu2z/implsk
 /**
  *
  * @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);
     }
 }
示例#4
0
文件: document.php 项目: Blu2z/implsk
 /**
  * Добавляет поле (для индекса).
  *
  * Внимание, может перезаписать существующее поле без предупреждения
  * (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;
 }
示例#5
0
文件: manager.php 项目: Blu2z/implsk
 /**
  * Получить составной ключ по определяющим свойствами поля (используется для
  * индексации элементов в коллекции данного типа с целью быстрого поиска полей)
  *
  * @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');
 }
示例#6
0
文件: fields.php 项目: Blu2z/implsk
$saved_custom_fields = array();
// сохранённые поля (для последующего удаления отсутствующих полей)
foreach ($input_custom as $custom_field_settings) {
    // подготовка настроек поля к сохранению:
    $custom_field_settings['weight'] = strtr($custom_field_settings["weight"], ",", ".");
    // decimal point
    // чекбоксы, подстрахуемся на случай, если по умолчанию значение свойства != false
    foreach (array('is_retrievable', 'is_normalized', 'is_sortable', 'is_indexed', 'is_stored') as $k) {
        if (!isset($custom_field_settings[$k]) && !$custom_field_settings[$k]) {
            $custom_field_settings[$k] = false;
        }
    }
    $custom_field_settings['is_searchable'] = $custom_field_settings['is_indexed'];
    $custom_field_settings['remove_from_parent'] = false;
    $custom_field_settings['query_scope'] = 'document';
    $field = new nc_search_field($custom_field_settings);
    $field->save();
    $fields->add($field);
    $saved_custom_fields[$custom_field_settings['name']] = true;
}
$is_save_request = count($input_title) || count($input_weight) || count($input_custom);
// выбрать поля с весом ($weight_fields) и с данными ($custom_fields) — пригодятся
// позже для вывода в форме + удаление старых (отсутствующих при сохранении) полей
$weight_fields = array();
$custom_fields = array();
foreach ($fields as $name => $field) {
    if (preg_match("/^w\\d+(?:_\\d+)?\$/", $name)) {
        if ($is_save_request && !isset($saved_weight_fields[$name])) {
            // cleanup
            $field->delete();
        } else {