2

I am building a custom .NET Page and I need to query the total count of items in each Sitecore index (backend is Solr). I have not been able to find any "hooks" or documentation of the Sitecore API to support my needs.

In older versions (I am building on 8.1), I was able to use the Sitecore.Search.SearchManager but it appears this is now obsolete. I am leaning towards hitting the Solr API directly.

  • 1
    Have you looked into using ContentSearchManager? Would the following work for you? gist.github.com/grg17/cc8a6400d5205555e68c300842b411c0 You should always use Sitecore API instead of directly going to Solr API. – grg Nov 7 '18 at 22:20
  • That may be a better fit. Is that becoming obsolete like the Search.SearchManager? – Kode Nov 7 '18 at 22:31
  • Also, do you know where in the Sitecore docs they list the info/options for ContentSearchManager? – Kode Nov 7 '18 at 22:41
1

Below link will help you get all the details about how to access indexes using LINQ

https://doc.sitecore.net/sitecore_experience_platform/developing/developing_with_sitecore/search_and_item_buckets/linq_to_sitecore

https://www.geekhive.com/buzz/post/2017/08/predicate-builder-advanced-search-queries/

You can also create your custom indexes so you can get count of total items for each index while building the indexes. Essentially when you access indexes all the calculations are done and you just fetch the total count.

Here's the example of creating custom indexes.

https://www.linkedin.com/pulse/implement-search-using-lucene-indexes-sitecore-cms-app-umar-desai/

2

The Sitecore ContentSearchManager is what you want for this kind of thing. It's definitely not obsolete.

First add a reference to the ContentSearch API by adding Sitecore.ContentSearch and Sitecore.ContentSearch.Linq libraries either as a direct reference or via the nuget feed.

You can query index state like this:

foreach (var index in ContentSearchManager.Indexes)
{
    var summary = index.Summary;
    var documents = summary.NumberOfDocuments;
}

Documentation for querying indexes is available here.

  • Very helpful, but where did you get the values of .Indexes like Summary and NumberofDocuments? Are the allowed variables listed somewhere for what ContentSearchManager.Indexes allows us to Query? – Kode Nov 8 '18 at 18:55
  • I can open the dll in reflector if necessary, but it would be nice to have some docs – Kode Nov 8 '18 at 19:26
  • 1
    I think that part of the api won't be documented so you're best off reflecting the dlls – Mark Gibbons Nov 8 '18 at 22:08

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.