This content is archived. See latest version here

Last updated: Nov 16 2015


This topic explains how to run several Episerver Find searches in one request, which speeds up your search.

How it works

When you run multiple search in one request, an IEnumerable<SearchResults<T>> is returned. Below is a simple multi-search example.

C#
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 this example, both queries search and return the Article type. Alternatively, you can search for and return different types using Episerver Find projections as illustrated in the following example.

C#
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 that they are searched for, so that the first result is related to the first query, and so on. Also, these searches only count as one query against the index.

Multi-unified search

There is also a multiple unified search equivalent available. Below is a simple multi-unified-search example.

C#
results = service.MultiUnifiedSearch()
    .UnifiedSearch(x => x.For("Banana"))
    .UnifiedSearch(x => x.For("Annanas"))
    .GetResult();

You can also specify your own hit specification with customized highlighting for each search as illustrated in the following example.

C#
results = service.MultiUnifiedSearch()
    .UnifiedSearch(x => x.For("Banana"), new HitSpecification
            { HighlightTitle = true, HighlightExcerpt = true, PostTagForAllHighlights = "</strong>", PreTagForAllHighlights = "<strong>" })
    .UnifiedSearch(x => x.For("Annanas"), new HitSpecification
            { HighlightTitle = true, HighlightExcerpt = true, PostTagForAllHighlights = "</em>", PreTagForAllHighlights = "<em>" })
    .GetResult();

Maximum number of searches

One multi-search request can create up to 10 searches. This limitation prevents abuse.


Do you have feedback on this documentation? Send an email to documentation@episerver.com. For development-related questions and discussions, refer to our Forums on https://world.episerver.com/forum/