redisearch 全文搜索引擎 使用 demo

搜索推荐

2017-07-13

302

0

技术:redis 4.XXX 开发版本+ java8 + redisearch

运行环境:IDEA 15.2 + jdk8 + windows 10

demo功能:提供一个redisearch全文搜索引擎的基础使用代码

安装带redisearch模块的redis

下载不稳定版本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);
    }
}

测试下吧自己

欢迎添加微信,互相学习↑↑↑ -_-

发表评论

全部评论:0条

白老虎

programming is not only to solve problems, ways to think