Hi

You should do the following:

TopFieldCollector tfc = TopFieldCollector.create();
FacetsCollector fc = FacetsCollector.create();
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.

BTW, you don't need to do new CategoryPath("CATEGORY_PATH", '/'), when the
category does not contain the delimiter.
You can use the vararg constructor which takes the path components
directly, if you have them already.

Shai


On Thu, Aug 1, 2013 at 7:46 PM, Sanket Paranjape <
sanket.paranjape.mailingl...@gmail.com> wrote:

> 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.
>
>
> I have asked this question on stackoverflow as well. (
>
> http://stackoverflow.com/questions/17992183/lucene-4-faceted-search-with-sorting
> )
>
>
> Please Help !!
>

Reply via email to