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

Forums / Developing with Sitefinity / Extending SearchResult

Extending SearchResult

14 posts, 0 answered
  1. Angel
    Angel avatar
    32 posts
    Registered:
    04 Feb 2008
    01 Apr 2010
    Link to this post
    Hi,

    I have few questions about SearchResult(probably the answers would be the same for SearchBox):

    1. If I want to make it with new look can I put it in a new folder? And if yes - should I override the path for it somewhere?
    2. Is there a code-behind for those ascx files? If not how can I override their methods? I guess I can override methods given here: http://www.sitefinity.com/help/developer-manual/telerik.search-telerik.search.webcontrols.searchresult.html

    Probably more questions will come after that!

    Thanks,
    Angel Antonov
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    01 Apr 2010
    Link to this post
    Hi Angel,

    1. If I want to make it with new look can I put it in a new folder? And if yes - should I override the path for it somewhere?

    SearchResults.ascx is only a template for SearchResults control. The control is embedded into Telerik.Search.dll. There are two way to change the template of the contol

    1. Using the public property of the control - LayoutTemplatePath. Once you open the control designer you will find the property under Appearance category.

    2.If you create a custom class that inherits from Telerik.Search.WebControls.SearchResults and implement new template.

    sample code

         public ITemplate LayoutTemplate
           {
               get
               {
                   if ( this.layoutTemplate == null )
                       this.layoutTemplate = ControlUtils.GetTemplate<DefaultTemplate> ( this.LayoutTemplatePath );
                   return this.layoutTemplate;
               }
               set
               {
                   this.layoutTemplate = value;
               }
           }
     
    public string LayoutTemplatePath
           {
               get
               {
                   object obj = this.ViewState[ "layoutTemplatePath" ];
                   if ( obj != null )
                       return ( string ) obj;
                   return "~/HERE SET THE PATH TO YOUR CUSTOM TEMPLATE";
               }
               set
               {
                   this.ViewState[ "layoutTemplatePath" ] = value;
               }
           }

    2. Is there a code-behind for those ascx files? If not how can I override their methods? I guess I can override methods given here


    There is no code behind of the control. Please take a look at "1"

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Angel
    Angel avatar
    32 posts
    Registered:
    04 Feb 2008
    07 Apr 2010
    Link to this post
    Hi Ivan,

    Thanks for the answer!

    I just watched I just watched "Working with Sitefinity search" from http://www.sitefinitywatch.com/blog.aspx?BlogTagID=b4bc3f17-8ee6-4621-82b2-78e534eff98a !!! A pretty good webinar :)

    What I need for my search result is to display the date of the news item which is not a property of the ResultItem Class that is used in the SearchResult.ascx

    Is that somehow configurable easily (to get the date) or should I go with the custom implementation used in the webinar^^?

    Thanks,
    Angel Antonov
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Apr 2010
    Link to this post
    Hello Angel,

    You need to add the item guid in the Snippet. You can do this from fieldsInfoProvider.xml that is generated in the folder of each search index. You could take a look at this post. Then you have to extract the ID from the snippet as shown in the post and get the metadata by using GetMetaData method of the content item.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Angel
    Angel avatar
    32 posts
    Registered:
    04 Feb 2008
    08 Apr 2010
    Link to this post
    Hi Ivan,

    The other post was very useful! I finally can get the information I need! There is still one problem existing. I cannot understand where do I put this:

    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;
                string value = resultITem.Snippet;
                string ID = value.Substring(0, 36);
                  
                
            }
        }

    I cannot just make a new webcontrol and directly inherit Telerik.Search.WebControls.SearchResults. If I create a SearchResult.cs in my App_Code and inherit Telerik.Search.WebControls.SearchResults how do I use that in SF as a control?

    Sorry, I'm pretty confused here with using that!!!

    Edit: I have one more question - Since I wnat to make a search in hole site how do I get it's content?
    What I do to get the news is:
    ContentManager manager = new ContentManager("News");
    What do I do to get all the pages?

    Kind regards,
    Angel Antonov
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    09 Apr 2010
    Link to this post
    Hello Angel,

    1. The code should be added to the SearchResults template where you access the repeater. Another option is crating a custom class library or custom control and filter the default snippet. Then you have to create a new list of filtered Result Items. You may find this post useful

    2. To get all pages you can use CmsManager class - GetPages().

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. Angel
    Angel avatar
    32 posts
    Registered:
    04 Feb 2008
    13 Apr 2010
    Link to this post
    Hi Ivan,

    I am using GetPages(), but I'm afraid that it returns only the default language pages!!! The same thing goes for:

    IList allNews;
    ContentManager manager = new ContentManager("News");

    allNews = manager.GetContent();


    Any suggestions?
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Apr 2010
    Link to this post
    Hello Angel,

    You could use LangID property


    Regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  9. Angel
    Angel avatar
    32 posts
    Registered:
    04 Feb 2008
    13 Apr 2010
    Link to this post
    Hi,

    How do I get an instance of CmsProvider? so I can use the GetPageLanguageVersion method

    I think I just found it myself:

    CmsPageContent.CmsProvider.GetPageLanguageVersion(pageID, langID)
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Apr 2010
    Link to this post
    Hello Angel,

    Just call new CmsManager();. This is the same way that you create an object from another ASP.NET class.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  11. Angel
    Angel avatar
    32 posts
    Registered:
    04 Feb 2008
    14 Apr 2010
    Link to this post
    Hi Ivan,

    I'm almost there, but I still have some problems. What I'm doing to get English version of the sites is (the default language is Dutch):

    public IIndexerInfo[] GetContentToIndex()
    {
        IList allNews;
        ContentManager manager = new ContentManager("News");
        allNews = manager.GetContent();
     
        List<IIndexerInfo> results = new List<IIndexerInfo>();
        foreach (IContent news in allNews)
        {
            VAIndexerInfo vaInfo = new VAIndexerInfo();
            vaInfo.Title = news.GetMetaData("Title").ToString();
            vaInfo.Content = news.Content.ToString();
            vaInfo.Date = news.GetMetaData("Publication_Date").ToString();
            if (news.Language == "en")
                vaInfo.Url = string.Format("{0}/{1}", "en" + news.Url);
            else
                vaInfo.Url = news.Url;
     
            vaInfo.IsNews = true;
     
            results.Add(vaInfo);
        }
     
     
        CmsManager cmsManager = new CmsManager();
        IList allPages = cmsManager.GetPages();
         
     
        foreach (CmsPageContent page in allPages)
        {
            VAIndexerInfo vaInfo = new VAIndexerInfo();
            vaInfo.Title = string.IsNullOrEmpty(page.Title) ? "..." : page.Title.ToString();
            vaInfo.Content = GetInternalPageData(page.ID);
            //if (page.LangID == 127 || page.LangID != 9)
                vaInfo.Url = page.StaticUrl;
            //else
            //    vaInfo.Url = string.Format("{0}/{1}", "en", page.StaticUrl);
     
            vaInfo.IsNews = false;
     
            ICmsPage enPage = page.CmsProvider.GetPageLanguageVersion(page.ID, 9);
            if (enPage != null)
            {
                VAIndexerInfo vaInfoEn = new VAIndexerInfo();
                vaInfoEn.Title = string.IsNullOrEmpty(enPage.Title) ? "..." : enPage.Title.ToString();
                vaInfoEn.Content = GetInternalPageData(enPage.ID);
                vaInfoEn.IsNews = false;
     
                results.Add(vaInfoEn);
            }
     
            results.Add(vaInfo);
        }
     
        return results.ToArray();
    }

    The bold code is my added code to get the English pages, I'm not sure if I'm doing it the correct way!
    Although it should work fine I'm getting error while indexing:

    Value cannot be null.
    Parameter name: docPath


    Telerik.Search.Engine.BaseIndexer.AddDataToIndex(Byte[] data, String docPath, Encoding encoding, Guid dataId) +522
       Telerik.Search.Engine.Crawler.IndexContent(String provider, LinkedList`1 data, Boolean appendToIndex, Dictionary`2 indexers) +253
       Telerik.Search.Engine.Crawler.Index(String provider, String[] urls, LinkedList`1 data, Boolean appendToIndex) +150
       Telerik.Search.Engine.IndexingManager.StartIndexing(IIndexingService service, Boolean appendToIndex) +86
       Telerik.Search.Engine.IndexingService.Index(Boolean appendToIndex) +11
       Telerik.Search.WebControls.Admin.ControlPanel.Service_Command(Object sender, CommandEventArgs e) +334
       System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +108
       System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
       System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


    I tried putting the bold code in try-catch block, but it still crashes!

    How should I get the English news as well, so far it is only retrieving Dutch news?
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    14 Apr 2010
    Link to this post
    Hi Angel,

    The error could be thrown if the collection of pages is empty or null. Then the parameter is empty and you get the error. Also you could create the following helper class the return the culture and clear your code

    internal class CultureHelper
     {
         internal static CultureInfo GetPageCulture(IPageContent page)
         {
             CultureInfo culture;
             if (page.LangID == CultureInfo.InvariantCulture.LCID)
                 culture = LocalizationManager.DefaultCulture;
             else
                 culture = CultureInfo.GetCultureInfo(page.LangID);
             return culture;
         }
     }


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  13. Angel
    Angel avatar
    32 posts
    Registered:
    04 Feb 2008
    15 Apr 2010
    Link to this post
    Hi Ivan,

    and thanks for the answer!

    One more thing - on the search results, each one is showing a snippet of 5-6 lines (if available) of the text in the page. How can I set that to max 3 lines?
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Apr 2010
    Link to this post
    Hi Angel,

    The lines that you see shows the snippet by calling Eval in Sitefinity\ControlTemplates\Search\SearchResult.ascx

    <ItemTemplate>
        
        <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>
    </ItemTemplate>

    The ResultItem snippet is string, so you could use String.Substring Method (Int32, Int32)

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
14 posts, 0 answered