November Happy Hour will be moved to Thursday December 5th.

Loading...
Area: Optimizely Search & Navigation
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

Introduction

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.

Maximum Number of Searches

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

Do you find this information helpful? Please log in to provide feedback.

Last updated: Feb 23, 2015

Recommended reading