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

Forums / Developing with Sitefinity / Customizing seacr results

Customizing seacr results

4 posts, 0 answered
  1. syed
    syed avatar
    22 posts
    Registered:
    05 Mar 2009
    07 Jul 2009
    Link to this post
    HI there

    Is this possible to limit the number of lines in "snippet container" in seacrh results page?

    Example Below: i want to display the description in 2lines instead of 6lines.

    Untitled Document
    ... Jebel Ali International Hotels Home Page   Home | Reservation | Download Brouchure | Visitors info | Contact Us   RESORT HOTELS RESTAURANTS & BARS GOLF THE SPA SPORTS & LEISURE MEETINGS & EVENTS PROMOTIONS & PACKAGES CONTACT US Reservations Modify your Booking Find a Hotel SELECT YOUR HOTEL Palm Tree Court & Spa Jebel Ali Hotel Hatta Fort Hotel Oasis Beach Tower Arrival Date Nights 1 2 3 4 5 Rooms 1 2 3 4 5 Adults 1 2 3 4 5 Child(ren) 1 2 3 4 5 Promo ID Register ...


    thanks
    syed
  2. Nikolai
    Nikolai avatar
    216 posts
    Registered:
    01 Jun 2017
    07 Jul 2009
    Link to this post
    Hi syed,

    The best approach for limiting the "snippet" for you is to override the "Search Results" public control or create a new one. This way you will be able to modify the ResultItem.Snippet property, which holds the text you want to limit.

    You can also try to modify the template: "\Sitefinity\ControlTemplates\Search\SearchResult.ascx" which is the "Search Result" control. Change the "snippet" string format from:
    <%#DataBinder.Eval(Container.DataItem, "Snippet")%>
    to:
    <%#DataBinder.Eval(Container.DataItem, "Snippet", "{0}").Substring(0, 20)%>
    this way the "snippet" will be limited to 20 chars. but have in mind that the "snippet" itself contains html tags so this may mess up the results.

    Greetings,
    Nikolai
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. syed
    syed avatar
    22 posts
    Registered:
    05 Mar 2009
    07 Jul 2009
    Link to this post
    Hi
    thanks for your rapid reply.

    i thing better to go with over riding pubblic controls.

    can you please tell me how can we do that

    thanks
    syed
  4. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    07 Jul 2009
    Link to this post
    Hello syed,

    Please take a look at this forum thread - it will show you how to create a custom control.

    We have actually prepared some examples in the past, in order to illustrate how to modify the Snippet property for each search result item. The files needed are attached to the post. Please follow the following steps in order to run the example:

    1. You must place the SearchResultModified.ascx in the ~[your site]/Sitefinity/ControlTemplates/Search/ folder of your site.
    2. Put the SearchResultModified.ascx.resx file in the ~[your site]/Sitefinity/ControlTemplates/Search/App_LocalResources folder.
    3. Edit your SearchResult control. Change the property LayoutTemplatePath (located in Advanced tab,Appearance category) to ~/Sitefinity/ControlTemplates/Search/SearchResultModified.ascx.
    4. Edit the SearchResultModified.ascx.cs file and modify it to match your requirements (the attached version will remove the timestamps form the search results):
        void rptResults_ItemDataBound(object sender, RepeaterItemEventArgs e) 
        { 
            if (e.Item.ItemType == ListItemType.Item || 
                e.Item.ItemType == ListItemType.AlternatingItem) 
            { 
                ResultItem item = e.Item.DataItem as ResultItem; 
     
                Literal snippetPlace = e.Item.FindControl("snippetPlace"as Literal; 
                if (snippetPlace != null
                { 
                    item.Snippet = "Something";
                } 
            } 
        } 

    You should only change the highlighted code in order to apply your changes to the snippet.
    I hope this helps.

    Best wishes,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
4 posts, 0 answered