Writing Reusable VB.NET Functions
Overview
You can write custom VB.NET functions that can be reused in any connection or content definitions.
-
You can also use a script to create a public variable.
-
You can store your custom scripts, in one, but not both, of these libraries:
-
Common Script
-
Script
-
Common Script Library
- Use this library to store the System-wide scripts that you write.
- These scripts apply across the system.
- For example, use this type of function:
- To populate a managed property with a specific value to indicate that a document was crawled using the Connectivity Hub.
- A security function that is applicable to more than one security master connection (or at least applicable to more than one connection, in general) can be called from any connection.
Script Library
- Use this library to store the Content-wide scripts that you write.
- These scripts concatenate string from a specific library with an identifier string letting you know which content source your results are from.
Note: BA Insight default scripts that are included with the connectors cannot be stored in either of the libraries listed in this topic.
See the following topics for more information.
Write System-wide Functions into the Common Script Library
Procedure:
- Tools > Configuration: See the "Configuration Settings" page.
- Miscellaneous: Click to see the Miscellaneous page.
- Common Script Library:
- Enter your custom function, which uses any standard VB.NET function.
- The output of the script is determined by your final return statement.
- This output can be in the form of integer, DateTime, string, string array, or any other VB.NET type.
- Compile:
- Click Compile to validate your function.
- Perform this operation for each function that you add.
- Save: Click to add this function to the library.
Note: For information about the other settings on this page, go to How to Add a Custom Error Page.
Write Concatenation Scripts for a Specific Content Source into the Script Library
You write VB.NET functions, which can be used across your content, into the Script Library.
-
For example, you can write a string concatenation function that is specific to all of the metadata in the selected content source.
More specifically, you might have the NYC Documents content source with 50 metadata properties.
-
Some of these properties must be identified as coming from the NYC Documents.
-
To perform this identification operation, write a function that takes a string as input, adds
-NYC
to whatever string it receives from the source, and returns the new string. -
After you have compiled and validated this function, you can call this function from every metadata property in NYC Documents.
To access and use the Script Library, follow these steps:
- Go to Content > Content > <content source name> and click the Advanced tab.
- Script Library:
- Scroll down to and write your custom function, which uses any standard. VB.NET function, here.
- The output of the script is determined by your final return statement.
- This output can be in the form of integers, DateTime, string, string array, or any other VB.NET type.
- Compile:
- Click to validate your function.
- Perform this operation for each function that you add.
- Save: Click to add this function to the library.
Defining VBScript Function Variables
If you define a VBScript function, you must define variables.
-
These variables can be defined as function parameters or the variables can be declared as automatic variables, inside the function.
For example:
public
function doSomeThing(inval as string) as string
dim HOST As
SPWorks.Search.Common.ScriptHost
HOST.WriteTrace ("message")
end function
or
public
function doSomeThing(inval as string, ByVal HOST As
SPWorks.Search.Common.ScriptHost) as string
HOST.WriteTrace ("message")
end function