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

Forums / Developing with Sitefinity / how do I format the items on the search result page?

how do I format the items on the search result page?

6 posts, 0 answered
  1. Inna Young
    Inna Young avatar
    8 posts
    Registered:
    21 Jul 2009
    17 Nov 2009
    Link to this post
    Hello, is there a way to control how the search results are displayed on the search result page?

    Currently we have it all crammed together:

    http://web1.annapolis.gov/SearchResults.aspx?IndexCatalogue=Website%20Search&SearchQuery=planning

    Thank you!

    Inna
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    17 Nov 2009
    Link to this post
    Hi Inna Young,

    You can modify the html elements or add some styles to SearchResults template located under Sitefinity/ControlTemplates/Search/SearchResult.ascx. If you want to modify the exact search item you can subscribe for ItemDataBound event of "rptResults" and access ResultItem object.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Inna Young
    Inna Young avatar
    8 posts
    Registered:
    21 Jul 2009
    17 Nov 2009
    Link to this post
    This is a perfect advice! All worked, thank you.

    Now, another question:

    Currently the search page displays:
    1. Title (of the page searched for)
    2.  Some nonsense (that we need to substitute with something  meaningful)
    3.  Url (perfect!)

    The code for this display is:
    -----------------------------------------------------------------------
     
        <ItemTemplate>
           <p>
            <dt>
            <strong>
            <a href='<%#DataBinder.Eval(Container.DataItem, "Url")%>'><%#DataBinder.Eval(Container.DataItem, "Title")%></a>
            </strong>
            </dt>
            
                      
            <dd><%#DataBinder.Eval(Container.DataItem, "Snippet")%></dd>
            
            <dd>
            <em>
            <a href='<%#DataBinder.Eval(Container.DataItem, "Url")%>'><%#DataBinder.Eval(Container.DataItem, "Url")%></a>
            </em>
            </dd>
              
            </p>
            <hr size="1"  width="95%" />
        </ItemTemplate>
    ------------------------------------------------------------------------

    This line of code <dd><%#DataBinder.Eval(Container.DataItem, "Snippet")%></dd> displays nonsense.

    http://web1.annapolis.gov/SearchResults.aspx?IndexCatalogue=Website%20Search&SearchQuery=plan

    What do I do to change it?

    Thank you!

    Inna
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    17 Nov 2009
    Link to this post
    Hello Inna Young,

    The snippet shows the content of the result item. For instance your query is looking for the word plan. The indexer has looked in all content items( or pages) where you have used the world plan and as a result a small snippet is returned

    "Information Technology Office of the Mayor Public Works Monday, October 19, 2009 IT Strategic Plan Government > Departments > Management Information Technology > IT Strategic Plan Table of Contents ... IT Service Delivery Recommendations Implementation Plan Overview Project Summary Project Schedule ..."

    Basically the result is part of content where "Plan" is met while the crawler was indexing. Could you tell us what exactly you want to modify to the snippet, so we could think of a possible solution.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Inna Young
    Inna Young avatar
    8 posts
    Registered:
    21 Jul 2009
    18 Nov 2009
    Link to this post
    Ivan,

    It would make perfect sense if we'll insert there a page description, a field that we have to fill out when we are creating a new page. I just need to know the code, so I could insert it.

    Thanks again.

    Inna
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    18 Nov 2009
    Link to this post
    Hello Inna Young,

    This is the code that will allow you to access the search item and its properties.

    You need to create a code behind of Sitefinity\ControlTemplates\Search\SearchResult.ascx and subscribe for rptResults ItemDatabound event.

    protected void Page_Load(object sender, EventArgs e)
      {
          this.rptResults.ItemDataBound += new RepeaterItemEventHandler(rptResults_ItemDataBound);
           
      }
     
      void rptResults_ItemDataBound(object sender, RepeaterItemEventArgs e)
      {
          if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
          {
              Telerik.Search.Engine.ResultItem resultITem = e.Item.DataItem as Telerik.Search.Engine.ResultItem;
     
             // HERE YOU CAN USE THE RESULTITEM OBJECT
             
          }
      }

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
6 posts, 0 answered