antsfree / mxusearch
此包的最新版本(0.1.4)没有可用的许可证信息。
这是一个 mxu 全文搜索应用。
0.1.4
2017-10-27 03:15 UTC
This package is not auto-updated.
Last update: 2024-09-26 05:16:45 UTC
README
服务说明
全文检索服务是基于开源项目
xunsearch
封装的全文搜索引擎,服务仍在完善。
服务安装配置
1. 通过composer
安装搜索服务,输入以下命令安装最新版本。
composer require antsfree/mxusearch dev-master
OR
composer require antsfree/mxusearch '^0.1'
2. 在 config/app.php 的服务数组 providers 中添加以下服务。
Antsfree\Mxusearch\MxusearchProvider::class
3. 在 config/app.php 的门面数组 aliases 中添加以下门面。
'Mxusearch' => Antsfree\Mxusearch\Mxusearch::class,
4. 执行以下命令,配置mxusearch.php
配置文件;
php artisan vendor:publish --provider="Antsfree\Mxusearch\MxusearchProvider"
5. 分布式安装,每个laravel
项目需要配置以下env
参数:
注意:以上配置都有默认值,其中索引、搜索的host在分布式部署上需要注意区分。统一指向讯搜服务所在服务器。
6. 执行console
命令,生成ini
文件
php artisan search:reset-ini
基本服务方法设定
Artisan命令服务
提供 artisan 的命令实现
ini配置
1、 ini
配置文件:mxu-backend/config/mxusearch.ini
;
2、 服务器配置
project.name = {{MXUSEARCH_PROJECT}}// 项目名称
project.default_charset = {{MXUSEARCH_CHARSET}}// 字符编码
server.index = {{MXUSEARCH_INDEX_HOST}}:{{MXUSEARCH_INDEX_PORT}}// 索引服务端配置(Host&端口)
server.search = {{MXUSEARCH_SEARCH_HOST}}:{{MXUSEARCH_SEARCH_PORT}}// 搜索服务端配置(Host&端口)
3、 索引字段配置
[id]
type = id
tokenizer = full
[column_id]
tokenizer = full
index = self
......
......
方法说明
multiSearch(多条件查询)
方法示例
/**
* 多条件查询功能
*
* @param $keyword
* @param string $field
* @param array $other_field_value
* @param array $range
* @param int $limit
* @param int $page
* @param array $sorts
*
* @return array
*/
public function multiSearch($keyword, $field = '', array $other_field_value = [], array $range = [], $limit = 0, $page = 1, array $sorts = []);
请求参数
请求示例
$key = '我是关键词';
$field = 'title';
// 多条件
$other_field_value = [
'site_id' => 1,
'column_id' => 2,
'type' => 'article',
// ...
];
$range = [
[
'field' => 'publish_time',
'from' => '2017-10-18 12:07:26',
'to' => '2017-10-23 17:07:26',
],
// ...
];
// 分页控制
$limit = 10;
$page = 1;
// 排序条件(true 为正序, false 为倒序)
$sorts = [
'field_1' => true, // 根据 field_1 正序排序
'field_2' => false // 根据 field_2 倒序排序
];
// 调用服务
Mxusearch::multiSearch($key, $field, $other_field, $range, $limit, $page, $sorts);
索引管理注意事项:
- 索引更新:多条同时更新存在时间误差,具体时长和需要创建的索引数量有关系,具体在
2~4分钟
能实现索引的更新; - 索引创建:多条同时新增存在时间误差,具体时长和需要创建的索引数量有关系,具体在
2~4分钟
能实现索引的创建; - 当前只支持单库存储;
- ini配置默认存于
laravel config
目录中;
待办事项列表
- 增加热词删除服务;
- 重构或优化高级搜索服务,支持搜索条件/类型可扩展;