How To Search For Content Using EpiFind

EpiFind is a power search provider developed by EpiServer; if you've stumbled across this post and you're considering using EpiFInd I suggest you read this article, Review Of The Different Search Providers Available To Use On Your Episerver Project. In today's post, I'll cover some basic code snippets to query Find.

Performing A Basic Search

Performing a search is pretty easy. The best approach to query find is to inject the Find API, IClient. In this example, I'm returning a PageData object, we can then use the standard PageData properties to display that search result: like:
           var searchClient = ServiceLocator.Current.GetInstance<IClient>();
            var result = searchClient.Search<PageData>()
                                         .For("EPiServer Find code samples")
For those of you who are interested the old singleton version,SearchClient, looks like this:
            var results = SearchClient.Instance.Search<PageData>()
                                         .For("Search Query")
Querying finds EpiFind results in the ContentResult object being returned. ContentResult has several useful bits of data, like facets, total results and the search results themselves. To get the search results, you can use this code:
            foreach (var result in results.Items)
                var name = result.PageName;
                var url = result.ExternalURL;
You can get the total number of results returned, like:

If you want to only search for certain content types, you can do that like this:
   var results = SearchClient.Instance.Search<StandardData>()
                                         .For("Search Query")
To get the facets, you can use this snippet:
            foreach (var facet in results.Facets)
                var name = facet.Name;


EpiFind is very simple to get started ith and offers a pretty powerful API. In today's post, I've covered some of the basic bog standard ways to query find and display those results on your website.

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

Back to top