实时通信 | 轻量级搜索引擎MeiliSearch
2023-06-13 09:15:38 时间
Part1介绍
MeiliSearch是一个功能强大,快速,开源,易于使用和部署的搜索引擎。搜索和索引都是高度可定制的。允许输入、过滤器和同义词等特性都是开箱即用的。是近两年开源的项目,同样也支持中文分词,在小数据规模下可以实现比ElasticSearch更加快速和易用的搜索体验。
Part2支持的功能
- 开源
- 用户量(开源搜索引擎第二名)
- 中文分词
- 同义词
- 纠错
- 高亮
- 全文返回
- 高级搜索
- 停用词、停用字段
- 加权、降权
- 逻辑搜索
- 唯一字段聚合
- 分页
- 重新索引
Part3使用
1第 1 步:设置和安装
我们将从下载和安装 Meilisearch 开始。您可以选择在本地安装 Meilisearch 或通过云服务部署,以下使用Docker部署服务端。
Docker部署
# Fetch the latest version of Meilisearch image from DockerHub
docker pull getmeili/meilisearch:latest
# Launch Meilisearch
docker run -it --rm \
-p 7700:7700 \
-v d:/work/meilisearch/data.ms:/data.ms \
getmeili/meilisearch:latest
运行Meilisearch
成功运行 Meilisearch 后,您应该会看到以下响应:
恭喜!您已准备好继续下一步!
2第 2 步:添加文档
对于这个快速入门,我们将使用PHP作为客户端演示案例
安装PHP的SDK
composer require meilisearch/meilisearch-php \
guzzlehttp/guzzle \
http-interop/http-factory-guzzle:^1.0
SDK 地址 https://github.com/meilisearch/meilisearch-php/
添加索引文档
require_once __DIR__ . '/vendor/autoload.php';
use MeiliSearch\Client;
$client = new Client('http://192.168.3.12:7700');
# An index is where the documents are stored.
$index = $client->index('movies');
$documents = [
['id' => 1, 'title' => 'Carol', 'genres' => ['Romance, Drama']],
['id' => 2, 'title' => 'Wonder Woman', 'genres' => ['Action, Adventure']],
['id' => 3, 'title' => 'Life of Pi', 'genres' => ['Adventure, Drama']],
['id' => 4, 'title' => 'Mad Max: Fury Road', 'genres' => ['Adventure, Science Fiction']],
['id' => 5, 'title' => 'Moana', 'genres' => ['Fantasy, Action']],
['id' => 6, 'title' => 'Philadelphia', 'genres' => ['Drama']],
];
# If the index 'movies' does not exist, Meilisearch creates it when you first add the documents.
$index->addDocuments($documents); // => { "uid": 0 }
3第 三 步:使用文档
基础搜索
$client = new Client('http://192.168.3.12:7700');
# An index is where the documents are stored.
$index = $client->index('movies');
// Meilisearch is typo-tolerant:
$hits = $index->search('wondre woman')->getHits();
print_r($hits);
打印信息
自定义搜索
require_once __DIR__ . '/vendor/autoload.php';
use MeiliSearch\Client;
$client = new Client('http://192.168.3.12:7700');
$index->search(
'phil',
[
'attributesToHighlight' => ['*'],
]
)->getRaw(); // Return in Array format
输出结果
{
"hits": [
{
"id": 6,
"title": "Philadelphia",
"genre": ["Drama"],
"_formatted": {
"id": 6,
"title": "<em>Phil</em>adelphia",
"genre": ["Drama"]
}
}
],
"offset": 0,
"limit": 20,
"processingTimeMs": 0,
"query": "phil"
}
相关文章
- 利用EEG和动态编码器-解码器建模框架实时估算驾驶员睡意
- 【Linux 内核】进程管理 - 进程优先级 ② ( prio 调度优先级 | static_prio 静态优先级 | normal_prio 正常优先级 | rt_priority 实时优先级 )
- AntDB数据库携超融合流式实时数仓亮相第25届中国高速公路信息技术化大会
- 机器人焊缝追踪是怎么实现实时补偿的
- 如何使用canal监控mysql数据库实现elasticsearch索引实时更新
- Linux网卡性能测试:实时提升系统性能(linux网卡性能测试)
- Linux 文件监控:实时保护数据安全(监控Linux文件)
- Linux进程间通信实时探索(linux进程通信实验)
- 利用Redis队列推送消息实现实时通信(redis队列推送消息)
- Oracle12实现实时数据同步的进步(oracle12实时同步)
- Redis消息推送实现实时通信的利器(redis消息推送服务器)
- 腾讯实时合照专利获授权,可实现不同终端或地点用户使用
- 课程预告 | UCloud实时通信平台负责人裴志伟:线下教育如何平稳地过渡到线上?
- Iframe自适应高度并实时监控高度变化的js代码
- 通过rsync+inotify实现数据的实时备份配置