Created
June 25, 2013 13:23
-
-
Save cceremuga/5858390 to your computer and use it in GitHub Desktop.
Perform a taxonomy path based search with the Ektron 8.7 SearchManager class. In this example, I have 3 dropdown lists with optional category filters on a search. The value of the dropdown list item is a taxonomy path. When multiple dropdowns are selected, it is searching with AND based logic.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//create advanced search | |
AdvancedSearchCriteria criteria = new AdvancedSearchCriteria(); | |
criteria.OrderBy = new List<OrderData>() | |
{ | |
new OrderData(SearchContentProperty.DateCreated, OrderDirection.Descending) | |
}; | |
criteria.PagingInfo = new PagingInfo(500); | |
criteria.PagingInfo.CurrentPage = 1; | |
criteria.ReturnProperties = new HashSet<PropertyExpression>() | |
{ | |
SearchContentProperty.Id, | |
SearchContentProperty.Title, | |
SearchContentProperty.QuickLink, | |
SearchContentProperty.DateCreated | |
}; | |
//build search expression tree with some basics i.e. non-user content, default language | |
ContentManager contentManager = new ContentManager(); | |
Expression expressionTree = Ektron.Cms.Search.SearchType.IsNonUserContent(); | |
expressionTree &= SearchContentProperty.Language.EqualTo(contentManager.RequestInformation.DefaultContentLanguage); | |
//filter one | |
if (!String.IsNullOrEmpty(DdlFilterOne.SelectedValue)) | |
expressionTree &= SearchContentProperty.TaxonomyCategory.Contains(DdlFilterOne.SelectedValue); | |
//filter two | |
if (!String.IsNullOrEmpty(DdlFilterTwo.SelectedValue)) | |
expressionTree &= SearchContentProperty.TaxonomyCategory.Contains(DdlFilterTwo.SelectedValue); | |
//filter three | |
if (!String.IsNullOrEmpty(DdlFilterThree.SelectedValue)) | |
expressionTree &= SearchContentProperty.TaxonomyCategory.Contains(DdlFilterThree.SelectedValue); | |
//convert expression tree to criteria | |
criteria.ExpressionTree = expressionTree; | |
//perform search | |
ISearchManager manager = ObjectFactory.GetSearchManager(); | |
SearchResponseData response = manager.Search(criteria); | |
//do whatever you want with the response.Results here! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment