Code sample

Retrieve full result set with EPiServer Find

By default only the first ten hits are returned when using EPiServer Find. That number can be increased to a thousand, but not more. Here's an example of how to get *all* hits. Use with caution :)

public IEnumerable<PageData> GetPages()
{
    int totalNumberOfPages;

    var query = SearchClient.Instance.Search<PageData>()
                                .Take(1000);

    var batch = query.GetContentResult();
    foreach (var page in batch)
    {
        yield return page;
    }

    totalNumberOfPages = batch.TotalMatching;

    var nextBatchFrom = 1000;
    while (nextBatchFrom < totalNumberOfPages)
    {
        batch = query.Skip(nextBatchFrom).GetContentResult();
        foreach (var page in batch)
        {
            yield return page;
        }
        nextBatchFrom += 1000;
    }
}
Joel Abrahamsson

Joel Abrahamsson

I'm a passionate web developer and systems architect living in Stockholm, Sweden. I work as CTO for a large media site and enjoy developing with all technologies, especially .NET, Node.js, and ElasticSearch. Read more

More about EPiServer Find