M-Files API 23.11.13135.0
VaultObjectSearchOperations Object
Members 
Description
The VaultObjectSearchOperations class represents the available object search operations.
Public Methods
Gets a file based on the specified relative path.
Gets an object based on the specified relative path starting from the vault root.
Retrieves the facet values for the objects that satisfy the specified search conditions.
Retrieves the facet values for the objects that satisfy the search conditions extracted from the temporary search view specified by the path.
Gets the number of objects found with the specified search.
Gets objects by the path specified. This method can be used in offline mode.
Determines the search hits in the given text input.
Checks whether the specified relative path refers to an object in M-Files.
Searches the vault for objects that match the specified condition. Only the latest versions are searched for.
Searches for objects with the specified search conditions.
Searches the vault for objects that match the specified conditions.
Searches the vault for objects that match the given search conditions. The results are returned in XML form.
Searches the vault for objects that match the specified exported search string.
Searches the vault for objects that match the specified search string. The results are returned in XML form.
Searches the vault for objects that match the specified string.
Remarks
This method group interface can be accessed via the Vault object.
Example
' Initialize the API and connect to a vault.
Dim oVault As MFilesAPI.Vault
' ...

' Ignore errors here.
On Error Resume Next

' We are searching for the document with ID 123.
Dim iDocumentId As Integer
iDocumentId = 123

' Initialize an ObjID object for the search.
Dim oObjId As New MFilesAPI.ObjID
oObjId.SetIDs(MFilesAPI.MFBuiltInObjectType.MFBuiltInObjectTypeDocument, iDocumentId)

' Invoke the search operation.
Dim oResult As MFilesAPI.ObjectVersionAndProperties
oResult = oVault.ObjectOperations.GetLatestObjectVersionAndProperties(oObjId, True)

' Process the search result.
If oResult Is Nothing Then
    Call Console.WriteLine("Not found")
Else
    ' Resolve the value of the "Name or title" property.
    Dim oPropertyValue As MFilesAPI.PropertyValue
    oPropertyValue = oResult.Properties.SearchForProperty( _
        MFilesAPI.MFBuiltInPropertyDef.MFBuiltInPropertyDefNameOrTitle)

    ' Output the document name.
    Call Console.WriteLine("Title: " + oPropertyValue.TypedValue.DisplayValue)
End If

' Initialize the API and connect to a vault.
Dim oVault As MFilesAPI.Vault
' ...

' We are searching for objects with "estt" somewhere in the metadata or file content.
Dim szSearchText As String
szSearchText = "estt" ' This is case insensitive.

' Invoke the search operation.
Dim oObjectVersions As MFilesAPI.ObjectSearchResults = oVault.ObjectSearchOperations.SearchForObjectsByString( _
    szSearchText, False, _
    MFilesAPI.MFFullTextSearchFlags.MFFullTextSearchFlagsLookInMetaData Or _
    MFilesAPI.MFFullTextSearchFlags.MFFullTextSearchFlagsLookInFileData)

' Simply process the search results.
For Each oObjectVersion As MFilesAPI.ObjectVersion In oObjectVersions

    ' Resolve the object type.
    Dim oObjType As MFilesAPI.ObjType
    oObjType = oVault.ObjectTypeOperations.GetObjectType(oObjectVersion.ObjVer.Type)

    ' Output the result.
    Call Console.WriteLine("Title of " + oObjType.NameSingular + ": " + oObjectVersion.Title)

Next

' Initialize the API and connect to a vault.
Dim oVault As MFilesAPI.Vault
' ...

' We are searching for objects with "estt" somewhere in the metadata or file content.
Dim szSearchText As String
szSearchText = "estt" ' This is case insensitive.

