当前位置:网站首页>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;
}
}

边栏推荐
- C language data type replacement
- Business modeling of software model | vision
- Go dependency injection -- Google open source library wire
- 每日一题——输入一个日期,输出它是该年的第几天
- Example 006: Fibonacci series
- Typical low code apaas manufacturer cases
- [牛客网刷题 Day4] JZ55 二叉树的深度
- 287. Looking for repeats - fast and slow pointer
- 猜谜语啦(7)
- Wheel 1:qcustomplot initialization template
猜你喜欢

猜谜语啦(6)

319. Bulb switch
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?

Halcon affine transformations to regions

每日一题——替换空格

RT-Thread内核快速入门,内核实现与应用开发学习随笔记

Example 007: copy data from one list to another list.

Run菜单解析

Business modeling of software model | object modeling

Example 009: pause output for one second
随机推荐
资源变现小程序添加折扣充值和折扣影票插件
696. Count binary substring
Guess riddles (5)
Meizu Bluetooth remote control temperature and humidity access homeassistant
Digital analog 1: linear programming
關於線性穩壓器的五個設計細節
Pytorch entry record
Mathematical modeling: factor analysis
Illustration of eight classic pointer written test questions
Latex improve
Wheel 1:qcustomplot initialization template
2022.7.4-----leetcode. one thousand and two hundred
IT冷知识(更新ing~)
猜谜语啦(10)
【日常训练--腾讯精选50】557. 反转字符串中的单词 III
Guess riddles (7)
Matlab tips (28) fuzzy comprehensive evaluation
暑假第一周
STM32---ADC
2020-05-21