How to display custom data in a transformation for the Smart Search results

   —   
The smart search doesn’t return all data of a document, only a small subset of it. This article describes how to retrieve additional data and how to display it in the results listing. You can also perform some other logic based on this article like for example retrieve all the children of a document and display them in the search results.
The smart search doesn’t return all the data of a document by default. For example, if you want to display some custom data in the search results you will have to get the data by yourself. The default approach for retrieving additional column data associated with the document for smart search results is to use the transformation method GetSearchValue(string columnName).  In some cases this isn’t enough and you will need to get some other data bound to the document. An example could be getting all the child documents of the document or some custom table data which is bound to the document by the DocumentID. Additionally, using a transformation function isn’t a good solution performance-wise, since you are executing a new query to the database for each result. A set of instructions how to solve this follows.
As a starting point we will work with the default data returned by the smart search. You can see the values returned by default in the attached image.

CMSSolution_WebDeveloper-(Debugging)-Visual-Web-Developer-2008-Express-Edition_2012-03-06_11-31-16.png

The first column contains the DocumentID;NodeID_object.type value. You can parse the column to get those IDs to retrieve the additional data. You can use the DocumentID or NodeID depending on where your values are saved using our API. As I mentioned previously, I would recommend you to get all the objects containing the data you need at once and to create an additional column in the results dataset which can be later used in the transformation to display the given value, because retrieving the additional data for each item separately can cause performance issues. Now, after you’ve retrieved the data, you can add the column “MyData” to the results dataset:

results.Tables[0].Columns.Add("MyData", typeof(string));

Now you can populate this new column for each result and you can then use the Eval(“MyData”) syntax to display the data in the transformation. As you can see in the image, these changes need to be performed in the file CMSModules\SmartSearch\Controls\SearchResults.ascx.cs in the method Search().
 
-bp-


See also: http://devnet.kentico.com/downloads/kenticocms_api.zip
http://devnet.kentico.com/docs/6_0/devguide/smart_search_transformations.htm


Applies to: Kentico 5.5 and higher
Share this article on   LinkedIn