Content Level Scripts and Functions

 

Access and Use the Metadata Generation Scripts

The Metadata Generation Script is used to override automatic metadata generation for the selected content source.

This script is available only for the SQL Connector.

  1. On the Connectivity Hub page, click the content source name under Content. Click the Advanced tab.
  2. Scroll down to see Metadata Generation Script.

  3. Use the following HOST functions to generate the list of metadata properties that you require.

SQL Connector: Metadata Generation Parameters

Sub-type Function (HOST object) Input Parameters (Type) Return Type Description
Data Access GetDataSet()
DataSet Provides direct access to the items data set.



Specific to the Unstructured Field





AddStringMetadata()

ByVal name (String)


Adds the string metadata to the columns.
AddBooleanMetadata()

ByVal desc (String)

Adds the metadata as a Boolean value to the columns.
AddNumberMetadata()

ByVal scriptEnabled (Boolean)

Adds the metadata as a number value to the columns.
AddIntegerMetadata()

ByVal columns (String)

Adds the metadata as an integer value to the columns.
AddDateMetadata() ByVal metascript (String) Adds the metadata as a date value to the columns.

Add/Edit metadata to control values for the search index

When you specify the your custom metadata fields, you can write a VB.NET script to control the value that goes into the search index.

  1. Content Sources: Click the Content Sources link to see the Content Management page.

  2. Actions: Click Metadata for the content that you want to modify.


  3. The Content Metadata page appears.


  4. New: Click New to select the type of metadata that you will use.

  5. The Edit Metadata Property dialog appears.


  6. Click Define by script in the Value field to access the scripting pane.


  7. Pick column: Select a property in the drop-down.


  8. Click the Compile link above the field to validate the script.
  9. Click Save to save your settings and return to the Metadata page.

    1. The global variable HOST is accessible for any of your scripts

  10. You can choose to return a string for a single value or a string array for multiple values.

    1. See the following example to replace the value of the client code script:

Client Code script replacement
Copy
if HOST.GetStringValue("ClientCode") = "D" then return "Deleted" else return HOST.GetStringValue("ClientCode") end if


To learn more about the text and metadata functions, see the table below:

Subtype

Function (HOST object)

Input Parameters (Type) Return Type

Description

Data Access - All connectors

GetDataSet()

  DataSet

Provides direct access to the items dataset.

GetSubDataSet()

ByVal title (String) DataSet

Provides direct access to any additional datasets that might have been returned.

IsMulti()

ByVal colname (String) Boolean
  • If the column with the specified name is multi-valued, returns True.

  • Otherwise, returns False.

GetValue()

ByVal colname (String)

Object

  • Returns the native value for a column from the primary dataset's first row.

  • dbnull returns an empty string.

  • If the column does not exist, an exception is thrown.

GetValues()

ByVal colname (String) Object

Returns an array of values from the primary dataset's first row.

GetDSValues()

ByVal tableIndx (Integer)

ByVal colname (String)

Object

Returns the Object array result of the specified column in the specified table of the current dataset.

GetStringValues()

ByVal colname (String)

String

  • Returns an array of strings from the primary datasets first row.

  • If multiple fields are specified, more than one row is returned.

GetMultiColumnName()

ByVal colname (String) String

If the underlying data has linked multi-columns, the column names are returned.

GetDSStringValues()

ByVal tableIndx (Integer)

ByVal colname (String)

String

Returns the string array result of the specified column in the specified table of the current dataset.

GetStringValue()

ByVal colname (String) String
  • Returns a column's value as a string from the primary datasets first row.

  • dbnull returns an empty string.

  • If the column does not exist, an empty string is returned.

Connectivity Hub - All connectors

GetID()


String

Gets the primary ID of an item.

Connectivity Hub - All connectors

GetSubID()

  String

Gets the secondary ID of an item.

GetFolderID()

  String

Gets the folder IDs.

GetFolderSubId()

  String

Gets the folder sub IDs.

Specific to the Unstructured Field - SQL connector




AddFileToZip()

ByVal fullpath (String)

ByVal name (String)

Boolean

  • If the unstructured type is in .zip format, use this method to add these files.

    • Example:

      • Host.AddFileToZip("C:\Fileshare2\_feature4.pdf", "Feature.txt")

