1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Add Search Results to UserControl

Add Search Results to UserControl

8 posts, 0 answered
  1. Ben Alexandra
    Ben Alexandra avatar
    215 posts
    Registered:
    15 Sep 2012
    24 Nov 2011
    Link to this post
    Hi,

    I want to create my own usercontrol that includes various items, including your search results.  I need to know what assembly your Search Results lives in and how to register and then reference it so I can add it via code.

    Thanks

    Ben
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    24 Nov 2011
    Link to this post
    Hello Ben Alexandra,

    The search results widget is part of the Telerik.Sitefinity assembly and can be referenced from the Telerik.Sitefinity.Services.Search.Web.UI.Public namespace. Please find below the default template we're using for the control as well:
    <%@ Control Language="C#" %>
    <%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sitefinity" %>
    <%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Services.Search.Web.UI.Public" TagPrefix="sfSearch" %>
     
    <sfSearch:SearchBox ID="topSearchBox" runat="server" />
     
    <sitefinity:SitefinityLabel id="resultsStats" runat="server" WrapperTagName="p" CssClass="sfsearchResultStatistics" Text="<%$Resources:SearchResources, SearchResultsStatusMessage %>" />
     
    <asp:Repeater ID="resultsList" runat="server">
        <HeaderTemplate>
            <dl class="sfsearchResultsWrp sfsearchReultTitleSnippetUrl">
        </HeaderTemplate>
        <ItemTemplate>
            <dt class="sfsearchResultTitle"><a runat="server" href='<%# Eval("Link")%>'><%# Eval("Title") %></a></dt
            <dd class="sfsearchResultSnippet"><%# Eval("Summary")%></dd>
            <dd class="sfsearchResultUrl"><a runat="server"  href='<%# Eval("Link")%>'><%# Eval("Link")%></a></dd>
            <dd class="sfsearchResultHighLighter"><%# Eval("HighLighterResult")%></dd>
        </ItemTemplate>
        <FooterTemplate>
            </dl>
        </FooterTemplate>
    </asp:Repeater>
    <sitefinity:Pager ID="pager" runat="server" />
    <sfSearch:SearchBox ID="bottomSearchBox" runat="server" />
    Please let us know if you need some additional information, we'll be glad to help.

    Best wishes,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Ben Alexandra
    Ben Alexandra avatar
    215 posts
    Registered:
    15 Sep 2012
    24 Nov 2011
    Link to this post
    Great. Thanks!  I'll give it a try!
  4. Ben Alexandra
    Ben Alexandra avatar
    215 posts
    Registered:
    15 Sep 2012
    24 Nov 2011
    Link to this post
    I'm afraid that didn't work.  The search box shows up but in the place where it's supposed to show the results, I just get "{0} search results for {1}"

    I dropped your search results user control on from the toolbox right above it and it returns results but something isn't firing with the code you sent..  There were some problems with the spaces in your code not coming through, but I put spaces everywhere I could think they were needed.  I was getting a parser error before but now I'm not, so I think I got them all.

    Let me know if you have any other ideas

    Thanks!

    Ben
  5. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    25 Nov 2011
    Link to this post
    Hi Ben Alexandra,

    I have just tested this functionality, by registering a custom SearchResults widget in my project, and configuring the Search widget to display the results on the page where the custom widget is dropped (which happens to be the same page in my current example). The widget displays properly the returned results, please find attached a sample video I've recorded while testing this functionality.

    Best wishes,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Ben Alexandra
    Ben Alexandra avatar
    215 posts
    Registered:
    15 Sep 2012
    25 Nov 2011
    Link to this post
    Hi,

    Thanks for the video.  That seems to work better, but doesn't allow me to customize the design like your first version.  Also, so we're clear, this is totally different code (in your video) than what you pasted above, right?

    Here is your NEW code (from the video) and it does seem to work:
    <%@ Control Language="C#"  %>
    <%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Services.Search.Web.UI.Public" TagPrefix="sfSearch" %>
     
    <sfSearch:SearchResults runat="server" ID="MyResults"></sfSearch:SearchResults>


    This is the code I WAS using (from your example above) but it doesn't return results.  It just says: "{0} search results for {1}"
    <%@ Control Language="C#" %>
    <%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sitefinity" %>
    <%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Services.Search.Web.UI.Public" TagPrefix="sfSearch" %>
     
     
    <sitefinity:SitefinityLabel id="resultsStats" runat="server" WrapperTagName="p" CssClass="sfsearchResultStatistics" Text="<% $Resources:SearchResources, SearchResultsStatusMessage %>" />
    <asp:Repeater ID="resultsList" runat="server">
        <HeaderTemplate>
            <dl class="sfsearchResultsWrp sfsearchReultTitleSnippetUrl">
        </HeaderTemplate>
        <ItemTemplate>
            <dtclass="sfsearchResultTitle"><a runat="server" href='<%# Eval("Link")%>'><%# Eval("Title") %></a></dt>
            <ddclass="sfsearchResultSnippet"><%# Eval("Summary")%></dd>
            <ddclass="sfsearchResultUrl"><a runat="server" href='<%# Eval("Link")%>'><%# Eval("Link")%></a></dd>
            <ddclass="sfsearchResultHighLighter"><%# Eval("HighLighterResult")%></dd>
        </ItemTemplate>
        <FooterTemplate>
            </dl>
        </FooterTemplate>
    </asp:Repeater>
    <sitefinity:Pager ID="pager" runat="server"/>
  7. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    29 Nov 2011
    Link to this post
    Hi Ben Alexandra,

    Please excuse me if I have misled you with my latest response. Let me elaborate a little bit on the two approaches we've covered so far. Starting with your initial question:

    "I want to create my own usercontrol that includes various items, including your search results.  I need to know what assembly your Search Results lives in and how to register and then reference it so I can add it via code."
     The Search Results widget's logic is in the SearchResults class of Telerik.Sitefinity.Services.Search.Web.UI.Public namespace. You can register this namespace as a tag prefix in your user control and add the SearchResults inside your user control as I demonstrated in my latest response.
    On the other hand, the SearchResults widget is using a template for the public representation of its data, this is the code I provided you with in my initial response.

    If you want to modify just the visual appearance of your SearchResults control, you can simply create a custom template based on the default one we're using, and then map it to all instances of the widget throughout Sitefinity, or pass it to one widget on a page. . For more information on mapping external templates to Sitefinity 4.x widgets, please check these resources:
    Customizing Sitefinity 4 Controls with the ViewMap
    Mapping External Templates for Sitefinity 4 Widgets

    Now if you need to change the logic of the widget, you can create a custom class, that inherits from the base SearchResults and override the out of the box logic.

    If you need to modify both the logic and the visual representation of the data, you can create a custom class, that inherits from the base SearchResults, implement your own logic, and then pass the customized template to the layoutTemplatePath property of the control.

    Please note that when using the template only, you're missing the code-behind logic that passes data to the Repeater inside the SearchResults template, that's why you're getting no results. On the other hand if you're just using the control inside a user control, like I demonstrated in my latest response, you can either go with the default template, or specify a customized one in the control declaration like this:
    %@ Control Language="C#" AutoEventWireup="true" CodeBehind="SearchResultsCustom.ascx.cs" Inherits="SitefinityWebApp.Controls.SearchResultsCustom" %>
    <%@ Register TagPrefix="sfSearch" Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Services.Search.Web.UI.Public" %>
    This is my custom Search results widget
    <sfSearch:SearchResults runat="server"  LayoutTemplatePath="~/MyCustomTemplate.ascx"></sfSearch:SearchResults>

    On a side note, I'd like to elaborate a little bit on the SearchResults widget functionality. Since the search functionality in Sitefinity is designed to be universal for all content types(i.e. so you can include multiple content types in one search index, and then look for a keyword in the generated index for different content types) the SearchResults widget builds a query which returns a result of type IResultSet and then binds the results of the query to a control which displays the returned results as clickable links. Each of the generated links will pass a querystring to a selected page where a ContentView widget of the corresponding type is placed (this is the default page where this content is published, you specify it for each content type when configuring the search index). Then this widget will be able to resolve and display the particular content item.

    Please do not hesitate to let us know if any problems persist, or you need some more information. Maybe if you share with us the exact use case scenario that you need to implement, we can give you a more specific advice.

    All the best,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Jagjot
    Jagjot avatar
    3 posts
    Registered:
    17 Jul 2012
    17 Jul 2012
    Link to this post
    Hello 

    I have similar problem. In my case i need to add custom results along with other search results. I have created a department page which shows the products of particular department( on the basis of department id passed as query string). Now the client want us to include the page in search results along with querystring whenever somebody searches for Department Name. 
8 posts, 0 answered