0

I am trying to move from lucene 2.4 to 4.4. I had used bobo-browse for faceting in 2.4.

I used below code (from Lucene examples) to query documents and get facets.

List<FacetRequest> categories = new ArrayList<FacetRequest>();
categories.add(new CountFacetRequest(new CategoryPath("CATEGORY_PATH", '/'), 10));
FacetSearchParams searchParams = new FacetSearchParams(categories);    
TopScoreDocCollector topScoreDocCollector = TopScoreDocCollector.create(200, true);
FacetsCollector facetsCollector = FacetsCollector.create(searchParams, indexReader, taxonomyReader);
indexSearcher.search(new MatchAllDocsQuery(), MultiCollector.wrap(topScoreDocCollector, facetsCollector));

Above code gives me results along with facets.

Now I want to add a Sort field on document, say I want to sort by name. I can achieve this using following

Sort sort = new Sort(new SortField("NAME", Type.STRING));    
TopFieldDocs docs = indexSearcher.search(new MatchAllDocsQuery(), 100, sort);

Now, how do I achieve sorting along with faceting, because there is no method in IndexSearcher which has Collector and Sort.

goodsanket
  • 13
  • 4
  • Found answer. Heres how. searcher.search(query, MultiCollector.wrap(tfc, fc)); Basically IndexSearcher.search(..., Sort) creates TopFieldCollector internally, so you need to create it outside and wrap both collectors with MultiCollector. – goodsanket Oct 08 '13 at 10:41
  • 2
    Can you add your comment as a answer and accept your own answer ? It will help visitors. – asyncwait Nov 05 '13 at 12:43

0 Answers0