Search code examples
javasolrsolrjspring-data-solr

how to add group field in @Query annotation in Solr


I have added a method to get quarters my repository class based on the value of book and year

public interface Repository extends SolrCrudRepository<Doc, Long> { @Query(fields = { Constants.QUARTER_FIELD }) public List<CodingClinicDoc> findQuarterByBookAndYear(String book, int year); }

but i am getting duplicate values e.g. 'First quarter' around 10 times

Please tell me if there is a way to apply group field like group=true&group.field=quarter to @Query annotation to get unique result. Or some other way to get the distinct quarters.


Solution

  • As of version 1.5.2 of Spring Data Solr, you cannot use result grouping with SolrRepository. You'll have to use SolrTemplate. See this section (http://docs.spring.io/spring-data/solr/docs/1.5.2.RELEASE/reference/html/#solr.misc.group) on Spring data solr reference.