I have a requirement to limit search results to an arbitrary number in a Site Search implementation. Is there a way to accomplish this in a query and get accurate facets relative to the arbitrary search result cap?

For example if a full result set is 350 items, using the FacetOn() method I get all of the facets correctly. However, I want to limit my result set to 100 results. If I use Take(100) the facets are still relative to the full result set of 350. Is there a way to adjust the facets to match the hits that are actually taken? Or is there a way to set a search hit limit on a per-query basis?


You can set the facet in Indexing section of the item.

enter image description here

  • That's not quite what I'm looking for. I am trying to get a result set that is limited in quantity. I am using FacetOn() in order to get facets, and that works fine. For example, if solr returns 350 results, the facets that are returned are correct relative to those 350 results. The problem is that if do a Take(100) in the query, and then get results, the facets are still relative to the original 350. Jun 18 '19 at 14:13

You should be able to use Sitecore Linq query on your SearchResults. You will want to look at using .Page() on the query you're using so that it's all part of your search query before you get the results.

Something like this (not currently at my PC to confirm exact syntax and name spaces):

using (var context = Sitecore.ContentSearch.ContentSearchManager.CreateSearchContext(new Sitecore.ContentSearch.SitecoreIndexableItem(Sitecore.Context.Item))) {
var query = context.GetQueryable<SearchResultItem>().Where(i => i.Name.Contains("test search term"));
query = query.Page(1, 100);
var results = query.GetResults();
if (results.Hits.Count() > 0) {
   return results.Hits;

This is basically getting you page 1 with a page size of 100

  • Getting 100 results is the first part. What I need is for the Facets to be relative to those 100 results, not all of the possible results including results that would be on page 2, 3, 4... Mar 26 '20 at 13:12

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.