`
wuxianjun
  • 浏览: 5814 次
  • 性别: Icon_minigender_1
  • 来自: 中国
社区版块
存档分类
最新评论

compass2.0集成bobo-browse 实现分组统计

阅读更多
bobo-browse 下载地址:http://code.google.com/p/bobo-browse/downloads/list

try {
			final ResourceMapping mapping = ((InternalCompassSession) session)
					.getMapping().findRootMappingByClass(type);
			final LuceneSearchEngineInternalSearch lucene = LuceneHelper
					.getLuceneInternalSearch(session, mapping
							.getSubIndexHash().getSubIndexes(),
							new String[] { mapping.getAlias() });
			
			final MultiValueFacetHandler nameHandler = new MultiValueFacetHandler(name);
			
			List<FacetHandler> handlerList = Arrays.asList(new FacetHandler[]{nameHandler});
			// decorate it with a bobo index reader
            BoboIndexReader boboReader = BoboIndexReader.getInstance(lucene.getReader(),handlerList);
            
            // creating a browse request
            BrowseRequest br=new BrowseRequest();
            br.setCount(10);
            br.setOffset(0);
            br.setQuery(((LuceneSearchEngineQuery) ((DefaultCompassQuery) query)
					.getSearchEngineQuery())
					.getQuery());
            // add the facet output specs
            FacetSpec colorSpec = new FacetSpec();
            colorSpec.setOrderBy(FacetSortSpec.OrderHitsDesc);
            br.setFacetSpec(name,colorSpec);
            
            // perform browse
            Browsable browser=new BoboBrowser(boboReader);
            BrowseResult result = null;
			try {
				result = browser.browse(br);
			} catch (BrowseException e) {
				e.printStackTrace();
			}
			
            Map<String,FacetAccessible> facetMap = result.getFacetMap();
            FacetAccessible colorFacets = facetMap.get(name);
            List<BrowseFacet> facetVals = colorFacets.getFacets();
            Map<String,Integer> map = new HashMap<String, Integer>();
            for (BrowseFacet bf : facetVals) {
            	map.put(bf.getValue(), bf.getHitCount());
	     }
			return map;
		} catch (final IOException e) {
			throw new CompassException(
					"failed to get terms from reader", e);
		}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics