IBM FileNet P8, Version 5.2.1            

Invoking a Custom Search Function

The following Java™ and C# examples show how to start a custom search function that converts a Date value to a Calendar value.

The function, DateConversionFunctionHandler, is specified in the selection list of the SearchSQL object. A SearchScope object is created and its fetchRows method called. For each row returned by the search, the server calls the custom search function. The function returns the converted value, which is then printed along with other properties in the search select list.

Java Example

// Create a SearchSQL instance and build the SQL statement.
SearchSQL sqlObject = new SearchSQL();

// In the in the select list, specify the custom search function to evaluate the DateCreated property.
// Because "Month" is passed as a parameter to the function, the function will return the current month and year. 
// For more information, see Implementing a Search Function Handler.
sqlObject.setSelectList("d.DocumentTitle, d.Id, SCF::DateConversionFunctionHandler(DateCreated, 'Month') as MonthYear");

sqlObject.setFromClauseInitialValue("Document", "d", false); 

// Print the SQL statement to be invoked.  
System.out.println("SQL: " + sqlObject.toString()); 

// Create a SearchScope instance. (Assumes you have the object store object.)
SearchScope search = new SearchScope(os);

// To execute searches calling custom functions, the fetchRows method must be used.
RepositoryRowSet myRows = search.fetchRows(sqlObject, null, null, null);

// Iterate the collection of rows and print selected properties.
// The MonthYear property reflects the value returned by the DateConversionFunctionHandler function.
int rowCount = 0;
Iterator iter = myRows.iterator();
while (iter.hasNext()) 
{
   RepositoryRow row = (RepositoryRow) iter.next();
   String docTitle = row.getProperties().get("DocumentTitle").getStringValue();
   Id docId = row.getProperties().get("Id").getIdValue();
   String MonthYear = row.getProperties().get("MonthYear").getStringValue();
   rowCount++;

   System.out.print("row " + rowCount + ":");
   System.out.print(" Id=" + docId.toString());
   if (docTitle != null) System.out.print(" DocumentTitle=" + docTitle);
   System.out.print(" Date last modified=" + MonthYear + "\n");
}

C# Example

// Create a SearchSQL instance and build the SQL statement.
 SearchSQL sqlObject = new SearchSQL();

// In the in the select list, specify the custom search function to evaluate the DateCreated property.
// Because "Month" is passed as a parameter to the function, the function will return the current month and year. 
// For more information, see Implementing a Search Function Handler.
sqlObject.SetSelectList("d.DocumentTitle, d.Id, SCF::DateConversionFunctionHandler(DateCreated, 'Year') as MonthYear");

sqlObject.SetFromClauseInitialValue("Document", "d", false);  

// Print the SQL statement to be invoked.  
System.Console.WriteLine("SQL: " + sqlObject.ToString()); 

// Create a SearchScope instance. (Assumes you have the object store object.)
SearchScope search = new SearchScope(os);

// To execute searches calling custom functions, the FetchRows method must be used.
IRepositoryRowSet myRows = search.FetchRows(sqlObject, null, null, null);

// Iterate the collection of rows and print selected properties.
// The MonthYear property reflects the value returned by the DateConversionFunctionHandler function.
int rowCount = 0;
foreach (IRepositoryRow row in myRows)
{
   string docTitle = row.Properties.GetProperty("DocumentTitle").GetStringValue();
   Id docId = row.Properties.GetProperty("Id").GetIdValue();
   String MonthYear = row.Properties.GetProperty("MonthYear").GetStringValue();
   rowCount++;

   System.Console.Write("row " + rowCount + ":");
   System.Console.Write(" Id=" + docId.ToString());
   if (docTitle != null) System.Console.Write(" DocumentTitle=" + docTitle);
   System.Console.Write(" Date last modified=" + MonthYear + "\n");
 } 


Last updated: October 2015
customSearchFunctions_snip3.htm

© Copyright IBM Corporation 2015.