How do I combine Facet and FilterQueries using Spring data Solr?

945 views Asked by At

Is it possible to combine a facet and field query in spring data solr? Something that would build a query like this:

> http://localhost:8983/solr/myCore/select?q=lastName%3AHarris*&fq=filterQueryField%3Ared&wt=json&indent=true&facet=true&facet.field=state

In other words, how do I add FilterParameters to a SimpleFacetQuery?

Any/all replies welcome, thanks in advance, -- Griff

1

There are 1 answers

0
ikumen On BEST ANSWER

I assume you're using Spring Data Solr, from your reference to SimpleFacetQuery. Based on your sample query, the code would look something like this:

// creates query with facet
SimpleFacetQuery query = new SimpleFacetQuery(
     new Criteria("lastName").startsWith("Harris"))
  .setFacetOptions(new FacetOptions()
  .addFacetOnField("state"));

// filter parameters  on query  
query.addFilterQuery(new SimpleFilterQuery(
  Criteria.where("filterQueryField").is("red")));

// using query with solrTemplate
solrTemplate.queryForFacetPage(query, YourDocumentClass.class)