Show language: C# VB.NET Both

Custom Data

Custom data, containing specific information about a document, can be assigned to a document at the indexing stage and then recalled during a search. The data's origin, type and relevance are determined by the developer and can be presented to the end user (as extra fields or an image for example) or processed to affect the search results in some way (such as result order).

Source Of Custom Data

The origin of the data is open to the developer, if for example the document represents an item from a database, then the data could be specially selected database columns (such as dates, ownership or other meta data). The data could also consist of the result of an analysis of the document, or data that was originally used in the creation of the document (such as product names, related page URLs or thumbnail images).

Types of Custom Data

The custom data is held as a string, however it can consist of simple or complex types (through the use of delimiters for example) and can be used to store any kind of data (from simple strings through to UUEncoded binary).


Custom date data used for sorting and additional user info.

Adding Custom Data To A Document

This can be achieved either through meta tags in HTML based documents, or through the Central Event System. The indexer will read the data and store it with the document record.

Meta-tags

By adding the following meta tag to a document

<meta name="Keyoti_Search_Custom_Data" content="..." />

The content attribute holds the custom data that should be stored with the document. Technically there is no limit to the length of the data, however large amounts of data (kilobytes) will make reading the document table slower, and thus affect most operations to some degree. If the document is dynamically generated then the custom data can be inserted at run-time, otherwise the data will be static.

Central Event System

By subscribing to the Action event and processing ActionName.ReadText. The associated ActionData.Data is of type DocumentText which has a property called MetaCustomData, which can be set to the data that should be stored. See the Central Event System section for more information on handling actions.

C#
private void CentralEventDispatcher_Action(object sender, Keyoti.SearchEngine.Events.ActionEventArgs e)

{

    if(e.ActionData.Name== ActionName.ReadText)

    {

        string documentUri = (sender as Document).Uri.AbsoluteUri;

        (e.ActionData.Data as DocumentText).MetaCustomData = "my custom data"; 


    } 

}
VB.NET
Private Sub CentralEventDispatcher_Action(ByVal sender As Object, ByVal e As Keyoti.SearchEngine.Events.ActionEventArgs)
        
		If (e.ActionData.Name = ActionName.ReadText) Then
        
			Dim documentUri As String = CType(sender,Document).Uri.AbsoluteUri
            
			CType(e.ActionData.Data,DocumentText).MetaCustomData = "my custom data"

		End If

	End Sub

In this example every document will have it's custom data set to the string "my custom data". The documentUri variable could be used to determine what custom data should be set for the document, for example the document's URI could be used to lookup data in a database, or find a related image.

PDF Meta Data

PDF file meta data can be accessed through the DocumentText.MetaData Hashtable. For example to set CustomData to the PDF creation date, use (e.ActionData.Data as DocumentText).MetaCustomData = (e.ActionData.Data as DocumentText).MetaData["CreateDate"], note however that meta data is not guaranteed to exist. Other keys in the meta data hashtable are CreateDate, CreatorTool, ModifyDate, Producer, Title, and Format.

Using CustomData in a search

Please see the how-to in the 'Searching an Index' section: ...use CustomData for date sorting