IBM FileNet P8, Version 5.2.1            

Defining a Background Search

The following Java™ and C# code examples demonstrate how to define a background search by creating a subclass of the CmBackgroundSearch interface and creating a custom property.
Each code example performs the following steps:
  1. Create a CmBackgroundSearch subclass definition.
  2. Set the default value of the SearchExpression property definition of the CmBackgroundSearch subclass definition to the SQL search expression.
  3. Set the required class of the SearchResults property definition to the CmAbstractSearchResult subclass that was previously defined.
  4. Define a property template for that parameter that is included in the search expression.
  5. Use the new property template to add a custom property definition to the CmBackgroundSearch subclass definition.

Java Example

// Fetch CmBackgroundSearch class definition.
ClassDefinition objClassDefBkSearch = Factory.ClassDefinition.fetchInstance(objObjectStore, GuidConstants.Class_CmBackgroundSearch, null);

// Create a subclass of the CmBackgroundSearch class.
ClassDefinition objClassDefBkSearchSub = objClassDefBkSearch.createSubclass();

// Define locale for subclass.
LocalizedString objLocStrSC = Factory.LocalizedString.createInstance();
objLocStrSC.set_LocalizedText("CmBackgroundSearch Subclass 1");
objLocStrSC.set_LocaleName(objObjectStore.get_LocaleName());

// Set display name for subclass.
objClassDefBkSearchSub.set_DisplayNames(Factory.LocalizedString.createList());
objClassDefBkSearchSub.get_DisplayNames().add(objLocStrSC);

// Set symbolic name for subclass.
objClassDefBkSearchSub.set_SymbolicName("BackgroundSearchSub1");

// Get property definitions list.
PropertyDefinitionList objPropDefs = objClassDefBkSearchSub.get_PropertyDefinitions();

// Iterate property definitions until SearchExpression is found and set its PropertyDefaultString
// metadata property to the background search expression.
String strPropDefSymbolicName = null;
PropertyDefinitionString objPropDef = null;
for (int i=0; i < objPropDefs.size(); i++)
{
   strPropDefSymbolicName = ((PropertyDefinition) objPropDefs.get(i)).get_SymbolicName();
   if (strPropDefSymbolicName.equalsIgnoreCase("SearchExpression"))
   {
      objPropDef = (PropertyDefinitionString) objPropDefs.get(i);
      Property prop = objPropDef.getProperties().get("PropertyDefaultString");
      prop.setObjectValue("SELECT DocumentTitle FROM Document1 WHERE DateCreated > @StartDate Parameter@");
   }
}

// Fetch CmAbstractSearchResult subclass definition created in previous example.
ClassDefinition objClassDefSearchResultSub = Factory.ClassDefinition.fetchInstance(objObjectStore, "SearchResultSubclass1", null);

// Iterate property definitions until SearchResults is found and set its RequiredClassId
// metadata property to the CmAbstractSearchResult subclass that was previously defined.
strPropDefSymbolicName = null;
objPropDef = null;
for (int i=0; i < objPropDefs.size(); i++)
{
   strPropDefSymbolicName = ((PropertyDefinition) objPropDefs.get(i)).get_SymbolicName();
   if (strPropDefSymbolicName.equalsIgnoreCase("SearchResults"))
   {
      objPropDef = (PropertyDefinitionString) objPropDefs.get(i);
      Property prop = objPropDef.getProperties().get("RequiredClassId");
      prop.setObjectValue(objClassDefSearchResultSub.get_Id());
   }
}

// Create property template for a DateTime custom property to use for the search parameter named StartDate.
String strTemplateName = "StartDate";
PropertyTemplateDateTime objPropTemplate = Factory.PropertyTemplateDateTime.createInstance(objObjectStore);

// Set cardinality of properties that will be created from the property template.
objPropTemplate.set_Cardinality(Cardinality.SINGLE);

// Define locale for template.
LocalizedString objLocStrPT = Factory.LocalizedString.createInstance();
objLocStrPT.set_LocalizedText(strTemplateName);
objLocStrPT.set_LocaleName(objObjectStore.get_LocaleName());

// Set template display name.
objPropTemplate.set_DisplayNames(Factory.LocalizedString.createList());
objPropTemplate.get_DisplayNames().add(objLocStrPT);

