Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Document Type Properties -> Search fields View modes: 
User avatar
Member
Member
eagleag - 7/10/2011 3:45:12 AM
   
Document Type Properties -> Search fields
Hi,
anyone have an example how they used Custom search name?

This is what I'm trying to do ad I think this field might do it.

I have a Document Type which have a Field drop down that get info from sql query.
SELECTING from a custom table:
select ItemID, industryName
from career_industry


the document field store the ItemID in it and I have a custom function, in transformation, that takes ItemID and gets the associated industryName from custom table.

on site search (smart search), if I search for "Hi-Tech" (which is an industryName), the docuent doesnt come up becasue its only storing the ItemID.

HOw do I tell the search to make that connection?

thanks

User avatar
Member
Member
kentico_michal - 7/10/2011 5:04:44 AM
   
RE:Document Type Properties -> Search fields
Hello,

In order to achieve this, you will need to use the CustomDataHandler class and in particular, its OnGetContent method. In general, the custom handler (CustomDataHandler, CustomTreeNodeHandler etc.) gives you ability to execute custom code when some CMS event occurs. The events of CustomDataHandler are applied to all data items that are stored to the database and the OnGetContent is a method used by smart search. It's called every time the document (or custom table, forum, user) is indexed.

The first parameter usually contains TreeNode object (or CustomTableItem, ForumPostInfo, UserInfo object) and the second parameter contains text that gets indexed by Lucene.NET search ungine used in Kentico CMS smart search module. You can use this method to modify the text, e.g. add content of the industryName field from the custom table to it depending on the ItemID of the current TreeNode object that represents the current document.


public override string OnGetContent(object obj, string content)
{
CMS.TreeEngine.TreeNode node = obj as CMS.TreeEngine.TreeNode;
if (node != null)
{
int ItemID = CMS.GlobalHelper.ValidationHelper.GetInteger(node.GetValue("ItemID"), 0);
if (ItemID != 0)
{
string industryName;
// get the value of industryName based on the ItemID
content = content + " " + industryName;
}
}
}


If you want more information about the CustomDataHandler class and how to add it to your project, please visit following links:
Event handling overview, Data handler

API related to custom tables is available here:
API - getting custom tables, Kentico CMS API


Best reagards,
Michal Legen

User avatar
Member
Member
eagleag - 7/10/2011 9:46:55 AM
   
RE:Document Type Properties -> Search fields
Just want to make sure we are talking about smae this->

User image

ItemID (from cusotm table, an int) is stored in Industry field in docuemnt type.

This means an INT is stored in Industry (in docuemtn type).

When someone searches the site for the word Hi-Tech, any document that was created as a CAREER should appear in results.

How do I do this eventhough the STRING Hi-Tech isnt stored in the CAREER, only the ItemId (INT) is stored in CAREER?

User avatar
Member
Member
kentico_michal - 7/11/2011 1:35:42 AM
   
RE:Document Type Properties -> Search fields
Hello,

Yes, we are talking about the same thing. Let me put it in another way. The OnGetContent method accepts as an input parameter variable content:

public override string OnGetContent(
Object obj,
string content
)


The variable content contains all values that users can use to search for that particular document. So if you want to the document being searchable using the value of industryName field (even if it is not part of the document directly), you need to include the value of industryName field to the content variable just as I outlined in the code snippet posted above:

1. get the ItemID of the current document
2. if the ItemID is not null, get the industryName of the appropriate custom table record
3. content = content + " " + industryName;

I hope it makes more sense.

Best regards,
Michal Legen