Esempio n. 1
0
 /**
  * Обработать документ (конкретный класс должен проверить, есть ли документ
  * в индексе, и в зависимости от этого обновить существующий документ или добавить
  * новый)
  * @param nc_search_document $document
  * @return bool
  */
 public function process_document(nc_search_document $document)
 {
     $doc_hash = $document->generate_hash();
     // Есть ли документ с таким путём в нашей базе?
     $stored = nc_search_document::get_hash_by_path($document->get('site_id'), $document->get('path'));
     if ($stored) {
         $document->set_id($stored->get_id());
         // Нужно ли обновлять данные в индексе? Проверить хэш для content
         if ($stored->get('hash') == $doc_hash) {
             $document->save();
             return false;
             // ---- RETURN ----
         }
     }
     // Загрузить словарь в память?
     if (nc_search::should('DatabaseIndex_LoadAllCodesForIndexing')) {
         $this->load_dictionary();
     }
     // (1) Сохранение документа в `Search_Document`
     $document->save();
     $doc_id = $document->get_id();
     $doc_context = $this->create_document_context($document);
     $all_terms = array();
     // (2) Удаление старых данных из `Search_Index_FieldN`
     if ($stored) {
         $this->remove_document_fields($doc_id);
     }
     // (3) Обработка полей: сохранение данных в `Search_Index_FieldN`
     /** @var $field nc_search_field */
     foreach ($document->get_fields() as $field) {
         if (!isset($this->skipped_fields[$field->get('name')])) {
             $all_terms[] = $this->store_field($doc_id, $field, $doc_context);
         }
     }
     // (4) Сохранение искабельного текста в `Search_Index`
     $this->store_index_data($this->index_table_name, $doc_id, join('/', array_filter($all_terms)));
     return true;
 }
Esempio n. 2
0
 /**
  * 
  */
 protected function remove_absent_documents()
 {
     $absent_document_count = 0;
     /** @var nc_db $db */
     $db = nc_Core::get_object()->db;
     $query = "SELECT `Document_ID` FROM `Search_Document` WHERE `ToDelete` = 1 LIMIT 10000";
     while ($absent_documents = $db->get_results($query, ARRAY_A)) {
         foreach ($absent_documents as $row) {
             $doc = new nc_search_document();
             $doc->set_id($row['Document_ID']);
             $this->index->remove_document($doc);
         }
         $absent_document_count += count($absent_documents);
         // this operation might be slow, so save the task to prevent it from being marked as 'hung up'
         $this->task->save();
     }
     return $absent_document_count;
 }
Esempio n. 3
0
 /**
  * Обработать документ
  * @param nc_search_document $document
  * @return bool
  */
 public function process_document(nc_search_document $document)
 {
     $doc_hash = $document->generate_hash();
     // Есть ли документ с таким путём в нашей базе?
     $stored = nc_search_document::get_hash_by_path($document->get('site_id'), $document->get('path'));
     if ($stored) {
         // Нужно ли обновлять данные в индексе? Проверить хэш для content
         if ($stored->get('hash') == $doc_hash) {
             // «cтолько времени ззря!» © Фандорин
             $document->set_id($stored->get_id())->save();
             return false;
         }
         $document->set_id($stored->get_id());
         $this->update_document($document);
     } else {
         $this->add_document($document);
     }
 }