Note: To add more than one file to a zip archive, multiple entries, one file path per line, can be entered
  • Example:

    • Host.AddFileToZip("C:\Fileshare2\_feature1.pdf", "Feature1.txt")

    • Host.AddFileToZip("C:\Fileshare2\_feature2.pdf", "Feature2.txt")

    • Host.AddFileToZip("C:\Fileshare2\_feature3.pdf", "Feature3.txt")

Specific to the Unstructured Field - SQL connector

AddBlobToZip()

ByVal data() (byte)

ByVal name (String)

Boolean
  • If the unstructured type is .zip format, use this function to add blob data as files.

    • Dim filePath As String: "C:\path\to\your\file.txt"

    • Dim data As Byte(): System.IO.File.ReadAllBytes(filePath)

      • If Host.AddBlobToZip is your custom function to add a byte array to a zip file:

        • You can use the data variable like this:

          • Host.AddBlobToZip(data, "test.txt")

  • Example:

    • Below, the byte array is pushed into a .zip file of name "test.txt"

      Copy
      dim data as Byte();
      Host.AddBlobToZip(data, "test.txt")
Specific to the Unstructured Field - SQL connector

SetFileExtension()

ByVal extension (String)  

If the type is File System, overrides the file extension of the returned file path.

GetFileExtension()


String

Gets the file extension.

GetTempFilePath()

ByVal extension (String) String

Gets the temp file name. Use this method for copying the file for indexing purposes.

Filter Scripts and Functions

This script is available for most content sources and is used after you add and test your content.

  • For example, for WebService Content and Template Content.

  • You can also access this field when you select Exchange Mailbox Content > Private Mailboxes.

  • This script is used to filter individual items from a crawl. In other words, the script is applied after enumeration and before indexing.

This script must return a Boolean value.

If the script is active and returns the value True then the global variable HOST is accessible throughout the script:

  • True: The item is indexed.
  • False: The item is rejected.

Choose to return a string for a single value or to return a string array for multiple values.

See the following example:

Copy
if HOST.GetStringValue("ClientCode") = "D" then return false
return true

To choose from a list of the existing filter functions, see the table below:

WARNING! Make sure that your script returns the correct data type and watch for any arrays that might be returned.


Subtype Function (HOST object) Input Parameter (Type) Return Type Description

Data Access

GetDataSet()


DataSet Provides direct access to the item's dataset containing all of the metadata for the dataset.
GetSubDataSet() ByVal title (String) DataSet

Provides direct access to any additional datasets that might be returned.

GetValueFromDataset() DataSet, colname DataSet
  • Returns a column's value as object from a dataset

  • It expects the dataset as parameter

  • Use HOST.GetSubDataSet(<datasetName>) to obtain the dataset and then pass it as parameter, followed by the column name.

Example:

  • dim flag as object= HOST.GetValueFromDataset(HOST.GetSubDataSet("test"),"Sponsor_Collaborators")

GetStringValue()

ByVal colname (String)

String
  • Returns a column's value as a string from the first row of the primary dataset.

  • dbnull returns an empty string.

  • If the column does not exist, an exception is thrown.

GetValue()

ByVal colname (String) Object
  • Returns the native value of a column from the first row of the primary dataset.

  • dbnull returns an empty string.

  • If the column does not exist, an exception is thrown.

GetStringValues()

ByVal colname (String) String
  • Returns an array of strings from the first row of the primary dataset.

  • If this is a multi-field value, more than one row is returned.

GetValues()

ByVal colname (String) Object Returns an array of values from the first row of the primary dataset.

IsMulti()

ByVal colname (String) Boolean

If the underlying data has a linked multi-column, the column name is returned.

GetMultiColumnName()

ByVal colname (String) String

If the underlying data has a linked multi-column value, the column name is returned as a string value.

Connectivity Hub-Related

GetID()

 

String

Gets the primary ID of the item.

GetSubID()

  String Gets the secondary ID of the item.
GetFolderID()   String Gets the folder ID of the item.
GetFolderSubID()   String Gets the folder sub ID of the item.

Index Item Scripts and Functions

After you add and test content such as SQL Server Content, and WebService Content, you can write scripts to determine how items are indexed.

  1. Go to Content and click on a content type under Content.
  2. The <type of> Content page appears.
  3. Click the Item Definition tab and scroll down to see the required Item Extension box.



  4. Reference DS Columns with brackets(required): Make a selection such as SPW_EXTENSION.
  5. Advanced (required): Click the Advanced tab.
  6. Enter your script using the information provided above in this section.
  7. Compile: Click the Compile link above the field to validate and use your script.