SearchManager
The SearchManager provides access to query the index of a configured search provider.
Namespace
Ektron.Cms.Framework.Search.SearchManager
Constructors
SearchManager()
SearchManager(ApiAccessMode)
Properties
SearchService
. Gets the underlying service facilitating access to the configured search provider.
Methods
Remarks
All Providers
. For diagnostic purposes, the search provider's interpretation of your search criteria can be logged to the Windows Application log. This represents the raw query issued to the search engine. To log this information, set the value of theLogLevel
application setting in your site'sweb.config
to3
.FAST Search for Sharepoint 2010
. The AdvancedSearchCriteria is not applicable when your search provider is Microsoft FAST Search for SharePoint. For the purposes of easing migration to this provider, any queries using this criteria is interpreted as KeywordSearchCriteria.Search Server 2010
. MSDN states that the maximum length for a keyword query is 2048 characters. If you encounter this limitation using the KeywordSearchCriteria, consider revising your query or switching to the AdvancedSearchCriteria which supports longer queries.MSDN also states that the maximum length for a full-text search query is 4096 characters. If you encounter this limitation using the AdvancedSearchCriteria, consider revising your query.
Solr
. The AdvancedSearchCriteria is not applicable when your search provider is Apache Solr. For the purposes of easing migration to this provider, any queries using this criteria is interpretedas KeywordSearchCriteria.By default, the content of assets (Word documents, PDFs, and so on) is indexed for files up to 10 MB in size. This limit is intended to accelerate crawl times and minimize the burden placed upon the search server by the content extraction process. When a file exceeds this limit, its summary is indexed instead of the full content of the document. The limit can be adjusted via the ManifoldCF administration console. (Use caution when updating advanced configuration options such as this. Changes may impact the performance of your search server.)
Solr relies on Apache Tika, an open source collection of content analysis libraries, for the extraction of content from asset files (Word documents, PDFs, and so on). Support for the extraction of content from these types of files is subject to the features and limitations of this toolkit.
Search(AdvancedSearchCriteria)
Search(Ektron.Cms.Search.KeywordSearchCriteria)
Issues advanced search to return specific results and run complex queries.
Submits a query according to the specified criteria. The AdvancedSearchCriteria is intended to target specific, narrow, sets of data. The length and complexity of queries supported by this method are subject to the limitations of the configured search provider. For some search providers, this method may also allow for longer or more complicated queries than may be allowed with the KeywordSearchCriteria. This method is not supported for all search providers.
Authenticated users
- CMS Administrators
To create anonymous user access with this method, set the API access mode (ApiMode
) in the Manager class when instantiating the class.
Parameters
criteria
. Search criteria.
Returns
Search response data.
Return properties
You want the following properties to be returned when viewing the results.
criteria.ReturnProperties = new HashSet<PropertyExpression>() { SearchContentProperty.Id, SearchContentProperty.Title, SearchContentProperty.QuickLink };
OrderBy
Sets the order of search results based on a return property Ascending/Descending
.
criteria.OrderBy = new List<OrderData>() { new OrderData(SearchContentProperty.Rank, OrderDirection.Descending) };
PagingInfo
Sets the number of results you see per page and the current page number for search.
criteria.PagingInfo = new PagingInfo(10); criteria.PagingInfo.CurrentPage = 1;
ExpressionTree
Helps build nested or complex queries using managed properties. This examples shows how to search for the Content ID specified by the user in the currently active site language or default content language (if no active language is found). Also, search results are restricted by Content Type (Ektron.Cms.Search.SearchType.IsNonUserContent()
) to ensure users or community groups do not appear.
ContentManager contentManager = new ContentManager(); Expression expressionTree = Ektron.Cms.Search.SearchType.IsNonUserContent(); if (contentManager.RequestInformation.ContentLanguage == 0) expressionTree &= SearchContentProperty.Language.EqualTo(contentManager.RequestInformation.DefaultContentLanguage); else if (contentManager.RequestInformation.ContentLanguage > 0) expressionTree &= SearchContentProperty.Language.EqualTo(contentManager.RequestInformation.ContentLanguage); expressionTree &= SearchContentProperty.Id.EqualTo(id); criteria.ExpressionTree = expressionTree;
.aspx code snippet
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0"> <asp:View ID="View1" runat="server"> <div class="ektron-ui-form registerForm"> <ol class="formFields"> <li class="clearfix"> <ektronUI:Label ID="Label1" AssociatedControlID="uxContentId" CssClass="span-8 last" runat="server" Text="Search for Content Id (in current site language):" /> <ektronUI:TextField ID="TextField1" CssClass="span-6" runat="server" ValidationGroup="RegisterValidationGroup" Text="30" /> </li> </div> <li class="clearfix"> <ektronUI:Button ID="Button1" runat="server" OnClick="uxSubmit_Click" Text="Search"></ektronUI:Button> </li> </ol> </div> </asp:View> <asp:View ID="View2" runat="server"> <ektronUI:Message ID="Message1" DisplayMode="Information" Visible="false" runat="server" /> <asp:ListView ID="ListView1" runat="server" ItemPlaceholderID="aspItemPlaceholder" Visible="false"> <EmptyDataTemplate> Search criteria did not match any records. </EmptyDataTemplate> <LayoutTemplate> <table class="devsite-api-method"> <thead> <tr> <th> Content Id </th> <th> Content Title </th> <th> Quicklink </th> </tr> </thead> <tbody> <asp:PlaceHolder ID="aspItemPlaceholder" runat="server"></asp:PlaceHolder> </tbody> </table> </LayoutTemplate> <ItemTemplate> <h1 > FOR C# ASPX <h1 /> <tr> <td class="devsite-method" style="width: 55px"> <%#((SearchResultData)Container.DataItem)[SearchContentProperty.Id].ToString()%> </td> <td class="devsite-method"> <%# ((SearchResultData)Container.DataItem)[SearchContentProperty.Title].ToString()%> </td> <td class="devsite-method"> <%# ((SearchResultData)Container.DataItem)[SearchContentProperty.QuickLink].ToString()%> </td> </tr> <h1 > FOR VB ASPX <h1 /> <tr> <td class="devsite-method" style="width: 55px"> <%# Container.DataItem(SearchContentProperty.Id).ToString()%> </td> <td class="devsite-method"> <%# Container.DataItem(SearchContentProperty.Title).ToString()%> </td> <td class="devsite-method"> <%# Container.DataItem(SearchContentProperty.QuickLink).ToString()%> </td> </tr> </ItemTemplate> </asp:ListView> </asp:View> </asp:MultiView>
.aspx.cs code-behind namespace
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Ektron.Site; using Ektron.Cms.Common; using Ektron.Site.Developer; using Ektron.Cms.Framework.UI.Controls.EktronUI; using Ektron.Cms.Framework.Search; using Ektron.Cms.Search.Expressions; using Ektron.Cms; using Ektron.Cms.Search; using Ektron.Cms.Framework.Content;
.aspx.cs code-behind method
protected void uxSubmit_Click(object sender, EventArgs e) { try { long id; if (long.TryParse(uxContentId.Text, out id)) { AdvancedSearchCriteria criteria = new AdvancedSearchCriteria(); criteria.OrderBy = new List<OrderData>() { new OrderData(SearchContentProperty.Rank, OrderDirection.Descending) }; criteria.PagingInfo = new PagingInfo(10); criteria.PagingInfo.CurrentPage = 1; criteria.ReturnProperties = new HashSet<PropertyExpression>() { SearchContentProperty.Id, SearchContentProperty.Title, SearchContentProperty.QuickLink }; ContentManager contentManager = new ContentManager(); Expression expressionTree = Ektron.Cms.Search.SearchType.IsNonUserContent(); if (contentManager.RequestInformation.ContentLanguage == 0) expressionTree &= SearchContentProperty.Language.EqualTo(contentManager.RequestInformation.DefaultContentLanguage); else if (contentManager.RequestInformation.ContentLanguage > 0) expressionTree &= SearchContentProperty.Language.EqualTo(contentManager.RequestInformation.ContentLanguage); expressionTree &= SearchContentProperty.Id.EqualTo(id); criteria.ExpressionTree = expressionTree; ISearchManager manager = ObjectFactory.GetSearchManager(); SearchResponseData response = manager.Search(criteria); uxSearchResultView.Visible = true; uxSearchResultView.DataSource = response.Results; uxSearchResultView.DataBind(); uxPageMultiView.SetActiveView(uxViewMessage); } else { MessageUtilities.UpdateMessage(uxMessage, "Please enter a numeric Content Id", Message.DisplayModes.Error); uxPageMultiView.SetActiveView(uxViewMessage); } } catch (Exception ex) { MessageUtilities.UpdateMessage(uxMessage, ex.Message, Message.DisplayModes.Error); uxPageMultiView.SetActiveView(uxViewMessage); } }
Search(KeywordSearchCriteria)
Search(Ektron.Cms.Search.KeywordSearchCriteria)
Issues a simple text search query that you can combine with complex managed property queries.
Submits a query according to the specified criteria. The criteria may be a combination of free form search terms and programmatically generated query expressions. The length and complexity of queries supported by this method are subject to the limitations of the configured search provider.
Authenticated users
- CMS Administrators
To create anonymous user access with this method, set the API access mode (ApiMode
) in the Manager class when instantiating the class.
Parameters
criteria
. Search criteria.
Returns
Search response data.
ReturnProperties
Returns the properties you want in the results.
criteria.ReturnProperties = new HashSet<PropertyExpression>() { SearchContentProperty.Id, SearchContentProperty.Title, SearchContentProperty.QuickLink };
OrderBy
Sets the order of search results based on a return property Ascending/Descending
.
criteria.OrderBy = new List<OrderData>() { new OrderData(SearchContentProperty.Rank, OrderDirection.Descending) };
PagingInfo
Sets the number of results you see per page and the current page number for search.
criteria.PagingInfo = new PagingInfo(10); criteria.PagingInfo.CurrentPage = 1;
QueryText
Set the text search query.
criteria.QueryText = uxSearchText.Text;
ExpressionTree
Helps build nested or complex queries using managed properties. The following example shows how to search for the content in the currently active Site language or default content language (if no active language is found). Also, the search results are restricted by Content Type (Ektron.Cms.Search.SearchType.IsNonUserContent()
) to ensure users or community groups do not appear.
ContentManager contentManager = new ContentManager(); Expression expressionTree = Ektron.Cms.Search.SearchType.IsNonUserContent(); if (contentManager.RequestInformation.ContentLanguage == 0) expressionTree &= SearchContentProperty.Language.EqualTo(contentManager.RequestInformation.DefaultContentLanguage); else if (contentManager.RequestInformation.ContentLanguage > 0) expressionTree &= SearchContentProperty.Language.EqualTo(contentManager.RequestInformation.ContentLanguage);
.aspx code snippet
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0"> <asp:View ID="View1" runat="server"> <div class="ektron-ui-form registerForm"> <ol class="formFields"> <li class="clearfix"> <ektronUI:Label ID="Label1" AssociatedControlID="uxContentId" CssClass="span-8 last" runat="server" Text="Search for Content Id (in current site language):" /> <ektronUI:TextField ID="TextField1" CssClass="span-6" runat="server" ValidationGroup="RegisterValidationGroup" Text="30" /> </li> </div> <li class="clearfix"> <ektronUI:Button ID="Button1" runat="server" OnClick="uxSubmit_Click" Text="Search"></ektronUI:Button> </li> </ol> </div> </asp:View> <asp:View ID="View2" runat="server"> <ektronUI:Message ID="Message1" DisplayMode="Information" Visible="false" runat="server" /> <asp:ListView ID="ListView1" runat="server" ItemPlaceholderID="aspItemPlaceholder" Visible="false"> <EmptyDataTemplate> Search criteria did not match any records. </EmptyDataTemplate> <LayoutTemplate> <table class="devsite-api-method"> <thead> <tr> <th> Content Id </th> <th> Content Title </th> <th> Quicklink </th> </tr> </thead> <tbody> <asp:PlaceHolder ID="aspItemPlaceholder" runat="server"></asp:PlaceHolder> </tbody> </table> </LayoutTemplate> <ItemTemplate> <h1 > FOR C# ASPX <h1 /> <tr> <td class="devsite-method" style="width: 55px"> <%#((SearchResultData)Container.DataItem)[SearchContentProperty.Id].ToString()%> </td> <td class="devsite-method"> <%# ((SearchResultData)Container.DataItem)[SearchContentProperty.Title].ToString()%> </td> <td class="devsite-method"> <%# ((SearchResultData)Container.DataItem)[SearchContentProperty.QuickLink].ToString()%> </td> </tr> <h1 > FOR VB ASPX <h1 /> <tr> <td class="devsite-method" style="width: 55px"> <%# Container.DataItem(SearchContentProperty.Id).ToString()%> </td> <td class="devsite-method"> <%# Container.DataItem(SearchContentProperty.Title).ToString()%> </td> <td class="devsite-method"> <%# Container.DataItem(SearchContentProperty.QuickLink).ToString()%> </td> </tr> </ItemTemplate> </asp:ListView> </asp:View> </asp:MultiView>
.aspx.cs code-behind namespace
using System; using System.Collections.Generic; using Ektron.Cms; using Ektron.Cms.Framework.Content; using Ektron.Cms.Framework.UI.Controls.EktronUI; using Ektron.Cms.Search; using Ektron.Cms.Search.Expressions; using Ektron.Site.Developer;
.aspx.cs code-behind method
protected void uxSubmit_Click(object sender, EventArgs e) { try { if (!String.IsNullOrWhiteSpace(uxSearchText.Text)) { KeywordSearchCriteria criteria = new KeywordSearchCriteria(); criteria.OrderBy = new List<OrderData>() { new OrderData(SearchContentProperty.Rank, OrderDirection.Descending) }; criteria.PagingInfo = new PagingInfo(10); criteria.PagingInfo.CurrentPage = 1; criteria.ReturnProperties = new HashSet<PropertyExpression>() { SearchContentProperty.Id, SearchContentProperty.Title, SearchContentProperty.QuickLink }; ContentManager contentManager = new ContentManager(); Expression expressionTree = Ektron.Cms.Search.SearchType.IsNonUserContent(); if (contentManager.RequestInformation.ContentLanguage == 0) { expressionTree &= SearchContentProperty.Language.EqualTo(contentManager.RequestInformation.DefaultContentLanguage); } else if (contentManager.RequestInformation.ContentLanguage > 0) { expressionTree &= SearchContentProperty.Language.EqualTo(contentManager.RequestInformation.ContentLanguage); } criteria.ExpressionTree = expressionTree; //Pass in query text criteria.QueryText = uxSearchText.Text; ISearchManager manager = ObjectFactory.GetSearchManager(); SearchResponseData response = manager.Search(criteria); uxSearchResultView.Visible = true; uxSearchResultView.DataSource = response.Results; uxSearchResultView.DataBind(); uxPageMultiView.SetActiveView(uxViewMessage); if (response.PagingInfo.TotalRecords > 0) { string pagingInfo = "Total # of Results = " + response.PagingInfo.TotalRecords.ToString() + "<br />"; pagingInfo += "Total # of Pages = " + response.PagingInfo.TotalPages.ToString() + "<br />"; pagingInfo += "Displaying search result " + response.PagingInfo.StartRow.ToString() + " through " + response.PagingInfo.EndRow.ToString(); MessageUtilities.UpdateMessage(uxMessage, pagingInfo, Message.DisplayModes.Success); } } else { MessageUtilities.UpdateMessage(uxMessage, "Please enter a search text", Message.DisplayModes.Error); uxPageMultiView.SetActiveView(uxViewMessage); } } catch (Exception ex) { MessageUtilities.UpdateMessage(uxMessage, ex.Message, Message.DisplayModes.Error); uxPageMultiView.SetActiveView(uxViewMessage); } }