简介
Meilisearch是一个闪电般的快速搜索引擎
支持多种语言
- 任何使用空格分隔单词的语言
- 中文
- 希伯来语
- 韩语
- 日语
- 泰语
提供多种sdk,开箱即用
- .NET(opens new window)
- Dart(opens new window)
- Golang(opens new window)
- Java(opens new window)
- JavaScript(opens new window)
- PHP(opens new window)
- Python(opens new window)
- Ruby(opens new window)
- Rust(opens new window)
- Swift(opens new window)
相关资料
使用
环境搭建(docker)
拉取镜像
docker pull getmeili/meilisearch:v1.0.2
启动服务
docker run -it --rm \ --name meilisearch \ -d -p 7700:7700 \ -e MEILI_ENV='development' \ -e MEILI_MASTER_KEY='123456' \ -v /data/meili_data:/meili_data getmeili/meilisearch:v1.0.2
MEILI_MASTER_KEY 属性可以忽略
- web访问地址:http://localhost:7700/
基础Demo(java版)
maven
<dependencies> <dependency> <groupId>com.meilisearch.sdk</groupId> <artifactId>meilisearch-java</artifactId> <version>0.9.0</version> </dependency> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.8.11</version> </dependency> <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>okhttp</artifactId> <version>4.9.3</version> </dependency> </dependencies>
获取Client
Client client = new Client(new Config("http://localhost:7700", "123456"));
索引
索引是一组具有关联设置的文档。它类似于SQLMongoDB 中的表或集合
public static void createIndex(Client client) throws MeilisearchException { TaskInfo taskInfo = client.createIndex("movies", "id"); }
文档
文档是由一个或多个字段组成的对象。每个字段都包含一个属性及其相关值。文档作为组织数据的容器,是Meilisearch数据库的基本构建块。要搜索文档,您必须先将其添加到索引中
添加文档
public static void addDocuments(Client client) throws MeilisearchException, IOException { Path fileName = Path.of("/movies.json"); String moviesJson = Files.readString(fileName); Index index = client.index("movies"); index.addDocuments(moviesJson); }
修改文档
public static void updateDocuments(Client client) throws MeilisearchException { Index index = client.index("movies"); TaskInfo taskInfo = index.updateDocuments("{\"id\": \"1\",\"zn\": \"测试测试\",\"en\": \"test\"}"); }
删除文档
public static void deleteDocument(Client client) throws MeilisearchException { Index index = client.index("movies"); TaskInfo taskInfo = index.deleteDocument("2"); }
简单查询
public static void sampleSearch(Client client) throws MeilisearchException { Index index = client.index("movies"); // Meilisearch is typo-tolerant: SearchResult results = index.search("Room"); System.out.println(JSONUtil.toJsonStr(results)); }
此文章仅是简单使用demo,更多功能请参考官方文档