redis-search(java开发中的问题)

redis-search支持中文,还可以进行精确的短语搜索,否定搜索,前缀搜索,可选关键字和组合redis。

因为java版本支持度没有那么高,如果有需要的功能没提供方法的话,需要Redissearch-source.jar解压,然后就是io,和meta-inf(用于存放一些meta information相关的文件),源码修改io。

譬如修改源码部分可以使用:FT.SUGGET,FT.SUGadd

先在package io.redisearch.client;类Commands的CommandProvider接口中 加入

ProtocolCommand suggetGetCommand();

ProtocolCommand suggetAddCommand();

在实现 @Override

        public ProtocolCommand suggetAddCommand(){

            return Command.SUGADD;

        }

        @Override

        public ProtocolCommand getCreateCommand() {

            return Command.CREATE;

        }

最后在class Client写好如下方法就可以调用了

/**

* @param key

* @param string

* @param score

*/

public long sugAdd(String key, String string, Double score) {

// TODO Auto-generated method stub

ArrayList args = new ArrayList<>(Arrays.asList(key,string, Double.toString(score)));

try (Jedis conn = _conn()) {

            long resp = sendCommand(conn, commands.suggetAddCommand(), args.toArray(new String[args.size()])).getIntegerReply();

            return resp;

        }

}

你可能感兴趣的:(redis-search(java开发中的问题))