Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Determine if Smart Search Result has (or is) an attachment View modes: 
User avatar
Member
Member
@davey_lad - 7/12/2013 5:58:14 AM
   
Determine if Smart Search Result has (or is) an attachment
Is there a common technique or transformation method than allows me to determine if a smart search result has an attachment or if the reason it appears in results is because of the attachment content ?

i.e. I'm looking to make a call within my smart search transformation in order to indicate whether there's a document attached (e.g. an icon) when the search results are displayed.

Similarly, I would like to be able to filter out the results i.e. "show only results with attachments". Anybody got an example of this ?

Cheers

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 7/12/2013 3:24:00 PM
   
RE:Determine if Smart Search Result has (or is) an attachment
I'd suggest creating a simple custom control and include it in your transformation. In your control create a few properties that take class name, node id, transformation name, display type and things like that to determine if that particular document has an attachment or not. What you want to do after that is up to you. Maybe have a repeater that displays all the document attachments or based on the display type, hide the repeater and show a label with a simple number of attachments.

Not sure if this is what you're looking for or not but maybe a start.

User avatar
Member
Member
@davey_lad - 7/15/2013 2:47:59 AM
   
RE:Determine if Smart Search Result has (or is) an attachment
Hi FroggEye,

I was hoping there was something a little more direct I could use.

I'm already displaying a list of search results, but the properties available within the transforamtion are different for a smart search result compared to a traditional document type.

I'll probably just fire off a call to a custom method in order to determine if there's an attachment. It's the filtering aspect that may be more difficult. I had hoped there was perhaps an "Attachment Count" property available.

User avatar
Kentico Support
Kentico Support
kentico_filipl - 7/15/2013 3:12:28 AM
   
RE:Determine if Smart Search Result has (or is) an attachment
Hi,

Document attachments are processed separately from documents and relevance (score) cannot be therefore applied. Relevance is a feature of Lucene.NET and only documents data is indexed by Lucene .NET, attachments are not. Attachments are stored in the database and they are searched separately with SQL full text search functionality (Developer's Guide - Searching attachments). When it comes to providing search results, Lucene.NET results and attachments results are merged and therefore we do not have any relevance value for attachments.

The following video might be worth checking out:
Smart Search in Kentico CMS 6

If you manage to make the content of your attachments to be a part of the index file, then you will have the relevance feature of Lucene.NET available. The video is presenting a solution on how to search in content of files with Lucene.NET support.

What you would need is to make sure that the content of your document attachments is stored in index file. After that, you will not need full text search functionality of SQL server, content of your attachments will be stored in index file and you will get relevance (score). However, it is not that easy. It will require customization of the module, some level of .NET programming skills, patience and knowledge of the CMS. It is not something that you can simply set up in your settings.

Best regards,
Filip Ligac

User avatar
Member
Member
@davey_lad - 7/15/2013 3:21:30 AM
   
RE:Determine if Smart Search Result has (or is) an attachment
Hi Filip,

Thanks for the reply however my issue isn't with "Relevance" as such, it's more a case of "how do you know" if the search result originates from an attachment search (SQL) or an indexed search. It seems at the presentation level all searches are equal in this respect and there is no disambiguation between the two.

Also, it's about how you would selectively filter results based upon whether they had attachments

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 7/15/2013 10:47:22 AM
   
RE:Determine if Smart Search Result has (or is) an attachment
@davey_lad wrote: I was hoping there was something a little more direct I could use.
Creating a custom control to do this work would be pretty direct IMHO. Not to mention allow your results to be displayed dynamic enough where you wouldn't need to make a code change, just let the control set the values.

Although if you wanted to create a custom method to take a class name, node, etc. That would work as well. It would also be the same method I'd use in creation of this custom control.

If you debug through the smart search results code and look at the dataset visualizer you will see the fields in the search result dataset. Within there you have everything you need in order to perform your custom methods/queries or display additional results.

User avatar
Member
Member
@davey_lad - 7/18/2013 3:11:11 AM
   
RE:Determine if Smart Search Result has (or is) an attachment
Just to close this off I thought I'd share the solution I actually settled on..

First, I should clarify that I'm using group attachments on the Form tab so these all get stored in CMS_Attachment table.. an odd side effect of this is the related document type table seems to get an additional field for this group but never actually gets used i.e. it's always null. So, on to my solution:

1. I created an additional field on my doc type(s) "HasAttachments" (boolean). This never gets shown on the Form. I configure this as a "Searchable" field so that it's available in search results.

2. I have created a couple of event handlers ObjectEvents.Delete.After and ObjectEvents.Insert.Before which monitor for attachments ("cms.attachment") being added to/removed from my document types. I update the "HasAttachments" field accordingly. i.e. on insert it will alwsy be set to true (unless it's true already), on delete it will get set to false only if there are no more attachments in the group.

3. This now gives me a field that I can now use directly in my SmartSearch transformation in order to indicate whether the result has an attachment e.g.
<li <%# If(GetSearchValue("HasAttachments"), "class=\"hasAttachment\"", null) %>>

4. It also allows me to easily configure a Smart Search filter to filter results based on whether they have attachements or not i.e.
;;All
+hasattachments;true;With attachments
+hasattachments;false;Without attachments

I've summarised all this for brevity but hopefully it's clear enough for anyone else to decipher although an understanding of smart search and filters are required.

I'm happy to consider better alternatives but this was pretty simple to implement and works very well.