Try our conversational search powered by Generative AI!

Question about Count in MultiSearch

Vote:
 

Hello.

How can I send request of count in multisearch?

where, request of count = EPiServer.Find.SearchExtensions.Count()

           Multisearch = EPiServer.Find.IClient.MultiSearch

Any ideas?

Version EPiServer.Find = 8.9

Best Regards

#122089
May 26, 2015 15:29
Vote:
 

Hi,

You cannot use .Count() on individual searches in a multisearch request but you can do it on all searches using .Count() instead of .GetResult():

var results = service.MultiSearch<Article>()

                .Search<Article>(x => x.For("Banana"))

                .Search<Article>(x => x.For("Orange"))

                .Count();

I guess however that you want to do a count on just a some of the searches and to do this with minimal overhead you can use .Take(0) on that query and look at .TotalMatching in the result:

var results = service.MultiSearch<Article>()

                .Search<Article>(x => x.For("Banana"))

                .Search<Article>(x => x.For("Orange").Take(0))

                .GetResult();

results.ElementAt(1).TotalMatching

This will effectivly be a count query as it won't return any matching documents and only return the number of documents actually matching your query.

#122173
May 27, 2015 16:08
Vote:
 

Thank you. It is very good answer.

Best Regards.

#122207
May 28, 2015 9:00
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.