Search code examples
faceted-searchfacetsolrjsolr

How to get facet.query results only, using solrj?


I'm trying to get results of a facet query using solrj, but it seems it doesn't matter whether I add the facet query or not. I get the same document list anyway.

So this query returns the same document list...

  query.setQuery(searchString);
  query.setFacet(true);
  query.addFacetField("CATNAME_STR");
  query.addFacetQuery("CATNAME_STR:" + facetName); 

...with this query

  query.setQuery(searchString);
  query.setFacet(true);
  query.addFacetField("CATNAME_STR");

Only difference is I can get number of documents that matches the facet query with response.getFacetQuery();

I was expecting it to work like

http://localhost:8983/solr/select/?q=*%3A*&version=2.2&start=0&rows=10&indent=on&facet=on&facet.field=CATNAME_STR&fq=CATNAME_STR:Erasmus

Any ideas?

Thanks.

By the way I'm using Solr Version 3.1.0 and solr-core-3.1.0


Solution

  • As it turns out fq=CATNAME_STR:Erasmus does not mean query.addFacetQuery("CATNAME_STR:Erasmus") but instead query.addFilterQuery("CATNAME_STR:Erasmus")