bobo-browse 是一用java写的lucene扩展组件,通过它可以很方便在lucene上实现分组统计功能。

可以从http://sna-projects.com/bobo/上下载和查看相关文档。

下面介绍如何使用:

第一步:设置相关配置文件

bobo-browse 使用了spring,这里主要配置bobo.spring和field.xml两个文件。可以从他的源码例子中找到这两个文件,参考它做相应的修改。

bobo.spring

<?xml version="1.0" encoding="UTF-8"?>  <beans xmlns="http://www.springframework.org/schema/beans"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">  

<bean id="color" class="com.browseengine.bobo.facets.impl.SimpleFacetHandler">  <constructor-arg value="color"/>  </bean>  

<bean id="category" class="com.browseengine.bobo.facets.impl.SimpleFacetHandler">  <constructor-arg value="category"/>  </bean>  

<bean id="city" class="com.browseengine.bobo.facets.impl.PathFacetHandler">  <constructor-arg value="city"/>  <property name="separator" value="/"/>  </bean>  

<bean id="makemodel" class="com.browseengine.bobo.facets.impl.PathFacetHandler">  <constructor-arg value="makemodel"/>  <property name="separator" value="/"/>  </bean>  

<bean id="year" class="com.browseengine.bobo.facets.impl.RangeFacetHandler">  <constructor-arg value="year"/>  <constructor-arg value="true"/>  </bean>  

<bean id="price" class="com.browseengine.bobo.facets.impl.RangeFacetHandler">  <constructor-arg value="price"/>  <constructor-arg>  <bean class="com.browseengine.bobo.facets.data.PredefinedTermListFactory">  <constructor-arg value="java.lang.Float"/>  <constructor-arg value="00000000000000000000"/>  </bean>  </constructor-arg>  <constructor-arg value="true"/>  </bean>  

<bean id="mileage" class="com.browseengine.bobo.facets.impl.RangeFacetHandler">  <constructor-arg value="mileage"/>  <constructor-arg>  <bean class="com.browseengine.bobo.facets.data.PredefinedTermListFactory">  <constructor-arg value="java.lang.Integer"/>  <constructor-arg value="00000000000000000000"/>  </bean>  </constructor-arg>  <constructor-arg>  <list>  <value>[* TO 12500]</value>  <value>[12501 TO 15000]</value>  <value>[15001 TO 17500]</value>  <value>[17501 TO *]</value>  </list>  </constructor-arg>  </bean>  

<bean id="tags" class="com.browseengine.bobo.facets.impl.MultiValueFacetHandler">  <constructor-arg value="tags"/>  </bean>  

<bean id="handlers" class="java.util.ArrayList">  <constructor-arg>  <list>  <ref bean="color"/>  <ref bean="category"/>  <ref bean="city"/>  <ref bean="makemodel"/>  <ref bean="year"/>  <ref bean="price"/>  <ref bean="mileage"/>  <ref bean="tags"/>  </list>  </constructor-arg>  </bean>  </beans>  

field.xml(前两天收到软件原作者John Wang的邮件 说field.xml不是必须的。)

<?xml version="1.0" encoding="UTF-8"?>  <field-info>  <field>  <name type="simple">category</name>  <param name="preloadcache" value="true"/>  </field>  <field>  <name type="path">city</name>  <param name="preloadcache" value="true"/>  </field>  <field>  <name type="simple">color</name>  <param name="preloadcache" value="true"/>  </field>  <field>  <name type="path">makemodel</name>  <param name="preloadcache" value="true"/>  </field>  <field>  <name type="range">price</name>  <param name="preloadcache" value="false"/>  <param name="value_type" value="float"/>  <param name="format" value="00000000000000000000"/>  <param name="display" value=".00"/>  </field>  <field>  <name type="range">year</name>  <param name="preloadcache" value="false"/>  <param name="value_type" value="integer"/>  <param name="format" value="00000000000000000000"/>  </field>  <field>  <name type="range">mileage</name>  <param name="preloadcache" value="false"/>  <param name="value_type" value="integer"/>  <param name="format" value="00000000000000000000"/>  </field>  <field>  <name type="multi">tags</name>  <param name="maxVal" value="15"/>  <param name="preloadcache" value="true"/>  </field>  </field-info>  

