当前位置:网站首页>Redis implements a high-performance full-text search engine -- redisearch
Redis implements a high-performance full-text search engine -- redisearch
2022-07-05 08:42:00 【Sea of sperm whales】
RediSearch It's a Redis modular , by Redis Provide query 、 Secondary indexing and full-text search , His performance is even better than es higher .
install :
docker pull redislabs/redismod:preview
Start the container :
Note that the port number should not be the same as redis The conflict :
docker run -p 6399:6379 --name redismod -v /mydata/redismod/data:/data -d redislabs/redismod:preview

Use springboot Integrate :
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>
Code
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);
// Define an index schema
Schema schema = new Schema().addTextField("title", 5.0).addTextField("body", 1.0).addNumericField("star");
// For the first time run You can comment it out first
client.dropIndex();// Clear the index first
// Create index
client.createIndex(schema, Client.IndexOptions.Default());
// Add document to index
Map<String, Object> fields1 = createDocument(" Any video ", " Content that does not exist in the new document will be preserved . The fields existing in both will be overwritten ", 1000);
Map<String, Object> fields2 = createDocument(" Any communication ", " Content that does not exist in the new document will be lost ", 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(" Content ").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;
}
}

边栏推荐
- 猜谜语啦(5)
- Run菜单解析
- Numpy pit: after the addition of dimension (n, 1) and dimension (n,) array, the dimension becomes (n, n)
- Hello everyone, welcome to my CSDN blog!
- 猜谜语啦(3)
- UE pixel stream, come to a "diet pill"!
- Is the security account given by Yixue school safe? Where can I open an account
- C# LINQ源码分析之Count
- Reasons for the insecurity of C language standard function scanf
- 319. 灯泡开关
猜你喜欢

Pytorch entry record

猜谜语啦(7)

Numpy 小坑:维度 (n, 1) 和 维度 (n, ) 数组相加运算后维度变为 (n, n)

Example 002: the bonus paid by the "individual income tax calculation" enterprise is based on the profit commission. When the profit (I) is less than or equal to 100000 yuan, the bonus can be increase

Classification of plastic surgery: short in long long long

An enterprise information integration system

Low code platform | apaas platform construction analysis

Run菜单解析

猜谜语啦(10)

实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
随机推荐
Latex improve
287. 寻找重复数-快慢指针
U8g2 drawing
Wheel 1:qcustomplot initialization template
Five design details of linear regulator
Sword finger offer 05 Replace spaces
MATLAB skills (28) Fuzzy Comprehensive Evaluation
Search data in geo database
Halcon wood texture recognition
How to manage the performance of R & D team?
Several problems to be considered and solved in the design of multi tenant architecture
L298N module use
C语言标准函数scanf不安全的原因
696. 计数二进制子串
猜谜语啦(11)
Business modeling of software model | stakeholders
Dynamic dimensions required for input: input, but no shapes were provided. Automatically overriding
My university
Halcon shape_ trans
GEO数据库中搜索数据