技术:redis 4.XXX 开发版本+ java8 + redisearch
运行环境:IDEA 15.2 + jdk8 + windows 10
demo功能:提供一个redisearch全文搜索引擎的基础使用代码
下载不稳定版本redis https://github.com/antirez/redis/archive/unstable.tar.gz,编译安装redis
下载,编译,运行 redisearch模块 http://demoworld.tech/Redisearch_%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B
http://git.oschina.net/youlixishi/demo-world/tree/master/src/redisearch
public class SearchTest {
@Test
public void createIndexTest1() {
Client client = new Client("demoworld", "192.168.222.130", 6380, 1000, 2);
Schema sc = new Schema()
.addTextField("title", 5.0)
.addTextField("body", 1.0)
.addNumericField("price");
client.createIndex(sc, Client.IndexOptions.Default());
Map<String, Object> fields = new HashMap<>();
fields.put("title", "hello world");
fields.put("body", "lorem ipsum");
fields.put("price", 1337);
// redis.clients.jedis.commands.ProtocolCommand
Assert.assertEquals(true, client.addDocument("doc1", fields));
}
@Test
public void search1() {
Client client = new Client("demoworld", "192.168.222.130", 6380, 1000, 20);
Query q = new Query("hello world")
.addFilter(new Query.NumericFilter("price", 0, 2000))
.limit(0, 5);
SearchResult res = client.search(q);
}
}
欢迎添加微信,互相学习↑↑↑ -_-
白老虎
programming is not only to solve problems, ways to think
grafana 级连 菜单 templating (variables) 配置
rocketmq 集群搭建 (2master + 2slave + 2namesrv)
AI 机器人 抓取 微信 聊天中的 百度网盘 分享地址和密码