Try our conversational search powered by Generative AI!

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

Recommended reading 

Querying scenarios

In addition to providing great, near-real-time search, Episerver Find can solve other querying needs for which you previously used the FindPagesWithCriteria method. The examples below illustrate common querying scenarios specific to Episerver 7/7.5 CMS. See Searching and Filtering for more filtering examples.

Filtering by category

C#
int categoryId = 3; //Category to match

var pages = SearchClient.Instance.Search<PageData>()
  .Filter(x => x.Category.Match(categoryId))
  .GetContentResult();

Filtering by Author/ChangedBy

C#
var pages = SearchClient.Instance.Search<PageData>()
  .Filter(x => x.ChangedBy.Match("Zlatan"))
  .GetContentResult();

Filtering by publish date

The example below finds pages published in October 2011.

C#
var pages = SearchClient.Instance.Search<PageData>()
  .Filter(x => x.StartPublish.MatchMonth(2011, 10))
  .GetContentResult();
To find all pages published prior to October 2011, use the query below.
C#
var pages = SearchClient.Instance.Search<PageData>()
  .Filter(x => x.StartPublish.Before(new DateTime(2011, 10, 1)))
  .GetContentResult();

Filtering by page type

When using typed content, the easiest way to filter by content type is use the Client Search method and specify the desired type in the type parameter. However, in that case, pages of page types inheriting from the specified type are also matched. In other situations, you may not know what type to filter by until at runtime. In both cases, you can filter via IContent.ContentTypeID.

C#
int contentTypeId = 42;

var pages = SearchClient.Instance.Search<IContent>()
  .Filter(x => x.ContentTypeID.Match(contentTypeId))
  .GetContentResult();

Filtering by Site ID

In an enterprise scenario with multiple sites, all sites use one index. To enable fltering by site ID, the return value of an IContent extension method, SiteId, is indexed. Use SiteId to filter for content from a specific site.

C#
var content = SearchClient.Instance.Search<IContent>()
  .Filter(x => x.SiteId().Match("MySiteId"))
  .GetContentResult();

Related topics

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

Last updated: Nov 16, 2015

Recommended reading