' Create a search condition for the object name.
Dim oSearchCondition As MFilesAPI.SearchCondition = New MFilesAPI.SearchCondition
oSearchCondition.ConditionType = MFilesAPI.MFConditionType.MFConditionTypeContains
oSearchCondition.Expression.DataPropertyValuePropertyDef = MFilesAPI.MFBuiltInPropertyDef.MFBuiltInPropertyDefNameOrTitle
oSearchCondition.TypedValue.SetValue(MFilesAPI.MFDataType.MFDatatypeText, szSearchText)

' Invoke the search operation.
Dim oObjectVersions As MFilesAPI.ObjectSearchResults = oVault.ObjectSearchOperations.SearchForObjectsByCondition( _
        oSearchCondition, False)

' Simply process the search results.
For Each oObjectVersion As MFilesAPI.ObjectVersion In oObjectVersions

    ' Resolve the object type.
    Dim oObjType As MFilesAPI.ObjType
    oObjType = oVault.ObjectTypeOperations.GetObjectType(oObjectVersion.ObjVer.Type)

    ' Output the result.
    Call Console.WriteLine("Title of " + oObjType.NameSingular + ": " + oObjectVersion.Title)

Next

' Initialize the API and connect to a vault.
Dim oVault As MFilesAPI.Vault
' ...

' We are searching for the document with ID 123.
Dim iDocumentId As Integer
iDocumentId = 123

' Initialize an array of search conditions.
Dim oSearchConditions As MFilesAPI.SearchConditions = New MFilesAPI.SearchConditions

' Create a search condition for the object class (i.e., document in this case).
Dim oSearchCondition1 As MFilesAPI.SearchCondition = New MFilesAPI.SearchCondition
oSearchCondition1.ConditionType = MFilesAPI.MFConditionType.MFConditionTypeEqual
oSearchCondition1.Expression.SetStatusValueExpression( _
        MFilesAPI.MFStatusType.MFStatusTypeObjectTypeID)
oSearchCondition1.TypedValue.SetValue(MFilesAPI.MFDataType.MFDatatypeLookup, _
        MFilesAPI.MFBuiltInObjectType.MFBuiltInObjectTypeDocument)
oSearchConditions.Add(-1, oSearchCondition1)

' Create a search condition for the object ID.
Dim oSearchCondition2 As MFilesAPI.SearchCondition = New MFilesAPI.SearchCondition
oSearchCondition2.ConditionType = MFilesAPI.MFConditionType.MFConditionTypeEqual
oSearchCondition2.Expression.SetStatusValueExpression( _
        MFilesAPI.MFStatusType.MFStatusTypeObjectID)
oSearchCondition2.TypedValue.SetValue(MFilesAPI.MFDataType.MFDatatypeInteger, _
        iDocumentId)
oSearchConditions.Add(-1, oSearchCondition2)

' Invoke the search operation.
Dim oObjectVersions As MFilesAPI.ObjectSearchResults = oVault.ObjectSearchOperations.SearchForObjectsByConditions( _
        oSearchConditions, MFilesAPI.MFSearchFlags.MFSearchFlagNone, False)

' Simply process the search results.
For Each oObjectVersion As MFilesAPI.ObjectVersion In oObjectVersions

    Call Console.WriteLine("Title: " + oObjectVersion.Title)

Next

' Initialize the API and connect to a vault.
Dim oVault As MFilesAPI.Vault
' ...

' Create a search condition for deleted objects.
Dim oSearchCondition As MFilesAPI.SearchCondition = New MFilesAPI.SearchCondition

' Initialize an expression for the search condition.
Dim oExpression As New MFilesAPI.Expression
oExpression.DataStatusValueType = MFilesAPI.MFStatusType.MFStatusTypeDeleted
oExpression.DataStatusValueDataFunction = MFilesAPI.MFDataFunction.MFDataFunctionNoOp

' Initialize a boolean value.
Dim oTypedValue As New MFilesAPI.TypedValue
oTypedValue.SetValue(MFilesAPI.MFDataType.MFDatatypeBoolean, True)

' Initialize the search condition.
oSearchCondition.Set(oExpression, MFilesAPI.MFConditionType.MFConditionTypeEqual, oTypedValue)

