Do highlight and facet query with one request in spring data solr

1.4k views Asked by At

How do I combine a query in spring data solr to get a page as a result which contains highlighting and faceting? Right now I have to make two requests and combine the result.

I use a custom repository implementation:

@Override
public Page<Sample> myQuery(Criteria query, Criteria filterQuery) {
   FilterQuery filterQuery = new SimpleFilterQuery(filterQuery);

   FacetQuery facetQuery = new SimpleFacetQuery(query)
    .setFacetOptions(new FacetOptions().addFacetOnField("availability"));
   facetQuery.addFilterQuery(filterQuery);

   FacetPage<Sample> page = solrTemplate.queryForFacetPage(facetQuery, Sample.class);

   // Or create highlight query 

   SimpleHighlightQuery highlightQuery = new SimpleHighlightQuery(query);
   highlightQuery.addFilterQuery(filterQuery);
   highlightQuery.setHighlightOptions(new HighlightOptions());
   HighlightPage<Sample> highLightPage = solrTemplate.queryForHighlightPage(highlightQuery, Sample.class);
  return page;
}

What I want is a query which does the highlight and facet query at once - else I have to split it in tow methods and to tow requests.

1

There are 1 answers

0
Francisco Spaeth On

As for version 1.4.2-RELEASE, this isn't supported. Since HighlightQuery and FacetQuery are handled separately and there is no common implementation for those two interfaces the queries are mutual exclusive. See org.springframework.data.solr.core.DefaultQueryParser.doConstructSolrQuery(SolrDataQuery).

For this purpose there is already an issue: DATASOLR-244