Search Result URL from Custom Table

Sarah Bartell asked on July 5, 2016 18:30

I'm having the same issue from this question: http://devnet.kentico.com/questions/customize-search-results-in-custom-table-smart-search-index

Where the URL generated in a search result, when the result is a custom table item, does not render properly, so a custom transformation is needed to properly display the URL with the custom tables ItemID.

This was the code suggested to solve the issue.

<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>
<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>")%>
</asp:Hyperlink>

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 that indext to the search webpart, and I tried to implement the code used in the thread above for the transformation, but I get a "The name 'GetSearchType' does not exist in the current context" error. I'm using Kentico v8, so perhaps this code is outdated?

Recent Answers


Virgil Carroll answered on July 5, 2016 19:49

The GetSearchType was a custom function Brenden Kehren shared in his response to the other thread. That is not a function built into Kentico. You would need to add that function into your code to make it work correctly. You could either add it right into the transformation or write a custom code file that can be referenced.

1 votesVote for this answer Mark as a Correct answer

Sarah Bartell answered on July 5, 2016 19:59

Ok so I'm guessing I don't need the "visible=" part of the code at all.

I want the search result URL to be: http://www.site.com/News/Article.aspx&ItemID=XXX, so the code would be something like this?

<asp:Hyperlink runat="server" id="lnkLocation" NavigateUrl='<%# "/News/Article/" + GetItemID(Convert.ToString(Eval("ItemID"))) %>' >

So instead of "GetStoreNumber" I need to make a "GetItemID" request? How do I add that to the code?

Sorry I'm not a developer so I'm kind of clueless on this stuff.

0 votesVote for this answer Mark as a Correct answer

Virgil Carroll answered on July 6, 2016 20:34

Sarah,

Not sure why you would need to do the GetItemID, when you already have the ItemID value referenced here: Eval("ItemID"). Is this not the value you want? The only reason you wuld need to call an additional function is so you can get another value besides that.

0 votesVote for this answer Mark as a Correct answer

Sarah Bartell answered on July 7, 2016 15:34

So I've tried using this:

<asp:Hyperlink runat="server" id="lnkGeneral"  NavigateUrl='<%# SearchResultUrl(true) %>' >
 <%#SearchHighlight(HTMLHelper.HTMLEncode(CMS.ExtendedControls.ControlsHelper.RemoveDynamicControls(DataHelper.GetNotEmpty(Eval("Title"), "/"))), "<span style='font-weight:bold;'>", "</span>")%>
</asp:Hyperlink>

<asp:Hyperlink runat="server" id="lnkLocation"  NavigateUrl='<%# "/News/Articles.aspx?ItemID=" + Convert.ToString(Eval("ItemID")) %>' >
 Location Result: <%#SearchHighlight(HTMLHelper.HTMLEncode(CMS.ExtendedControls.ControlsHelper.RemoveDynamicControls(DataHelper.GetNotEmpty(Eval("Title"), "/"))), "<span style='font-weight:bold;'>", "</span>")%>
</asp:Hyperlink>

And the search results appear twice. Once with no hyperlink and a 2nd time with a hyperlink that doesn't populate the ItemID. Help.

0 votesVote for this answer Mark as a Correct answer

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