Ektron 9.00
Beginning with Ektron version 8.5, search capabilities are enhanced with several new server controla server control uses API language to interact with the CMS and Framework UI to display the output. A server control can be dragged and dropped onto a Web form and then modified.s.
NOTE: To apply paging to a search results page, use an EktronUI:Pager.
Templated server controla server control uses API language to interact with the CMS and Framework UI to display the output. A server control can be dragged and dropped onto a Web form and then modified.s are more specialized than their predecessors, which typically used 1 control to retrieve and display results. To provide search functionality, use 3 templated controls.
The following example shows this relationship using site search controls.
Benefits of these controls include the ability to:
To replicate all of the previous search server controls' functionality, use a combination of templated controls. For example, use the Pager control to manage the paging of search results. Also, use the Advanced Query Text parameter to limit results to those in a selected folder, in a selected taxonomya content-level categorization system that uses one-to-many relationships (such as Ronald Reagan is to Actor, Governor, and President) to create a scalable organization of content. A taxonomy lets your site visitors navigate content independent of the folder structure. category, and so on.
Search server controls have no Ektron-specific properties. In contrast, the pre-8.5 Search server control properties let you configure language, Display XSLTExtensible Stylesheet Language Transformations, folder ID, and so on.
References
You modify the behavior of templated controls by editing their markup. You no longer use Ektron server control properties nor an XSLT to edit the control's behavior.
You can edit a control's default markup, as well as the markup on any page that contains it.
<ItemTemplate>
tags between the control's opening and closing tags. <ItemTemplate>
tags instruct the server control to ignore the default properties.<ektron:SiteSearchResultsView ID="SiteSearchInputView1" ControllerID="Scontroller" Visible="true" runat="server"> <ItemTemplate> </ItemTemplate> </ektron:SiteSearchResultsView>
<ektron:SiteSearchResultsView ID="SiteSearchInputView1" ControllerID="Scontroller" Visible="true" runat="server"> <ItemTemplate> <h1>Search Phrase:<%# Eval("QueryText") %></h1> <asp:ListView ID="aspResults" runat="server" DataSource='<%# Eval("Results") %>' ItemPlaceholderID="aspPlaceholder"> <layouttemplate> <ul class="results"> <asp:PlaceHolder ID="aspPlaceholder" runat="server"> | </asp:PlaceHolder> </ul> </layouttemplate> <itemtemplate> <li class="result ektron-ui-clearfix"> <h3 class="title"> <a href="<%# Eval("Url") %>"><%# Eval("Title") %></a> </h3> <div class="summary"> <%# Eval("Summary") %> </div> <span class="url ektron-ui-quiet"> <%# Eval("Url") %> </span> <span class="date ektron-ui-quiet"> <%# Eval("Date") %> </span> </li> </itemTemplate> </asp:ListView> </Itemtemplate> </ektron:SiteSearchResultsView>
InputView and ResultsView controls have a corresponding .ascx template that contains their default markup. To change a control's default markup, modify its template.
To find a control's template file, open the folder siteroot\workarea\FrameworkUI\Templates\Search
, and locate the .ascx file that matches the control's name. For example, siteroot\workarea\FrameworkUI\Templates\Search\SiteSearchResultsView.ascx
.
NOTE: "Controller"controls only process data. Because they have no UI component, they do not have a template file.
The default .ascx file affects all instances of a control on your website. However, you may customize single instances of a control. To do so, see Customizing a Single Instance of a Templated Search Server Control.
Within an </ItemTemplate>
tag, use an eval statement <%# Eval() >)
to access Ektron's Search API object and expose its properties to the data binder. For example, <%# Eval (“QueryText”)%>
displays the search term in the search results.
As an example, you can remove the summary from the search results by deleting this line.
<div class="summary"><%# Eval("Summary") %></div>
Use an <%# Eval()>
statement to determine which field properties appear in search results. For example, <%# Eval("Summary")%>
displays each content item's summary.
When you insert <%# Eval()>
between a set of </ItemTemplate>
tags, a model is passed to the statement. Each set of controls has a model that determines available fields and properties. For example, the SearchModel's Results
property includes these fields:
Other models are SearchModel (covers content and XML Smart Forms) and UserSearchModel. The model's fields appear in the right pane.
To modify the text displayed by a templated control (for example, no results found), edit the corresponding .resx file in the siteroot\workarea\FrameworkUI\Templates\Search\app_loclaresources
folder.
For example, to edit text supplied by the Site Search template, edit siteroot\workarea\FrameworkUI\Templates\Search\app_loclaresources\SiteSearchInputView.ascx.resx
.
Ektron Search
.siteroot/bin/Ektron.Cms.Framework.UI.Controls.dll.
You should also add EktronUI controls to the Visual Studio toolbox at this time. See Installing Server Controls into Visual Studio.
Ektron's templated server controls use an MVC architecture, which is a common design pattern for user interfaces. MVC consists of a
Because MVC architecture separates the display layer from the data layer, a designer can work on the styling of the search results page, while a developer focuses on data being rendered.
You can extend the functionality of templated server controls by creating a custom service. For example, you can dynamically replace the content of the search results. You might want to do this to create a profanity filter, or to implement a "blacklist" of replacement terms in search results.
The following image illustrates the location of a custom (passthru) service within MVC architecture.
.
The passthru service completes these steps.
Use the siteroot/ektron.cms.framework.ui.unity.config
file to map each search type to a service. Below is the section of the file that accomplishes the mapping. By default, Ektron search controls use ISearch.Service
to take in and return data.
Note separate register statements for regular searches, product searches, and user searches.
NOTE: The ISearchController service handles regular content and XML Smart Form searches.
<register type="Ektron.Cms.Framework.UI.ISearchController, Ektron.Cms.Framework.UI" mapTo="Ektron.Cms.Framework.UI.Services.SearchController, Ektron.Cms.Framework.UI.Services"/> <register type="Ektron.Cms.Framework.UI.IProductSearchController, Ektron.Cms.Framework.UI" mapTo="Ektron.Cms.Framework.UI.Services.ProductSearchController, Ektron.Cms.Framework.UI.Services"/> <register type="Ektron.Cms.Framework.UI.IUserSearchController, Ektron.Cms.Framework.UI" mapTo="Ektron.Cms.Framework.UI.Services.UserSearchController, Ektron.Cms.Framework.UI.Services"/>
Follow these steps to create your own service and map it to a search type.
unity.ui.services.config
.<register type="Ektron.Cms.Framework.UI.ISearchService, Ektron.Cms.Framework.UI" mapTo="Demo.DemoSearchService"/>
using Ektron.Cms.Framework.UI;
unity.ui.services.config
.)public class DemoSearchService: ISearchService { }
public void AdvancedSearch(SearchModel model) { throw new NotImplementedException(); }
public class demosearchservice : ISearchService ISearchService searchService; public DemoSearchService() { this.searchService= new MockSearchService(); }
public void BasicSearch(SearchModel model) { this.searchService.BasicSearch(model); }
Now, when you drop inputview and resultsview controls on a page...
SiteSearchResultsView
tags, insert a set of <itemtemplate>
tags. <itemtemplate>
tags, insert <%# Eval(“QueryText”) %>
<ektron:SiteSearchResultsView ID="SiteSearchResultsView1"
ControllerID="Scontroller" runat="server">
<ItemTemplate> <%# Eval(“QueryText”) %> </ItemTemplate>
</ektron:SiteSearchResultsView \>
QueryText
. For this example, change the query text to "fifteen." To do this, edit the .cs file, like this.‘Public void BasicSearch(SearchModel model) { model.Querytext = “fifteen”; }
This example shows how search results may be modified after they are retrieved (that is, on the way back). To do this, edit the .cs file that you created in Creating a Custom Service Procedure like this.
Public void BasicSearch(SearchModel model)
{
model.Results.ForEach(result =>
{ result.Summary = result.Summary.Replace(“Summary”, “Ektron”); });
}
The above code loops through all results (Results.ForEach
) and replaces "Summary" with "Ektron" in each one.
This example shows how to remove the first search result that is retrieved. To do this, edit the .cs file that you created in Creating a Custom Service Procedure like this.
Public void BasicSearch(SearchModel model) { model.Results.RemoveAt(0); }
The AdvancedQueryText parameter lets you customize the behavior of the search controller. As examples, you can restrict search results to
Here is a sample AdvancedQueryText statement that restricts search results by language and folder.
(Assumes a SiteSearchController named siteSearchController1
is defined on my page)
<ektron:SiteSearchController ID="siteSearchController1"></ektron:SiteSearchController>
Set the AdvancedQueryText property in the code-behind for that page:
protected void Page_Init(object sender, EventArgs e) { siteSearchController1.AdvancedQueryText = string.Format( "({0}:1033 AND {1}:10)", SearchContentProperty.Language.Name, SearchContentProperty.FolderId.Name); }
The value assigned to AdvancedQueryText is appended to the user’s input.
folderid:10
folderidpath:'10'
(folderidpath:'10' AND NOT folderid:10)
NOTE: You cannot use the root
folder as part of the foldernamepath.