该组件提供了五种FacetHandler 来处理上面配置中的字段,字段中的一些属性设置可以参考他的api文档。

simple: (com.browseengine.bobo.facets.impl.SimpleFacetHandler ) Used when there is a discrete set of facet values, for example: color, with values: red,green,blue,white,black. Each document can have only 1 value in this field. When being indexed, this field should not be tokenized.

该字段的值只能对应一个分类或分组,并且该字段在索引是必须为非分词的。

multi: (com.browseengine.bobo.facets.impl.MultiValueFacetHandler ) Similar to simple type field, multi field allows a document to have multiple values. When being indexed, this field can be tokenized. Or alternatively, one can index multiple values in multiple document fields under the same field name.

该字段可以对应多个分类,并且字段需要分词的。

compact multi: (com.browseengine.bobo.facets.impl.CompactMultiValueFacetHandler ) Same as MultiValueFacetHandler, multiple values are allowed, the total possible values are limited to 32. However, this is more efficient than MultiValueFacetHandler and has a smaller memory footprint.

感觉应该和multi类似,我还没用过。

path: (com.browseengine.bobo.facets.impl.PathFacetHandler ) Used to denote facet values with hierarchical structure, for example: "A/B/C/D" Each document can have only 1 value in this field. When being indexed, this field should not be tokenized.

该字段我的理解是这样的,当前值属于:A(顶级分类)=>B(二级分类)=>C(三级分类)=>D(四级分类),字段必须为未分词的。

range: (com.browseengine.bobo.facets.impl.RangeFacetHandler ) Used to denote a range of facet, e.g. dates, prices etc. Each document can have only 1 value in this field. When being indexed, this field should not be tokenized. Furthermore, the values need to be formatted to ensure sorting by lexical order is the same as the value order.

范围,不用我介绍了,上面的bobo.spring里有这个例子。

参考它自带的例子 将你要进行分组的字段 设置好bobo.spring和field.xml这两个文件。

同时这两个文件要放在和索引文件的同一目录下。

第二步:搜索实现

字段配置写好之后,就可以在搜索的java文件中加上一些代码就可以得到统计结果了。

参考文档 http://code.google.com/p/bobo-browse/wiki/GettingStarted[已迁移到:http://linkedin.jira.com/wiki/display/BOBO/Home]

比如我要获取color字段按多到少的10个值

// opening a lucene index  Directory idx = FSDirectory.open(new File("myidx"));  IndexReader reader = IndexReader.open(idx);  // decorate it with a bobo index reader  BoboIndexReader boboReader = BoboIndexReader.getInstance(reader);  // creating a browse request  BrowseRequest br=new BrowseRequest();  br.setCount(10);  br.setOffset(0);  // parse a query  QueryParser qp = new QueryParser(fields,new StandardAnalyzer());  Query q=qp.parse(keyword);  br.setQuery(q);   // add the facet output specs  FacetSpec colorSpec = new FacetSpec();  

colorSpec.setMaxHitCount(10);  colorSpec.setOrderBy(FacetSortSpec.OrderHitsDesc);   br.setFacetSpec("color",colorSpec);  // perform browse  Browsable browser=new BoboBrowser(boboReader);  BrowseResult result=browser.browse(br);  int totalHits = result.getNumHits();  BrowseHit[] hits = result.getHits();   Map<String,FacetAccessible> facetMap = result.getFacetMap();   FacetAccessible colorFacets = facetMap.get("color");  List<BrowseFacet> facetVals = colorFacets.getFacets();   

经本人测试,效率还不错 ,有问题欢迎与我站内联系。

效果 可以参考它上面介绍的网站 http://www.simplyhired.com/a/jobs/list/o-13201

获取源码:https://github.com/javasoze/bobo

主页:http://sna-projects.com/bobo/

转载于:https://www.cnblogs.com/ibook360/archive/2011/11/15/2249564.html

