Adding Custom Search Results into Sitefinity Search Results Widget

Adding Custom Search Results into Sitefinity Search Results Widget

December 20, 2013 0 Comments

The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.

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", "");
                    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();
                    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.

Stanislav Velikov

Stanislav Velikov is a Tech Support Engineer at Telerik. He joined the Sitefinity Support team in April 2011.

Comments are disabled in preview mode.
Latest Stories in
Your Inbox
More From Progress
The New Mobile Development Landscape
Download Whitepaper
IDC Spotlight Sitefinity Thumbnail
Choosing the Right Digital Experience Platform to Improve Business Outcomes
Download Whitepaper
The Fastest Way to Build Mobile Apps With Cloud Data
Watch Webinar