// Save new property template to the server.
objPropTemplate.save(RefreshMode.REFRESH);

// Create property definition from property template.
PropertyDefinitionDateTime objPropDefDT = (PropertyDefinitionDateTime) objPropTemplate.createClassProperty();

// Create custom property by adding the new property definition to the CmBackgroundSearch subclass definition.
objPropDefs.add(objPropDefDT);
objClassDefBkSearchSub.save(RefreshMode.REFRESH);

C# Example

// Fetch CmBackgroundSearch class definition.
IClassDefinition objClassDefBkSearch = Factory.ClassDefinition.FetchInstance(objObjectStore, GuidConstants.Class_CmBackgroundSearch, null);

// Create a subclass of the CmBackgroundSearch class.
IClassDefinition objClassDefBkSearchSub = objClassDefBkSearch.CreateSubclass();

// Define locale for subclass.
ILocalizedString objLocStrSC = Factory.LocalizedString.CreateInstance();
objLocStrSC.LocalizedText = "CmBackgroundSearch Subclass 1";
objLocStrSC.LocaleName = objObjectStore.LocaleName;

// Set display name for subclass.
objClassDefBkSearchSub.DisplayNames = Factory.LocalizedString.CreateList();
objClassDefBkSearchSub.DisplayNames.Add(objLocStrSC);

// Set symbolic name for subclass.
objClassDefBkSearchSub.SymbolicName = "BackgroundSearchSub1";

// Get property definitions list.
IPropertyDefinitionList objPropDefs = objClassDefBkSearchSub.PropertyDefinitions;

// Iterate property definitions until SearchExpression is found and set its PropertyDefaultString
// metadata property to the background search expression.
String strPropDefSymbolicName = null;
foreach (IPropertyDefinitionString objPropDef in objPropDefs)
{
   strPropDefSymbolicName = objPropDef.SymbolicName;
   if (strPropDefSymbolicName.Equals("SearchExpression"))
   {
      IProperty prop = objPropDef.Properties.GetProperty("PropertyDefaultString");
      prop.SetObjectValue("SELECT DocumentTitle FROM Document1 WHERE DateCreated > @StartDate Parameter@");
   }
}

// Fetch CmAbstractSearchResult subclass definition created in previous example.
IClassDefinition objClassDefSearchResultSub = Factory.ClassDefinition.FetchInstance(objObjectStore, "SearchResultSubclass1", null);

// Iterate property definitions until SearchResults is found and set its RequiredClassId
// metadata property to the CmAbstractSearchResult subclass that was previously defined.
strPropDefSymbolicName = null;
foreach (IPropertyDefinitionString objPropDef in objPropDefs)
{
   strPropDefSymbolicName = objPropDef.SymbolicName;
   if (strPropDefSymbolicName.Equals("SearchResults"))
   {
      IProperty prop = objPropDef.Properties.GetProperty("RequiredClassId");
      prop.SetObjectValue(objClassDefSearchResultSub.Id);
   }
}
// Create property template for a DateTime custom property to use for the search parameter named StartDate.
String strTemplateName = "StartDate";
IPropertyTemplateDateTime objPropTemplate = Factory.PropertyTemplateDateTime.CreateInstance(objObjectStore);

// Set cardinality of properties that will be created from the property template.
objPropTemplate.Cardinality = Cardinality.SINGLE;

// Define locale for template.
ILocalizedString objLocStrPT = Factory.LocalizedString.CreateInstance();
objLocStrPT.LocalizedText = strTemplateName;
objLocStrPT.LocaleName = objObjectStore.LocaleName;

// Set template display name.
objPropTemplate.DisplayNames = Factory.LocalizedString.CreateList();
objPropTemplate.DisplayNames.Add(objLocStrPT);

// Save new property template to the server.
objPropTemplate.Save(RefreshMode.REFRESH);

// Create property definition from property template.
IPropertyDefinitionDateTime objPropDefDT = (IPropertyDefinitionDateTime) objPropTemplate.CreateClassProperty();

// Create custom property by adding the new property definition to the CmBackgroundSearch subclass definition.
objPropDefs.Add(objPropDefDT);
objClassDefBkSearchSub.Save(RefreshMode.REFRESH);


Last updated: October 2015
backgroundsearch_snip2.htm

© Copyright IBM Corporation 2015.