yutool-search搜索引擎组件
快速上手
1. Maven依赖
在项目的 pom.xml 中添加以下依赖:
xml
<parent>
<groupId>com.yupaits</groupId>
<artifactId>yutool-parent</artifactId>
<version>${yutool.version}</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>com.yupaits</groupId>
<artifactId>yutool-search</artifactId>
</dependency>
</dependencies>
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
2. 配置文件
因为yutool-search是基于redisearch实现的,因此需要在配置文件application.yml
中添加redis相关配置:
yaml
spring:
redis:
host:
port:
timeout:
password:
1
2
3
4
5
6
2
3
4
5
6
3. 注入SearchTemplate实例实现搜索功能
示例如下:
Java
public class BlogSearcherTests {
private final SearchTemplate searchTemplate;
public void testCreateIndex() {
searchTemplate.createIndex('blog', new Schema().addTextField('content', 1.0), Client.IndexOptions.defaultOptions());
}
public void testSearch() {
searchTemplate.search('blog', '震惊', SearchProps.defaultProps());
}
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
其他说明
因为yutool-search是基于redisearch实现的,因此需要先安装RediSearch。有以下两种方式安装RediSearch:
- 安装Redis 4.0+,再安装RedisMod中的RediSearch模块
- 安装Redis Stack,Redis Stack中自带了RediSearch模块
评论区留言准则:
1. 本评论区禁止传播封建迷信、吸烟酗酒、低俗色情、赌博诈骗等任何违法违规内容。
2. 当他人以不正当方式诱导打赏、私下交易,请谨慎判断,以防人身财产损失。
3. 请勿轻信各类招聘征婚、代练代抽、私下交易、购买礼包码、游戏币等广告信息,谨防网络诈骗。