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

Forums / Developing with Sitefinity / display custom search results fields

display custom search results fields

2 posts, 0 answered
  1. Will
    Will avatar
    1 posts
    Registered:
    01 Apr 2010
    13 Sep 2011
    Link to this post
    Hi,

    We have created a file management app into sitefinity 3.7.  We have created an index on this and everything looks good.  Now I want to use the search results but it only gives me 4 fields to display the values. (title, URL, snippet and score)  I would like to display the values from our fieldsInfoProvider.xml which has these fields:title, description, categories, authors and issues.

    I've create a new usercontrol called mysearchresults.ascx so I have a code behind and copied the stuff from your template searchresults.ascx.

    how do I go about getting these fields into the resultsitem?  Or how do I access these fields so I can use it to display on mySearchResults.ascx?

    thanks,
    Will
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    17 Sep 2011
    Link to this post
    Hello Will,

    Thank you for using our services.

    Unfortunately this is cannot be achieved with the Search indexing functionality. The fields that you find in the fieldsInfoProvider.xml file tell the index what to index from the document what is fetched to the indexer. Then when you search for a keyword the search manager looks for hits in all indexed document's fields. When the indexer finds hits it forms the snippet by caluclating the number of hits in each indexed field, the weight of the field and concatenates the snippet.

    The ResultItem object passed to the repeater which displays results does not hold information about the CMS object being displayed in the results page. It only hods the URL, Title, and Snippet. This means that you cannot get the CMS Page, News Item, Blog Post or etc. object rendered in the results page. This prevents you from being able to directly access the item.

    A possible workaround is to bind to the ItemDataBound event of the results repeater in ~/Sitefinity/ControlTemplates/Search/SearchResult.ascx. Then you have to check the item type of e.Item and if it is ListItem or AlternatingItem you can get the e.Item.DataItem variable which will be of type ResultItem. Once you get the result item, if you know that it is a page then you can get find the page using CmsManager by searching for a page with this URL and then display Title, Description, etc.

    All the best,
    Radoslav Georgiev
    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
2 posts, 0 answered