Quantcast
Viewing all articles
Browse latest Browse all 78

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;
    }
}
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 78

Trending Articles