1

Does Sitecore Content Search support group by clause?

If yes then what are the namespace / references are needed?

2

LINQ to Sitecore, which is used by Sitecore Content Search does not support GroupBy.

Here is the full list of not supported IQueryable methods:

  • Average
  • Concat
  • Facets
  • FirstOrDefault
  • GroupBy
  • Intersect
  • LastOrDefault
  • Match
  • OrderByDescending
  • Reverse
  • SingleOrDefault
  • SkipWhile
  • Sum
  • TakeWhile

You can read more in Sitecore documentation here: https://doc.sitecore.com/developers/90/sitecore-experience-manager/en/linq-to-sitecore.html

0

Above answer is spot on, content search does not support Group By directly.

Adding some extra information about group by support in content search with Solr. From Sitecore 9 on wards, there are extra functionalities (Group, Highlights, Spell checker, etc) which are on top of the existing content search API.

As Content Search API abstracts search providers, we can change providers without any code updates. But Group By is specific to Solr, once we use this, cannot be easily switched between the providers.

Below information is from Sitecore Documentation: https://doc.sitecore.com/developers/93/platform-administration-and-architecture/en/using-solr-to-group-search-results.html

Sitecore has an API that you use to access the result grouping feature of Solr. The API is designed as an extension to the existing ContentSearch API.

Follow these steps to use the API in your project:

Reference the following DLL files into your project (you can get them from the bin folder of your Sitecore website):

  • SolrNet.dll
  • Sitecore.ContentSearch.dll
  • Sitecore.ContentSearch.SolrProvider.dll
  • Sitecore.ContentSearch.SolrNetExtension.dll

Import the following namespace:

  • Sitecore.ContentSearch.SolrNetExtension

You can now use the Result Grouping API as part of ISearchIndex:

  • Create your query as string or any implementation of ISolrQuery.
  • Call IProviderSearchContext.Query() method and inspect the returned result of type SolrQueryResults.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.