SaaS CMS has officially launched! Learn more now.

How to search for pages of base type with EPiServer built-in search


Can't I use this?

//Search for pages using the provided language
var pageTypeQuery = new GroupQuery(LuceneOperator.AND);
pageTypeQuery.QueryExpressions.Add(new ContentQuery<SearchableSitePageData>());
pageTypeQuery.QueryExpressions.Add(new FieldQuery(languageBranch, Field.Culture));

//Search for blocks using the provided language
var blockTypeQuery = new GroupQuery(LuceneOperator.AND);
blockTypeQuery.QueryExpressions.Add(new ContentQuery<SearchableSiteBlockData>());
blockTypeQuery.QueryExpressions.Add(new FieldQuery(languageBranch, Field.Culture));

where SearchableSitePageData is

    public abstract class SearchableSitePageData : SitePageData, IShowInSearchResults

and SitePageData inherits from PageData.

May 22, 2014 18:59

Similar code works for me:

var typeQuery = new ContentTypesQuery();

foreach (string type in SearchPage.ContentTypesCategories)

var accessQuery = new AccessControlListQuery();
accessQuery.AddAclForUser(PrincipalInfo.Current, HttpContext.Current);

var query = new GroupQuery(LuceneOperator.AND);
query.QueryExpressions.Add(new FieldQuery(searchText));
May 22, 2014 22:15

Hey, but is ContentTypesQuery a class of your own?

May 23, 2014 9:08

Haha, sorry. Sure it was. But it's a really simple class.

using EPiServer.Search.Queries.Lucene;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

public class ContentTypesQuery : CollectionQueryBase
    private readonly string AssemblyName;

    public ContentTypesQuery()
        : base("EPISERVER_SEARCH_TYPE", LuceneOperator.OR)
        var assembly = this.GetType().Assembly;

        AssemblyName = assembly.GetName().Name;

    public void AddContentType(string name)
        base.Items.Add(string.Format("{0},{1}", name, AssemblyName));
May 23, 2014 19:22

And the reason was that we wanted the editors to be able to chose which types that should be searchable.

I guess ContentQuery<SearchableSitePageData>() is implemented in a similar way.

May 23, 2014 19:26
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.