Categories
Bloggers
Blogs RSS feed

Adding Custom Search Results into Sitefinity Search Results Widget

by Stanislav Velikov
The Sitefinity search results widget renders search results for content that is saved in Sitefinity search index. In order to make the search result widget render a result which is not located in Sitefinity search, the search result can be added on the fly while searching.

The data to construct this custom search result can be coming from a custom query.
To create this customization, create custom search results widget.

Here is the complete sample code.

The customization follows the approach from the blog post for trimming search results based on permissions.

The custom result added is of type IDocument which have several properties to be populated to render complete search result ID, Title, Content, Summary, Link and HighlightedResult. Title and Content.

//add custom search result
                    var searchService = this.GetService();
                    IList<IField> fields = new List<IField>(4);
                    IField fld1 = searchService.CreateDocumentField("Title", "title");
                    IField fld2 = searchService.CreateDocumentField("Id", "Identifier");
                    IField fld3 = searchService.CreateDocumentField("Content", "content");
                    IField fld4 = searchService.CreateDocumentField("Summary", "");
                    IField fld5 = searchService.CreateDocumentField("Link", "http://google.com");
                    IField fld6 = searchService.CreateDocumentField("HighLighterResult", "this is the higjligthed result");
 
                    fields.Add(fld1); fields.Add(fld2); fields.Add(fld3); fields.Add(fld4); fields.Add(fld5); fields.Add(fld6);
 
                    var document = searchService.CreateDocument(fields, "Id");
                    var res = result.ToList();
                    res.Add(document);
                    this.ResultsList.DataSource = res;

The attached sample can be used to automatically create search result on the fly based on the queries that the user enters when searching the website.

1 comment

Leave a comment
  1. Matt May 14, 2014
    I downloaded the source code and added it to my project then registered the control using SF thunder so that it is available in the toolbox.  The control however seems to only work exactly the same as the original searchresult widget and when I put breakpoints in the custom code they are not hit (meaning that the code is not executed).  Any ideas why this would be? Is it to do with the way the control has been registered in SF?

    Leave a comment