spring-projects / spring-projects/spring-data-rest
Solr faceted queries missing facet values [DATAREST-309]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Jega A opened DATAREST-309 and commented
I am working on a POC for using Solr with spring-data-solr and spring-data-rest-mvc
I have my repository defined as follows:
// Repository
@RepositoryRestResource(collectionResourceRel = "contracts_search", path = "contracts_search")
public interface ContractRepository extends SolrCrudRepository<Contract, String> {
@Query("?0")
@Facet( fields = "product")
FacetPage<Contract> searchAllFieldsWithFacets(@Param("searchStr") String searchStr, Pageable page);
}
I am executing a REST call to search for the work "Canada" using the repository.
// Query that is actually going to Solr when "searchAllFieldsWithFacets?searchStr=Canada" is executed seems right.
select?q=Canada&start=0&rows=20&facet=true&facet.mincount=1&facet.limit=10&facet.field=product&wt=javabin&version=2
// Result of the query (showing only the last section of the json result returned by the REST service).
"page" : {
"size" : 20,
"totalElements" : 2479,
"totalPages" : 124,
"number" : 0
}
Notice how the facet result appears just as one number under "totalElements". For some reason it is not being expanded into the various values under the faceted field (i.e "product").
//The same query executed directly in the Solr Admin UI returns the correct results. Notice here how the "product" has the count for various product types.
"facet_counts": {
"facet_queries": {},
"facet_fields": {
"product": [
"Consulting",
836,
"Software",
827,
"Training",
816
]
},
"facet_dates": {},
"facet_ranges": {}
}
Based on some feedback from the spring-data-solr support group I wrote some test programs to check the same results by only using spring-data-solr. The following code
gives the correct results
FacetPage<Contract> facetPage = contractRepository.searchAllFieldsWithFacets("canada", new PageRequest(0,10));
for(FacetFieldEntry entry : facetPage.getFacetResultPage("product")) {
// eg.: Consulting, Software, Training
System.out.println("Value: " + entry.getValue());
// eg.: 836, 827, 816
System.out.println("Count: " + entry.getValueCount());
}
System.out.println(facetPage.getFacetResultPage("product").toString());
// Results of the run
Value: Consulting
Count: 835
Value: Software
Count: 827
Value: Training
Count: 816
So the spring-data-solr by itself seems to be fetching the correct results. I am thinking that the data is being lost the layer where data is being coverted into
JSON at the spring-data-rest layer. Any suggestions on how to address this issue?
Affects: 2.1 RC1 (Dijkstra)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.