This document describes how to handle multiple searches in one single request in EPiServer Find, which is useful in order to reduce the number of requests and speed up search.
How it works
When you handle multiple search in one single request, an IEnumerable<SearchResults<T>> will be returned. There are several use cases for this, since several queries for a specific content, for instance a page can be done in one roundtrip.
Below is a simple multi-search example.
results = service.MultiSearch<Article>() .Search<Article>(x => x.For("Banana").InField(y => y.Title)) .Search<Article>(x => x.For("Annanas").InField(y => y.Title)) .GetResult();
In the example above both queries search in the Article type and also return the article type. However, it is also possible to search in different types and return different types, using the powerful projections in EPiServer Find as in the example below.
IEnumerable<SearchResults<string>> results = service.MultiSearch<string>() .Search<Article, string>(x => x.For(indexedArticle.Title).InField(y => y.Title).Select(y => y.Title)) .Search<User, string>(x => x.For(indexedUser.Name).InField(y => y.Name).Select(y => y.Name)).GetResult();
The results are always returned in the same way as they are searched for, so that the first result will be the first query. Also, these will of course only count as one query against the index.