Access to SearchUI via SearchConditions

Build 1501 on 14/Nov/2017  This topic last edited on: 21/Mar/2016, at 18:34

In version 1.5 or newer you can manipulate the displayed search controls programmatically.

The ShellSearchConditions object is used by the client applications to generate the actual search conditions passed to the database. The ShellSearchConditions is bound to the search user interface so that changes made by the user will result in changes to the associated ShellSearchConditions and crucially, vice versa.

The ShellSearchConditions object is primarily a list of ShellSearchCondition objects, one for each of the user interface objects displayed. There will be a ShellSearchCondition object for each of the attributeUI elements in the searchObjectUI used to create the search controls.

The method GetCurrentSearchCriteria() has been added to MainAddIn that gets the current SearchCriteria and therefore the ShellSearchConditions associated with the current search.

Dim searchCriteria As SearchCriteria = GetCurrentSearchCriteria()

If searchCriteria IsNot Nothing Then

  Dim conditions As ShellSearchConditions = searchCriteria.SearchConditions

  If conditions isnot nothing Then

    ' set conditions here

  End If

End If

Once the ShellSearchConditions object is retrieved, it can be manipulated programmatically.

Check if a search field exists on the current form and what it contains

You can search the SearchConditions object for a particular search field (path):

dim found as ShellSearchCondition 

found = conditions.FindPath("[document.sectionRef]")

if found isnot nothing then

  MessageBox.Show(String.Format("Op = {0}, From = {1}, To = {2}, IdList = {3}",

    found.Op, found.FromValue, found.ToValue, found.IdList.ToString()))

end if

Click to toggle graphic size

Set an object type field value

Use the SetObjectTypes method to set the objecttypes control:

Dim searchCriteria As SearchCriteria = GetCurrentSearchCriteria()

If searchCriteria IsNot Nothing Then

  Dim conditions As ShellSearchConditions = searchCriteria.SearchConditions

  If conditions isnot nothing Then

    conditions.SetObjectTypes(OpCode.In, New String(){ "audio", "document", "image" })

  End If

End If

Click to toggle graphic size

If you specify an object type that is not covered by the control, it gets silently ignored.

Set a string field value

Use the SetString method to set the values of a text or string search:

conditions.SetString("[archiveObject.title]", OpCode.Containing, "title")

Set a date field value

Use the SetDate method to set the values for a date search:

conditions.SetDate("[archiveObject.publicationDate]", OpCode.EqualDate, Date.Now)

Set a Boolean field value

Use the SetBoolean method to set the values for Boolean searches. The value accepts true, false and nothing:

conditions.SetBoolean("[page.editionRef.isTemplate]", OpCode.Equal, True)

Set a full-text field value

Use SetFullText to set the values for the full text searches:

Click to toggle graphic size

Set a reference or multi-reference

For reference, multi-reference attribute types, you can select an item from the displayed list of items using SelectIds and the names of the items. This uses the values already loaded by the control to match the names given:

conditions.SelectIds("[archiveObject.publicationRef]", OpCode.In, New String() {"publicationname"})

For reference or multi-reference attribute types where the control has not all the id values, such as folder references, you can specify an attribute to match the given names in the database. The following uses the folder's path to match the given names:

settings.SetIds("[folderObject.folderRef]", OpCode.In, 

  Schema.Class.folderObj.pathAttrType(DataConnection.Instance.Schema),

  New String() {"/system/users/reporter"})

Similarly for calendars, use the calendar's path:

settings.SetIds("[calendarObject.calendarRef]", OpCode.In,

  Schema.Class.folderObj.pathAttrType(DataConnection.Instance.Schema), 

  New String() {"/system"})

Another method that uses the database to get the value is SetReference that will set any reference control referencing the given object type to the values given. This is useful for setting any folder reference or calendar reference to a given value:

conditions.SetReference(OpCode.In,

  TeraDP.GN4.Schema.Class.folderObj.pathAttrType(DataConnection.Instance.Schema), 

  New String() {"/system/users/alec"})

Or this example for a publication title:

conditions.SetReference(OpCode.In, 

  TeraDP.GN4.Schema.Class.titleObj.nameAttrType(DataConnection.Instance.Schema), 

  New String() {"default"})

Get information about current form fields

The following code displays some information about the ShellSearchConditions that might help in some circumstances:

Dim searchCriteria As SearchCriteria = GetCurrentSearchCriteria()

If searchCriteria IsNot Nothing Then

  Dim conditions As ShellSearchConditions = searchCriteria.SearchConditions

  If conditions isnot nothing Then

    dim paths as new Text.StringBuilder()

    paths.AppendFormat("{0}/{1} contains the following paths:" & vbcrlf, 

    searchCriteria.BaseQuery.Name, searchCriteria.SearchObjectUI.Name)

    for each condition as ShellSearchCondition in conditions.List

      paths.AppendLine(condition.Path)

    next

    MessageBox.Show(paths.ToString())

  End If

End If

Click to toggle graphic size