Database lookup in specific columns
The following script sample shows how to access an internal database by searching values in specific columns. This could be
useful in case multiple columns contain similar data, or the data is ambiguous, as for example the first and the last name are
interchangeable such as
John Alexander
versus
Alexander John
.
FieldIDs can be used to define, which value to search in which column of the database. 0 means "search in all columns". Please be aware that the indexes are applied to only the subset of columns that you checked in the DB import dialog. So if you check only 5 out of 8 columns, you can index only 1 to 5. Also note that FieldIDs are only properly supported in Kofax TotalAgility 5.5 and higher. In earlier versions, the search happens always in all columns.
Dim Fields() As String
Dim FieldIDs() As Long
ReDim Fields(2)
ReDim FieldIDs(2)
Dim DB As CscDatabase
Dim DBResItems As CscDatabaseResItems
Dim arr() As String
Fields(0) = pXDoc.Fields(0).Text
Fields(1) = pXDoc.Fields(1).Text
Fields(2) = pXDoc.Fields(2).Text
FieldIDs(0) = 1
FieldIDs(1) = 0
FieldIDs(2) = 0
Set DB = Project.Databases.ItemByName("German")
Set DBResItems = DB.Search(Fields, FieldIDs, CscEvalMatchQuery, 5)
If DBResItems.Count > 0 Then
arr = DB.GetRecordData64(DBResItems(0).RecID64)
If MsgBox("Confidence: " + CStr(DBResItems(0).Score) + " Zip: " + arr(0) + " & City: " + arr(1) + _
"Street: " + arr(2) + vbCrLf + "Insert values?", vbYesNo, "Database lookup") = vbYes Then
pXDoc.Fields(0).Text = arr(0)
pXDoc.Fields(1).Text = arr(1)
pXDoc.Fields(2).Text = arr(2)
End If
End If
There are a few things to consider when you use a local fuzzy database in script. When you import the database into the project, you can define a few preprocessing settings, like additional delimiter characters, characters to ignore, and substitution pairs. When you use such a database in a regular Database Locator, the same preprocessing functions are applied to the document before searching its content in the database. However, this is not the case when you use the database directly in script. Instead of setting the fields array manually, set it using the following code.
- Code for additional delimiters
-
'Additional Delimiter chars are used to split the text into smaller fields. You need to split your search string 'by using the same characters: Dim i As Long Dim s as String s = QueryString 'Replace all delimiters by blank For i = 0 To Len(DB.AdditionalDelimiterChars)-1 s = Replace(s, Mid(DB.AdditionalDelimiterChars,i+1,1)," ") Next Fields = Split(s, " ")
- Code for ignore characters:
-
'Characters that are ignored during DB import need to be removed from the query Dim i As Long Dim s as String s = QueryString 'Replace all delimiters by blank For i = 0 To Len(DB.RemoveChars)-1 s = Replace(s, Mid(DB.RemoveChars,i+1,1)," ") Next
- Code for substitution pairs:
-
'Substitution pairs define which texts to be replaced by what. Apply that to your query string Dim i As Long Dim s as String s = QueryString For i = 0 To DB.SubstitutionPairCount-1 Dim value As String Dim substitute As String DB.GetSubstitutionPair(i,value,substitute) s = Replace(s,value,substitute) Next