API Questions on Kentico API.
Version 5.x > API > Search Results of Products vs Documentszzzzz View modes: 
User avatar
Member
Member
sammy - 2/5/2014 8:49:01 PM
   
Search Results of Products vs Documentszzzzz
Hi all,
I'm implementing a generic search. I want to search both documents and products.

When I display the results, I want to display products differently than documents. (for example, I want to place a thumbnail image next to the product).

I also want all products to be listed before documents.

I also want to highlight the searched text, to display where it is in the searched contents.

(I"m not asking for much, am i? ) ;-)

So, since this is the 1st time working with search, i've done some searching myself on this site, and my google foo is failing me.

Would someone be able to point me in the right direction, for searching products + documents like I want, yet display them differently?

Thanks!

User avatar
Member
Member
sammy - 2/5/2014 8:49:35 PM
   
RE:Search Results of Products vs Documents
(I wish there was a way to edit the post title)

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 2/6/2014 2:05:33 AM
   
RE:Search Results of Products vs Documentszzzzz
Hi,

Thank you for your message.

I believe that this could be accomplished by a correct transformations.

You could determin whether your search result is representing SKU or not. In this case I would most likely recommended creating a custom macro method. You would pass a DocumentID of the current search item. In the macro you would check if its SKU and if it is you would get the image and return tha tag with image.

The:
GetSearchValue("DocumentID")

Is holding the document ID of searched Item. You can create macro method according to: http://devnet.kentico.com/docs/devguide/registering_cutom_macro_methods.htm

Kind regards,
Richard Sustek

User avatar
Member
Member
sammy - 2/6/2014 2:35:32 PM
   
RE:Search Results of Products vs Documentszzzzz
Hi Richard,
Thanks for the quick reply.

Idiot ? here: How can you tell the difference between a sku vs a document? Then, how do you select the correct transformation to render (I understand how to create transformations), I just don't know how to pick one to render.

Thanks!

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 2/7/2014 2:14:09 AM
   
RE:Search Results of Products vs Documentszzzzz
Hi,

Thank you for your message?

In your macro in C# code you can e.g. check the DocumentSKUName column. It will be empty for non-SKU or filled with some name in case it is representing the SKU. So you can test its length. Your macro could return 0 or 1 based on if the document represents SKU.

Then in the transformation you might want to use conditions like:
<%# IfCompare(1, 2, "The values are different", "The values are equal") %>

Kind regards,
Richard Sustek

User avatar
Member
Member
sammy - 2/13/2014 6:05:31 AM
   
RE:Search Results of Products vs Documentszzzzz
So, I found the place in the code (SmartSearch/SearchResults.ascx.cs) where the DataSet of the result is being returned. I see the DocumentId is being stored in the 1st column (documentId;nodeId), so, I can parse this out.

I'm drawing a blank on how to get to the document properties.

Basically, i'm thinking I should just extend the DataSet and add a column to the DataTable called ImgSrc (or whatever), and I want to populate it with the prouduct image url.

then, in my transformation, I can just call <img src=<%#Eval("ImgSrc") %>

Make sense?

I'm drawing a blank on how to access the product image from the DocumentId value, in my C# code.

Any quick suggestions to point me in the right direction?

Thanks!

User avatar
Member
Member
sammy - 2/17/2014 3:36:45 PM
   
RE:Search Results of Products vs Documentszzzzz
fyi..in case anyone else ever runs into this, i just ended up modifying the SmartSearch user control, from codebehind.

I would just call GetSearchValue(...), to get the values I wanted, and I built the formatted output in a StringBuilder, and then just wrote it to an asp:Literal control