Công cụ thành viên

Công cụ trang web


web_server:use-elasticsearch-in-nukeviet

Khác biệt

Đây là những khác biệt giữa hai phiên bản của trang.

Liên kết đến bản xem so sánh này

Phiên bản trước của cả hai bênPhiên bản trước
Phiên bản sau
Phiên bản trước
web_server:use-elasticsearch-in-nukeviet [2016/10/07 15:20] – [7. Hướng dẫn nâng cấp dữ liệu với những module đã có dữ liệu trước khi tích hợp elasticSearch] kid.aptweb_server:use-elasticsearch-in-nukeviet [2016/10/14 15:16] (hiện tại) vuthao
Dòng 1: Dòng 1:
-====== Hướng dẫn tích hợp ElasticSearch vào NukeViet ====== +====== Hướng dẫn tích hợp ElasticSearch vào NukeViet ====== 
-===== 1. Khai báo thông tin máy chủ elasticsearch ===== + 
-Mở file config.php của NukeViet thêm vào đoạn sau đây+===== 1. Thêm thư viện elasticsearch cho PHP ===== 
 +Mở file composer.json ở thư mục gốc của NukeViet
 <code> <code>
-$db_config['elas_host'] = '192.168.0.30';//Đây là địa chỉ IP máy chủ đã cài elasticsearch +"vinades/nukeviet": "dev-master",
-$db_config['elas_port'] = '9200';//Cổng kết nối đến máy chủ +
-$db_config['elas_index'] = 'nukeviet4_elastic';//Cơ sở dữ liệu lưu trữ tại máy chủ.+
 </code> </code>
-Phần cơ sở dữ liệu không cần phải khởi tạo trước. Có thể đặt bất cứ tên nào tùy ý. 
  
-===== 2. Kết nối CSDL Elasticsearch =====+Thêm xuống dưới đoạn sau 
 +<code> 
 +"elasticsearch/elasticsearch": "~2.0", 
 +</code> 
 + 
 +Sau đó dùng composer để cập nhật thư viện elasticsearch 
 +===== 2. Khai báo thông tin máy chủ elasticsearch  ===== 
 +Với module news, vào phần cấu hình của module để khai báo các tham số 
 +<code> 
 +Địa chỉ máy chủ cài đặt Elasticsearch  
 +Cổng kết nối với máy chủ Elasticseach  
 +CSDL lưu trữ tại máy chủ Elasticsearch 
 +</code> 
 + 
 +===== 3. Hướng dẫn cập nhật dữ liệu module news trước khi tích hợp elasticSearch ===== 
 +Tạo file update-elastic.php ở thư mục gốc của site với nội dung sau: 
 +<code php> 
 +<?php 
 + 
 +/** 
 + * @Project NUKEVIET 4.x 
 + * @Author Mr.Thang (kid.apt@gmail.com) 
 + * @Copyright (C) 2016 VINADES.,JSC. 
 + * All rights reserved 
 + * @License GNU/GPL version 2 or any later version 
 + * @Createdate 07/10/2016, 00:36 
 + */ 
 + 
 +define('NV_SYSTEM', true); 
 + 
 +// Xac dinh thu muc goc cua site 
 +define('NV_ROOTDIR', pathinfo(str_replace(DIRECTORY_SEPARATOR, '/', __file__), PATHINFO_DIRNAME)); 
 + 
 +require NV_ROOTDIR . '/includes/mainfile.php'; 
 + 
 +$module_name = 'news'; //module can chuyen du lieu 
 +$site_mods = nv_site_mods(); 
 +if (isset($site_mods[$module_name])) { 
 +    $nukeVietElasticSearh = new NukeViet\ElasticSearch\Functions($module_config[$module_name]['elas_host'], $module_config[$module_name]['elas_port'], $module_config[$module_name]['elas_index']); 
 +     
 +    $module_data = $site_mods[$module_name]['module_data']; 
 +    $elas_type = NV_PREFIXLANG . '_' . $module_data . '_rows'; //bảng dữ liệu sẽ lưu trữ bên máy chủ elasticsearch - lấy tương ứng với bảng bên NukeViet để dễ quản lý 
 +    $id = $nv_Request->get_int('id', 'get', 0); 
 +    $per_page = 500; //so ban ghi se chay moi lan request 
 +     
 + 
 +    $htm = '<pre>'; 
 +    //Index a document: 
 +    $db_slave->sqlreset() 
 +        ->select('*'
 +        ->from($elas_type) 
 +        ->limit($per_page) 
 +        ->where('id > ' . $id) 
 +        ->order('id ASC'); 
 +    $id = 0; 
 +    $created = 0; 
 +    $result = $db_slave->query($db_slave->sql()); 
 +    while ($row = $result->fetch()) { 
 +        //  Lấy nội dung chi tiết 
 +        $body_contents = $db_slave->query('SELECT * FROM ' . NV_PREFIXLANG . '_' . $module_data . '_detail where id=' . $row['id'])->fetch(); 
 +        $row = array_merge($row, $body_contents); 
 +         
 +        // Lọc dấu để phục vụ chi tìm kiếm 
 +        $row['unsigned_title'] = nv_EncString($row['title']); 
 +        $row['unsigned_bodyhtml'] = nv_EncString($row['bodyhtml']); 
 +        $row['unsigned_author'] = nv_EncString($row['author']); 
 +        $row['unsigned_hometext'] = nv_EncString($row['hometext']); 
 +         
 +        $response = $nukeVietElasticSearh->insert_data($elas_type, $row['id'], $row); 
 +        if ($response['created']) { 
 +            ++$created; 
 +        } 
 +        $id = $row['id']; 
 +     
 +    } 
 +    if ($id) { 
 +        $redirect = NV_MY_DOMAIN . NV_BASE_SITEURL . 'update-elastic.php?id=' . $id; 
 +        $htm .= '</pre>'; 
 +        $time = number_format((microtime(true) - NV_START_TIME), 3, '.', ''); 
 +        nv_info_die($global_config['site_description'], $lang_global['site_info'], "Đang thực hiện, thời gian xử lý: " . $time . "  thàng công " . number_format($created) . "/" . number_format($per_page) . " row \n <meta http-equiv=\"refresh\" content=\"2;URL=" . $redirect . "\" />" . $htm); 
 +    } 
 +    die('Thực hiện xong'); 
 +} else { 
 +    die('Không có module: ' . $module_name); 
 +
 +</code> 
 + 
 +Sau đó truy cập qua trình duyệt http://my-domain.com/file update-elastic.php  
 + 
 + 
 +====== Hướng dẫn tích hợp ElasticSearch với các module khác  ====== 
 +===== 1. Kết nối CSDL Elasticsearch =====
  
 <code> <code>
Dòng 18: Dòng 107:
 Các tham số truyền vào đều đã được cấu hình tại file config. Các tham số truyền vào đều đã được cấu hình tại file config.
  
-===== 3. Thêm mới 1 dữ liệu vào Elasticsearch =====+===== 2. Thêm mới 1 dữ liệu vào Elasticsearch =====
  
 <code> <code>
Dòng 29: Dòng 118:
 </code> </code>
  
-===== 4. Cập nhật lại dữ liệu vào Elasticsearch =====+===== 3. Cập nhật lại dữ liệu vào Elasticsearch =====
  
 <code> <code>
Dòng 40: Dòng 129:
 </code> </code>
  
-===== 5. Xóa dữ liệu tại Elasticsearch =====+===== 4. Xóa dữ liệu tại Elasticsearch =====
  
 <code> <code>
Dòng 50: Dòng 139:
 </code> </code>
  
-===== 6. Tìm kiếm dữ liệu trong Elasticsearch =====+===== 5. Tìm kiếm dữ liệu trong Elasticsearch =====
  
 <code> <code>
Dòng 82: Dòng 171:
     $response = $nukeVietElasticSearh->search_data( $table, $array_query_elastic);     $response = $nukeVietElasticSearh->search_data( $table, $array_query_elastic);
 } }
