Customize search results in Custom Table smart search index

Adam Conde asked on December 27, 2014 19:10

I have a smart search index for a custom table, which returns results as expected when using the smart search web part. However, the hyperlink associated with the search results does not link to anything. How can I have the search results link to a specific page which displays the custom table data?

For example, I have Press Releases stored in a custom table. you can view all the press releases at the page ~/press/ or view a specific press release at ~/press/?id={ItemGUID}. I'd like the search results to link directly to the specific press release.

The smart search web part uses this custom table index and a page index, so I don't think I can specify a transformation for this custom table because it wouldn't work with results from the page index.

Correct Answer

Brenden Kehren answered on December 29, 2014 01:03

I do this same thing for 2 different custom table indexes and a regular document index. So here are a couple things to do:

  • First document what search field has the ID field set in the search settings of the custom table. In my case I set a text field with the ID as the Title field.

  • Second, modify your transformation like so:

        <asp:Hyperlink runat="server" id="lnkGeneral"   visible='<%# GetSearchType(Convert.ToString(Eval("id"))) == "generic" %>'  NavigateUrl='<%# SearchResultUrl(true) %>' >
          <%#SearchHighlight(CMS.GlobalHelper.HTMLHelper.HTMLEncode(CMS.ExtendedControls.ControlsHelper.RemoveDynamicControls(DataHelper.GetNotEmpty(Eval("Title"), "/"))), "<span style='font-weight:bold;'>", "</span>")%>
        <asp:Hyperlink runat="server" id="lnkLocation"  visible='<%# GetSearchType(Convert.ToString(Eval("id"))) == "location"  %>'  NavigateUrl='<%# "/Locations/Details/" + GetStoreNumber(Convert.ToString(Eval("Title"))) %>' >
         Location Result: <%#SearchHighlight(CMS.GlobalHelper.HTMLHelper.HTMLEncode(CMS.ExtendedControls.ControlsHelper.RemoveDynamicControls(DataHelper.GetNotEmpty(Eval("Title"), "/"))), "<span style='font-weight:bold;'>", "</span>")%>

    The ID field has the ClassName you can check to see what page type or custom table record is being rendered. The Title field in my case has the actual ID in it which is why I use it, I think that's the key for you, you need to determine what field will have ItemID in it.

    Good luck

1 votesVote for this answer Unmark Correct answer

Recent Answers

David Pearson answered on January 7, 2015 18:05

I am working on the Corporate site - Transformations > SmartSearchResults GetSearchType generates an error for me. Does not exist in the current context.

Maybe I am working with the wrong Transformation...

Thanks David

0 votesVote for this answer Mark as a Correct answer

Martin Danko answered on January 8, 2015 11:12

Hi David,

What kind of error does it generate? It would be great if you can post here a full error message.

Best regards, Martin

0 votesVote for this answer Mark as a Correct answer

Sarah Bartell answered on July 5, 2016 18:06

I'm also trying to achieve this same functionality. I'm using smart search for our website as a whole, but I would like the search results to show both pages and our press releases, which are housed in a custom table. I set up the search index for the custom table, added it to the webpart, and I tried to implement the code used above for the transformation, but I either get a "The name 'GetSearchType' does not exist in the current context" error. I'm using Kentico v8, so perhaps this code is outdated?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.