Help > Indexes > Indexing Rules > Scripting Rules > Metadata Injection

Metadata Injection

A metadata provider is used to inject external metadata about a document into the indexing process.

This is especially useful in Content or Document Management Systems where information about a document is stored external to the document, usually in a database.

Metadata Providers allow you to participate in the indexing process by providing the metadata for each document as it is indexed. This metadata is then indexed as part of the document, and can be included in your searches. If metadata caching is enabled in the index, you can gain quick and easy access to the metadata, this is of particular use for presentation in result lists.

To create a metadata injection rule script, you need to implement some of the functions below.

Sub GetMetadata(Request, Response)

ScanFiles provides a simply method to scan all your files in one function, it is only recommended for small datasets.

Parameters

Request - contains information about the document whose metadata is being requested, properties include:

Request.Filename returns the filename of the document being requested (as return from ScanFirst/ScanNext).
Request.IndexPath returns the path to the index being updated.
Request.Properties returns a collection of NTFS file system properties (Windows only).
Request.Script returns the name of the script currently executing.
Request.Size returns the size of the file on disk, if available.
Request.TimeStamp returns the timestamp on disk, if available.

Response - populate the response object with the metadata for the document.  Response properties/methods are:

Response.Add(Name, Value) Adds the name and value specified to the metadata collection for this document.
Response.AddList(List) Adds a list of items to the metadata collection for this document. List can be either ADO recordsets or lists returned from Perceptive Enterprise Search objects.
Response.Count Returns the number of items currently in the metadata collection for this document.
Response.Item(Index) Returns the value at the given name or index.
Response.Key(Index) Returns the field name for the item at the given index.
Response.Timestamp [Optional] The timestamp that is used to represent the date that the metadata was generated. This timestamp is checked during index to detected if the metadata has been changed.

Example
' This sample is designed for reference only.  If handles parsing a Dublin core
' rdf file, adding the meta data to each document for indexing.  The Dublin core
' rdf details can be found at the following
' http://dublincore.org/documents/dcmes-xml/index.shtml

' NOTE: This sample will not function without modification

function RequestRDF(Request)
  dim XMLDocument: set XMLDocument = Server.CreateObject("MSXML2.DOMDocument")
  ' NOTE: this method needs to be modified to request the rdf file from
  ' a server.  You could, for example, call XMLDocument.Open and pass
  ' a url from which the file can be downloaded.

  XMLDocument.ResolveExternals = false
  XMLDocument.Async = false
  XMLDocument.ValidateOnParse = false
  XMLDocument.Load Request.IndexPath & "\sample.xml"
  if XMLDocument.ParseError.errorCode = 0 then
    set RequestRDF = XMLDocument
  else
    set RequestRDF = Nothing
  end if
end function

sub GetMetaData(Request, Response)
  dim XML: set XML = RequestRDF(Request)
  if Not (XML is Nothing) then
    dim NodeMetaData, NodeDescription
    set NodeDescription = XML.DocumentElement.selectSingleNode("rdf:Description")
    set NodeMetaData = NodeDescription.FirstChild
    
    do while Not (NodeMetaData is Nothing)
      Response.Add NodeMetaData.NodeName, NodeMetaData.Text
    
      set NodeMetaData = NodeMetaData.NextSibling
    loop
  end if
end sub
Function GetMetadataTimestamp(Filename)

[Optional] Returns the last modified date of the metadata. Omit if unknown.

Parameters

Filename - The absolute path to a file

Returns

Return a timestamp of when the metadata last changed.