-</code> 
- 
-===== 7. Hướng dẫn nâng cấp dữ liệu với những module đã có dữ liệu trước khi tích hợp elasticSearch ===== 
- 
-<code> 
-<?php 
- 
-/** 
- * @Project NUKEVIET 4.x 
- * @Author Mr.Thang (kid.apt@gmail.com) 
- * @Copyright (C) 2016 VINADES.,JSC. 
- * All rights reserved 
- * @License GNU/GPL version 2 or any later version 
- * @Createdate 07/10/2016, 00:36 
- */ 
- 
- 
-define('NV_SYSTEM', true); 
- 
-// Xac dinh thu muc goc cua site 
-define('NV_ROOTDIR', pathinfo(str_replace(DIRECTORY_SEPARATOR, '/', __file__), PATHINFO_DIRNAME)); 
- 
-require NV_ROOTDIR . '/includes/mainfile.php'; 
- 
-$module_data = 'news';//module can chuyen du lieu 
- 
-$elas_host = '192.168.0.30';//dia chi server elasticsearch 
-$elas_port = '9200';//cong ket noi elasticsearch 
-$elas_index = 'nukeviet4_thang';//CSDL elasticsearch 
-$elas_type = NV_PREFIXLANG . '_' . $module_data . '_rows';//bảng dữ liệu sẽ lưu trữ bên máy chủ elasticsearch - lấy tương ứng với bảng bên NukeViet để dễ quản lý 
- 
-$nukeVietElasticSearh = new NukeViet\NukeVietElasticSearch\Functions( $elas_host, $elas_port, $elas_index ); 
- 
-$htm = '<pre>'; 
- 
-$id = $nv_Request->get_int('id', 'get', 0); 
-$per_page = 500;//so ban ghi se chay moi lan request 
-//Index a document: 
-$db_slave->sqlreset() 
-    ->select('*') 
-    ->from($elas_type) 
-    ->limit($per_page) 
-    ->where('id > ' . $id) 
-    ->order('id ASC'); 
-$id = 0; 
-$created = 0; 
-$result = $db_slave->query($db_slave->sql()); 
-while ($row = $result->fetch()) { 
-    //  Lấy nội dung chi tiết 
-    $body_contents = $db_slave->query('SELECT * FROM ' . NV_PREFIXLANG . '_' . $module_data . '_detail where id=' . $row['id'])->fetch(); 
-    $row = array_merge($row, $body_contents); 
-     
-     
-    $response = $nukeVietElasticSearh->insert_data($elas_type, $row['id'],$row ); 
-    if ($response['created']) { 
-        ++$created; 
-    } 
-    $id = $row['id']; 
- 
-} 
-if ($id) { 
-    $redirect = 'http://elasticsearch.xyz/update-elastic.php?id=' . $id; 
-    $htm .= '</pre>'; 
-    $time = number_format((microtime(true) - NV_START_TIME), 3, '.', ''); 
-    nv_info_die($global_config['site_description'], $lang_global['site_info'], "Đang thực hiện, thời gian xử lý: " . $time . "  thàng công " . number_format($created) . "/" . number_format($per_page) . " row \n <meta http-equiv=\"refresh\" content=\"2;URL=" . $redirect . "\" />" . $htm); 
-} 
-die('Thực hiện xong'); 
- 
 </code> </code>
web_server/use-elasticsearch-in-nukeviet.1475828442.txt.gz · Sửa đổi lần cuối: 2016/10/07 15:20 bởi kid.apt