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.
Phiên bản trước của cả hai bênPhiên bản trướcPhiê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.apt | web_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 | + | ===== 1. Thêm thư viện |
+ | Mở file composer.json ở thư mục gốc của NukeViet | ||
< | < | ||
- | $db_config[' | + | " |
- | $db_config[' | + | |
- | $db_config[' | + | |
</ | </ | ||
- | 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 |
+ | < | ||
+ | " | ||
+ | </ | ||
+ | |||
+ | 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ố | ||
+ | < | ||
+ | Đị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 | ||
+ | </ | ||
+ | |||
+ | ===== 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., | ||
+ | * All rights reserved | ||
+ | * @License GNU/GPL version 2 or any later version | ||
+ | * @Createdate 07/10/2016, 00:36 | ||
+ | */ | ||
+ | |||
+ | define(' | ||
+ | |||
+ | // Xac dinh thu muc goc cua site | ||
+ | define(' | ||
+ | |||
+ | require NV_ROOTDIR . '/ | ||
+ | |||
+ | $module_name = ' | ||
+ | $site_mods = nv_site_mods(); | ||
+ | if (isset($site_mods[$module_name])) { | ||
+ | $nukeVietElasticSearh = new NukeViet\ElasticSearch\Functions($module_config[$module_name][' | ||
+ | |||
+ | $module_data = $site_mods[$module_name][' | ||
+ | $elas_type = NV_PREFIXLANG . ' | ||
+ | $id = $nv_Request-> | ||
+ | $per_page = 500; //so ban ghi se chay moi lan request | ||
+ | |||
+ | |||
+ | $htm = '< | ||
+ | //Index a document: | ||
+ | $db_slave-> | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | $id = 0; | ||
+ | $created = 0; | ||
+ | $result = $db_slave-> | ||
+ | while ($row = $result-> | ||
+ | // Lấy nội dung chi tiết | ||
+ | $body_contents = $db_slave-> | ||
+ | $row = array_merge($row, | ||
+ | |||
+ | // Lọc dấu để phục vụ chi tìm kiếm | ||
+ | $row[' | ||
+ | $row[' | ||
+ | $row[' | ||
+ | $row[' | ||
+ | |||
+ | $response = $nukeVietElasticSearh-> | ||
+ | if ($response[' | ||
+ | ++$created; | ||
+ | } | ||
+ | $id = $row[' | ||
+ | |||
+ | } | ||
+ | if ($id) { | ||
+ | $redirect = NV_MY_DOMAIN . NV_BASE_SITEURL . ' | ||
+ | $htm .= '</ | ||
+ | $time = number_format((microtime(true) - NV_START_TIME), | ||
+ | nv_info_die($global_config[' | ||
+ | } | ||
+ | die(' | ||
+ | } else { | ||
+ | die(' | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Sau đó truy cập qua trình duyệt http:// | ||
+ | |||
+ | |||
+ | ====== Hướng dẫn tích hợp ElasticSearch với các module khác ====== | ||
+ | ===== 1. Kết nối CSDL Elasticsearch ===== | ||
< | < | ||
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 ===== |
< | < | ||
Dòng 29: | Dòng 118: | ||
</ | </ | ||
- | ===== 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 ===== |
< | < | ||
Dòng 40: | Dòng 129: | ||
</ | </ | ||
- | ===== 5. Xóa dữ liệu tại Elasticsearch ===== | + | ===== 4. Xóa dữ liệu tại Elasticsearch ===== |
< | < | ||
Dòng 50: | Dòng 139: | ||
</ | </ | ||
- | ===== 6. Tìm kiếm dữ liệu trong Elasticsearch ===== | + | ===== 5. Tìm kiếm dữ liệu trong Elasticsearch ===== |
< | < | ||
Dòng 82: | Dòng 171: | ||
$response = $nukeVietElasticSearh-> | $response = $nukeVietElasticSearh-> | ||
} | } | ||
- | </ | ||
- | |||
- | ===== 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 ===== | ||
- | |||
- | < | ||
- | <?php | ||
- | |||
- | /** | ||
- | * @Project NUKEVIET 4.x | ||
- | * @Author Mr.Thang (kid.apt@gmail.com) | ||
- | * @Copyright (C) 2016 VINADES., | ||
- | * All rights reserved | ||
- | * @License GNU/GPL version 2 or any later version | ||
- | * @Createdate 07/10/2016, 00:36 | ||
- | */ | ||
- | |||
- | |||
- | define(' | ||
- | |||
- | // Xac dinh thu muc goc cua site | ||
- | define(' | ||
- | |||
- | require NV_ROOTDIR . '/ | ||
- | |||
- | $module_data = ' | ||
- | |||
- | $elas_host = ' | ||
- | $elas_port = ' | ||
- | $elas_index = ' | ||
- | $elas_type = NV_PREFIXLANG . ' | ||
- | |||
- | $nukeVietElasticSearh = new NukeViet\NukeVietElasticSearch\Functions( $elas_host, $elas_port, $elas_index ); | ||
- | |||
- | $htm = '< | ||
- | |||
- | $id = $nv_Request-> | ||
- | $per_page = 500;//so ban ghi se chay moi lan request | ||
- | //Index a document: | ||
- | $db_slave-> | ||
- | -> | ||
- | -> | ||
- | -> | ||
- | -> | ||
- | -> | ||
- | $id = 0; | ||
- | $created = 0; | ||
- | $result = $db_slave-> | ||
- | while ($row = $result-> | ||
- | // Lấy nội dung chi tiết | ||
- | $body_contents = $db_slave-> | ||
- | $row = array_merge($row, | ||
- | | ||
- | | ||
- | $response = $nukeVietElasticSearh-> | ||
- | if ($response[' | ||
- | ++$created; | ||
- | } | ||
- | $id = $row[' | ||
- | |||
- | } | ||
- | if ($id) { | ||
- | $redirect = ' | ||
- | $htm .= '</ | ||
- | $time = number_format((microtime(true) - NV_START_TIME), | ||
- | nv_info_die($global_config[' | ||
- | } | ||
- | die(' | ||
- | |||
</ | </ |
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