on ‎2018 Jul 24 3:47 PM
Hi Friends,
I want to do a solr search to get the number of products under category. I don't want to use productsearchservice , as it hits the DB to find the count.
Thanks in advance.
Request clarification before answering.
Hi Amardeep
You can use the below function in solrProductSearchService. I don't think it hits the database and if it does, you may need to write your own custom code to fetch solr results without hitting DB.
public ProductCategorySearchPageData<SolrSearchQueryData, ITEM, CategoryModel> categorySearch(String categoryCode, PageableData pageableData)
Having said that, my understanding is that above method's implementation doesn't hit the DB. Now, the return type of this method is
FacetSearchPageData<SolrSearchQueryData, SearchResultValueData> searchPageData
Now your entire code would look like below:
final FacetSearchPageData<SolrSearchQueryData, SearchResultValueData> searchPageData = commerceProductSearchService
.categorySearch("xyz", null);
final List<FacetData<SolrSearchQueryData>> facets = searchPageData.getFacets();
for (final FacetData<SolrSearchQueryData> facetData : facets)
{
for (final FacetValueData<SolrSearchQueryData> facetValueData : facetData.getTopValues())
{
final CategoryData data = new CategoryData();
data.setCode(facetValueData.getCode());
data.setName(facetValueData.getName());
final CategoryResultData categoryResultData = new CategoryResultData();
categoryResultData.setCategory(data);
categoryResultData.setCount(facetValueData.getCount());
}
}
Let me know how you go.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.