The full-text search service is a full-text search engine encapsulated by the open source project
xunsearch, and the service is still being improved.
1. Install the search service through composer and enter the following command to install the latest version.
composer require antsfree/mxusearch dev-master
OR
composer require antsfree/mxusearch '^0.1'
2. Add the following services in the service array providers in config/app.php.
AntsfreeMxusearchMxusearchProvider::class
3. Add the following facade in the facade array aliases in config/app.php.
'Mxusearch' => AntsfreeMxusearchMxusearch::class,
4. Execute the following command to configure the mxusearch.php configuration file;
php artisan vendor:publish --provider="AntsfreeMxusearchMxusearchProvider"
5. Distributed installation, each laravel project needs to configure the following env parameters:
| Env configuration | Chinese definition | default value |
|---|---|---|
| MXUSEARCH_PROJECT | Index library name | mxu_project |
| MXUSEARCH_CHARSET | Character encoding | UTF-8 |
| MXUSEARCH_INDEX_HOST | Index server IP | 127.0.0.1 (see "Note" for the distributed deployment configuration) |
| MXUSEARCH_INDEX_PORT | Index port | 8383 |
| MXUSEARCH_SEARCH_HOST | Search the server IP | 127.0.0.1 (see "Note" for the distributed deployment configuration) |
| MXUSEARCH_SEARCH_PORT | Search port | 8384 |
| MXUSEARCH_INI | INI configuration file name | mxusearch.ini |
Note: All the above configurations have default values, among which the index and search hosts need to be distinguished in distributed deployment. Uniformly point to the server where the search service is located.
6. Execute the console command to generate an ini file
php artisan search:reset-ini
| Serial number | Method name | Chinese definition | Remark |
|---|---|---|---|
| 1 | addIndex | Create an index | Single supports instant synchronization, multiples have time errors, specific to 2 to 3 minutes, depending on the specific situation |
| 2 | deleteIndex | Delete the index | Multiple single pieces take effect immediately without delay |
| 4 | searchIndex | Find index | Support setFuzzy fuzzy query, support specific field-oriented query (column:key) |
| 5 | cleanIndex | Clear the index | Effective immediately without delay |
| 6 | rebuildIndex | Rebuild the index | Not supported yet |
| 7 | getIndexCount | Get the total number of indexes | |
| 8 | checkServer | Detect full text search service status | Directly output the current status and index number |
| 9 | flushIndex | Force refresh of search log | |
| 10 | getHotWords | Get popular search terms | |
| 11 | getMatchNum | Get the number of index matches | |
| 12 | flushIndex | Force refresh of index | Force refresh to realize the index's instant search |
| 13 | flushLogging | Force refresh of search log | |
| 14 | checkServer | Xunsou service status detection | |
| 15 | getKeyWords | Text word segmentation function | |
| 16 | resetIniFile | Reset INI file method | |
| 17 | multiSearch | Multi-condition query |
Provide artisan command implementation:
| Serial number | artisan command | console meaning | Remark |
|---|---|---|---|
| 1 | search:add | Create an index | Single supports instant synchronization, multiples have time errors, specific to 2 to 3 minutes, depending on the specific situation |
| 2 | search:delete | Delete the index | Multiple single pieces take effect immediately without delay |
| 3 | search:search | Find index | Terminal interaction, you can select the matching range |
| 4 | search:clear | Clear the index | Effective immediately without delay |
| 5 | search:check-server | Detect full text search service status | Directly output the current status and index number |
| 6 | search:flush | Force refresh of index and search log | By default, it is asynchronously created indexes, and forced refresh to implement instant search of indexes. |
| 7 | search:scws | Text word participle command | |
| 8 | search:reset-ini | Reset the ini file | Reconfigure INI files according to configuration items |
| 9 | search:list-hotwords | View the hot word list | Direct output from the command line |
1. ini configuration file: mxu-backend/config/mxusearch.ini ;
2. Server configuration
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. Index field configuration
[id]
type = id
tokenizer = full
[column_id]
tokenizer = full
index = self
......
......
Method Example
/**
* 多条件查询功能
*
* @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 = []);
Request parameters
| Parameter name | type | Parameter description | Required | Remark |
|---|---|---|---|---|
| $keyword | string | Keywords | N | |
| $field | string | Field name | N | Default null, indicating full text matching |
| $other_field_value | array | Other multi-condition parameters | N | Default empty array |
| $range | array | Interval condition filtering | N | |
| $limit | int | Pagination parameters | N | Default 10 items |
| $page | int | Pagination parameters | N | Default 1 |
| $sorts | array | Sort conditions | N | Default empty |
Request Example
$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分钟;laravel config directory by default;Xunsou SDK Guide