' Invoke the search operation.
Dim oObjectVersions As MFilesAPI.ObjectSearchResults = oVault.ObjectSearchOperations.SearchForObjectsByCondition( _
        oSearchCondition, False)

' Simply process the search results. Note that in order to have any results here, the 
' user must have privileges to see the deleted objects within the vault.
For Each oObjectVersion As MFilesAPI.ObjectVersion In oObjectVersions

    ' Resolve the object type.
    Dim oObjType As MFilesAPI.ObjType
    oObjType = oVault.ObjectTypeOperations.GetObjectType(oObjectVersion.ObjVer.Type)

    ' Output the result.
    Call Console.WriteLine("Title of " + oObjType.NameSingular + ": " + oObjectVersion.Title)

Next

Sub SearchForObjectsByClass

    ' Initialize the API and connect to a vault.
    Dim oVault As MFilesAPI.Vault
    ' ...

    ' We are searching for objects from class "Sales Invoice" (ID is 89 in Sample Vault).
    Dim iClass As Integer
    iClass = 89 ' In this case, this identifies the class "Sales Invoice".

    ' You might also want to use the enclosed helper function to resolve the class ID from the class name:
    iClass = MF_FindClassID(oVault, "Sales Invoice")

    ' Create a search condition for the object class.
    Dim oSearchCondition As MFilesAPI.SearchCondition = New MFilesAPI.SearchCondition
    oSearchCondition.ConditionType = MFilesAPI.MFConditionType.MFConditionTypeEqual
    oSearchCondition.Expression.DataPropertyValuePropertyDef = MFilesAPI.MFBuiltInPropertyDef.MFBuiltInPropertyDefClass
    oSearchCondition.TypedValue.SetValue(MFilesAPI.MFDataType.MFDatatypeLookup, iClass)

    ' Invoke the search operation.
    Dim oObjectVersions As MFilesAPI.ObjectSearchResults = oVault.ObjectSearchOperations.SearchForObjectsByCondition( _
            oSearchCondition, False)

    ' Simply process the search results.
    For Each oObjectVersion As MFilesAPI.ObjectVersion In oObjectVersions

        ' Resolve the object type.
        Dim oObjType As MFilesAPI.ObjType
        oObjType = oVault.ObjectTypeOperations.GetObjectType(oObjectVersion.ObjVer.Type)

        ' Output the result.
        Call Console.WriteLine("Title of " + oObjType.NameSingular + ": " + oObjectVersion.Title)

    Next

End Sub

' Helper function to find the class ID by a class name.
Function MF_FindClassID( _
            ByRef oVault As MFilesAPI.Vault, _
            ByVal szClassName As String) As Integer

    ' Set the search conditions for the value list item.
    Dim oScValueListItem As New MFilesAPI.SearchCondition
    oScValueListItem.Expression.SetValueListItemExpression( _
        MFilesAPI.MFValueListItemPropertyDef.MFValueListItemPropertyDefName, _
        MFilesAPI.MFParentChildBehavior.MFParentChildBehaviorNone)
    oScValueListItem.ConditionType = MFilesAPI.MFConditionType.MFConditionTypeEqual
    oScValueListItem.TypedValue.SetValue(MFilesAPI.MFDataType.MFDatatypeText, szClassName)
    Dim arrSearchConditions As New MFilesAPI.SearchConditions
    arrSearchConditions.Add(-1, oScValueListItem)

    ' Search for the value list item.
    Dim results As MFilesAPI.ValueListItemSearchResults
    results = oVault.ValueListItemOperations.SearchForValueListItemsEx(MFilesAPI.MFBuiltInValueList.MFBuiltInValueListClasses, arrSearchConditions)
    If results.Count > 0 Then
        ' Found.
        MF_FindClassID = results(1).ID
    Else
        ' Not found.
        MF_FindClassID = -1
    End If
End Function

See Also

VaultObjectSearchOperations Members