利用bobo-browse 实现lucene的分组统计功能相关推荐

  1. lucene实现分组统计的方法

    转:http://www.cnblogs.com/huangfox/archive/2012/07/10/2584750.html http://blog.163.com/liugangc@126/b ...

  2. 记录一下pandas的分组统计功能,agg

    主要是记录一下pandas学习,最近要统计一个数据,我向以前stata里面有一个很好用的函数,就是tabstat,可以分组统计,并且输出很多指标. 最近处理数据我的数据是这样的. 我向按照 valid ...

  3. 利用JS实现QQ好友的分组展开功能

    用到的属性-- openUl list-style: none去掉ul前面的原点 效果图(展开后): 展开前: <!DOCTYPE html> <html lang="en ...

  4. MongoDB 分组统计

    [摘要] MongoDB 在进行分组统计时如果面对一些比较复杂的计算情况,往往会遇到 shell 脚本过于复杂的问题.而集算器 SPL 语言,则因其有丰富的函数库及易用性恰好能弥补 Mongo 这方面 ...

  5. spss分组统计的方法

    在做数据分析的时候,用的工具是excel,spss和oracle.因为对spss不了解,分组统计的活一直靠写sql,单调重复的工作让人烦躁,而且容易出错.后来发现spss有很好的分组统计功能,以二维数 ...

  6. Sql Server 中利用游标对table 的数据进行分组统计式输出…

    Sql Server 中利用游标对table 的数据进行分组统计式输出- Table Name: Tb_Color Create table Tb_Color(id int identity(1,1) ...

  7. mysql 按小时分组统计_PowerBI业务分析:按排名分组统计

    对数据进行分组统计是常用的一种分析方式,之前的文章中曾介绍了按照客户订单数量进行分组统计,Power BI 数据分析应用:客户购买频次分布这篇文章介绍一下PowerBI如何按照客户的排名进行分组统计, ...

  8. 问题 B: 分组统计

    分组统计 问题 B: 分组统计时间限制: 1 Sec 内存限制: 32 MB 提交: 416 解决: 107 [提交][状态][讨论版][命题人:外部导入] 题目描述 先输入一组数,然后输入其分组,按 ...

  9. java 对 mongoDB 分组统计操作 以及一些常用操作

    为什么80%的码农都做不了架构师?>>>    /*** * 功能描述:* * @author :xiaoyu 创建日期 :2014年2月19日 下午2:23:44* * @para ...

最新文章

  1. “Hey Siri” 背后的黑科技大揭秘!
  2. playsound函数Linux使用,函数PlaySound和sndPlaySound的用法
  3. 个人项目中的WCF使用
  4. [一文一命令]less命令详解
  5. Lucene 4.X 倒排索引原理与实现: (3) Term Dictionary和Index文件 (FST详细解析)——直接看例子就明白了!!!...
  6. suse安装gcc,升级到4.8.5
  7. linux过滤输出内容,Linux内容整理--过滤器、输入输出及管道
  8. centos 5 .6安装NTP服务器
  9. 阮一峰react demo代码研究的学习笔记 - React.createElement
  10. PyCharm设置字体大小与颜色
  11. time是python的标准库吗_python3关于date和time的标准库
  12. 怎样实现短信验证功能
  13. 开课吧Java课堂:什么是主线程?如何去运用?
  14. 人脸方向学习(十三):Face Tracking-人脸跟踪KCF解读
  15. C语言atoi()函数:将字符串转换成int(整数)
  16. SPSS因子分析经典案例分享
  17. 技术团队管理:技术分享
  18. 计算机桌面是快捷方式,我的电脑桌面上的图标都变成快捷方式了怎么处理?
  19. 微信小程序:简单计算器
  20. JDK1.8 升级这么久!Stream 流的规约操作有哪些?

热门文章

  1. python四种可变类型_Python的可变类型与不可变类型
  2. c语言向自定数组_C语言怎么向自定义函数中传入一个数组,处理完再返回新的数组?...
  3. php缩略图代码,php 缩略图实现函数代码_php
  4. java 不定参数_Java不定参数
  5. mysql insert
  6. python Iterable
  7. Web_audio_spatialization_basics
  8. vim shell命令
  9. chrome 设置user agent
  10. python db api_dbapi · PyPI