当前位置:网站首页>Redis实现高性能的全文搜索引擎---RediSearch
Redis实现高性能的全文搜索引擎---RediSearch
2022-07-05 08:40:00 【抹香鲸之海】
RediSearch是一个Redis模块,为Redis提供查询、二次索引和全文搜索,他的性能甚至比es还要高。
安装:
docker pull redislabs/redismod:preview
启动容器:
注意端口号不要和redis冲突了:
docker run -p 6399:6379 --name redismod -v /mydata/redismod/data:/data -d redislabs/redismod:preview

使用springboot 集成一下:
pom
<dependency>
<groupId>com.redislabs</groupId>
<artifactId>jredisearch</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.3.10</version>
</dependency>
<dependency>
<groupId>com.hankcs</groupId>
<artifactId>hanlp</artifactId>
<version>portable-1.7.8</version>
</dependency>
代码
package com.example.demo.Utils.RedisearchUtills;
import io.redisearch.*;
import io.redisearch.client.AddOptions;
import io.redisearch.client.Client;
import java.util.HashMap;
import java.util.Map;
public class redisearchMain {
public static void main(String[] args) {
Client client = new Client("student", "120.48.54.67", 6399);
// 定义一个索引模式
Schema schema = new Schema().addTextField("title", 5.0).addTextField("body", 1.0).addNumericField("star");
// 首次run 可以先注释掉
client.dropIndex();//先清除索引
// 创建索引
client.createIndex(schema, Client.IndexOptions.Default());
// 向索引中添加文档
Map<String, Object> fields1 = createDocument("任何视频", "新文档中不存在的内容将被保留。两者中存在的字段都会被覆盖", 1000);
Map<String, Object> fields2 = createDocument("任何通信", "新文档中不存在的内容将丢失", 500);
// client.addDocument("doc1", fields1);
// client.addDocument("doc2", fields2);
Document doc1 = new Document("doc1", fields1, 1.0, null);
Document doc2 = new Document("doc2", fields2, 1.0, null);
AddOptions options = new AddOptions().setNosave(false);
options.setLanguage("chinese");
client.addDocument(doc1, options);
client.addDocument(doc2, options);
Query query = new Query("内容").addFilter(new Query.NumericFilter("star", 0, 1500)).setWithScores().limit(0, 10);
SearchResult result = client.search(query);
result.docs.stream().forEach(docs->
System.out.println("====="+docs)
);
}
private static Map<String, Object> createDocument(String title, String body, Integer price){
Map<String, Object> fields = new HashMap<String, Object>();
fields.put("title", title);
fields.put("body", body);
fields.put("star", price);
return fields;
}
}

边栏推荐
- Some pitfalls of win10 network sharing
- leetcode - 445. 两数相加 II
- Run menu analysis
- Lori remote control LEGO motor
- 实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
- C language data type replacement
- Bluebridge cup internet of things basic graphic tutorial - GPIO input key control LD5 on and off
- 猜谜语啦(11)
- Guess riddles (3)
- MATLAB小技巧(28)模糊綜合評價
猜你喜欢
Example 001: the number combination has four numbers: 1, 2, 3, 4. How many three digits can be formed that are different from each other and have no duplicate numbers? How many are each?

Xrosstools tool installation for X-Series

Sword finger offer 06 Print linked list from end to end
![[noi simulation] juice tree (tree DP)](/img/19/bc71e8dc3958e4cb87b31423a74617.png)
[noi simulation] juice tree (tree DP)

Shell script

Guess riddles (11)
AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)](/img/3b/c94b8466370f4461875c85b4f66860.png)
[NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)

【NOI模拟赛】汁树(树形DP)

99 multiplication table (C language)

Guess riddles (4)
随机推荐
L298N module use
MATLAB skills (28) Fuzzy Comprehensive Evaluation
Apaas platform of TOP10 abroad
U8g2 drawing
暑假第一周
Arduino+a4988 control stepper motor
Arduino burning program and Arduino burning bootloader
Guess riddles (142)
Sword finger offer 06 Print linked list from end to end
PIP installation
Run menu analysis
Sword finger offer 09 Implementing queues with two stacks
Example 008: 99 multiplication table
Guess riddles (8)
Shell script
[matlab] matlab reads and writes Excel
【三层架构及JDBC总结】
Is the security account given by Yixue school safe? Where can I open an account
287. 寻找重复数-快慢指针
UE pixel stream, come to a "diet pill"!