Adding Custom Search Results into Sitefinity Search Results Widget

Adding Custom Search Results into Sitefinity Search Results Widget

Posted on 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", "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.

Stanislav Velikov

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

Comments

Comments are disabled in preview mode.
Topics

Sitefinity Training and Certification Now Available.

Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.

Learn More
Latest Stories
in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Loading animation