Class ContentQuery<T>
Representing a query to the Lucene Indexing Service for a content item.
Implements
EPiServer.Search.Queries.IQueryExpression
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.Search.Queries.Lucene
Assembly: EPiServer.dll
Version: 10.10.4Syntax
public class ContentQuery<T> : IQueryExpression where T : IContentData
Type Parameters
Name | Description |
---|---|
T | The type of the content to search for. |
Examples
Example of how you could search for pages.
public class PageSearchSample : TemplatePage
{
public IEnumerable<PageData> FindPages(string searchQuery, ContentReference searchRoot, string cultureId, int pagingNumber, int pagingSize)
{
// The group query is needed to combine the different criteria
GroupQuery groupQuery = new GroupQuery(LuceneOperator.AND);
// The content query makes sure we only get hits that are of the type PageData
groupQuery.QueryExpressions.Add(new ContentQuery<PageData>());
// The field query contains the search phrase
groupQuery.QueryExpressions.Add(new FieldQuery(searchQuery));
// The virtual path query makes sure that we only get hits for children of the specified search root
VirtualPathQuery pathQuery = new VirtualPathQuery();
pathQuery.AddContentNodes(searchRoot);
groupQuery.QueryExpressions.Add(pathQuery);
// The access control list query will remove any pages the user doesn't have read access to
AccessControlListQuery aclQuery = new AccessControlListQuery();
aclQuery.AddAclForUser(PrincipalInfo.Current, HttpContext.Current);
groupQuery.QueryExpressions.Add(aclQuery);
// Add a specific field query for the Culture field in order to search for a specific culture
groupQuery.QueryExpressions.Add(new FieldQuery(cultureId, Field.Culture));
SearchResults results = Locate.SearchHandler().GetSearchResults(groupQuery, pagingNumber, pagingSize);
ContentSearchHandler contentSearchHandler = Locate.ContentSearchHandler();
foreach (var hit in results.IndexResponseItems)
{
// Use the content search handler to convert the page hit into a PageData
yield return contentSearchHandler.GetContent<PageData>(hit);
}
}
}
Constructors
ContentQuery()
Initializes a new instance of the ContentQuery<T> class.
Declaration
public ContentQuery()
Methods
GetQueryExpression()
Gets the query expression for this ContentQuery<T> instance.
Declaration
public virtual string GetQueryExpression()
Returns
Type | Description |
---|---|
System.String | A query expression string. |
Implements
EPiServer.Search.Queries.IQueryExpression