下载
https://github.com/downloads/linkedin/sensei/sensei-1.0.0-release.tar.gz
这个版本是2012年1月份发布的,如果您看到此文时时间太久,请到他们的官方网站去寻找:http://senseidb.com
下载kafka
kafka:由linkedin开源的高吞吐量的消息系统。
http://people.apache.org/~nehanarkhede/kafka-0.7.0-incubating/kafka-0.7.0-incubating-src.tar.gz
下载中文分词包IKAnalyzer http://code..com/p/ik-analyzer/downloads/list
编译sensei
tar zxvf sensei-1.0.0-release.tar.gz
cd sensei-trunk
./bin/build.sh 或者 mvn package 要是没有maven客户端,需要自行安装(ubuntu下直接apt-get install maven)
编译kafka
tar zxvf kafka-0.7.0-incubating-src.tar.gz
cd kafka-0.7.0-incubating-src/
./sbt
update
pacakge
编译IKA 新建一个jar包,里面只有一个类,内容如下:
- public class IKAnalyzerFactory implements SenseiPluginFactory<IKAnalyzer> {
- @Override
- public IKAnalyzer getBean(Map<String, String> initProperties, String fullPrefix, SenseiPluginRegistry pluginRegistry) {
- return new IKAnalyzer();
- }
- }
1)zookeeper的url: sensei.cluster.url=zookeeper.n.miliao.com:2181 2)IKA的class设置: sensei.index.analyzer.class = com.chen.IKA.IKAnalyzerFactory 3)kafka所使用的声明: sensei.gateway.class=com.senseidb.gateway.kafka.KafkaDataProviderBuilder
sensei.gateway.kafka.zookeeperUrl=zookeeper.n.miliao.com #下面的topic很关键,消息系统中用topic区别不同的消息 sensei.gateway.kafka.topic=hotTopic #ProducerData生成时,也应该叫hotTopic
启动sensei 略去了设置schema,可参考http://www.54chen.com/java-ee/scalable-reltime-search-senseidb.html.
cd sensei-trunk
bin/start-sensei-node.sh example/xxx/conf
(所有的使用的jar,比如说kafka\IKA及其依赖的包,都扔到conf/ext下)
配置kafka的server.properties
关键的一点:
1)设置kafka使用的zookeeper地址:
zk.connect=zookeeper.n.miliao.com:2181
启动kafka
cd kafka-0.7.0-incubating-src
nohup bin/kafka-server-start.sh config/server.properties &
[如果你的schema定义无误,那么到这里你就可以通知kafka有消息进入,sensei就会自动开始消费这些消息进行索引等过程]
在具体业务中传入数据参考前文:http://www.54chen.com/java-ee/scalable-reltime-search-senseidb.html
发起搜索
- public static JSONArray doSearch(String key, int limit, int offset, String senseiServer) throws JSONException {
- SenseiClientRequest senseiRequest = SenseiClientRequest.builder().query(Queries.stringQuery(key)).paging(limit, offset)
- .fetchStored(true).build();
- SenseiResult senseiResult = new SenseiServiceProxy(senseiServer, 8080).sendSearchRequest(senseiRequest);
- List<SenseiHit> list = senseiResult.getHits();
- JSONArray l = new JSONArray();
- for (int i = 0; i < list.size(); i++) {
- SenseiHit hit = list.get(i);
- l.put(new JSONObject(hit.getSrcdata()));
- }
- return l;
- }
____EOF____
2012.3.13 version 1
原创文章如转载,请注明:转载自五四陈科学院[http://www.54chen.com]
捐赠说明