Domino Code Fragment

Code Name*
NotesView method FTSearch
Date*
04/29/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.18.221.187.121
Description*
Using the NotesView method FTSearch , documents can be located and added to a document collection.
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Note: The FTSearch method should work even if a database is not full text indexed. We have found this to be true for local databases, but not for databases on a server. In order for the function to work on databases on a server, the database must be full text indexed.
Files/Graphics attachments (if applicable): Code:
FTSearch uses the Full Text Index search engine to search all documents in a view or database for the string desired. The database does not have to be full text indexed for FTSearch to execute properly, however the search will take longer if it is not.
When FTSearch executes, it returns a subset of documents based on the search criteria. This subset of documents is called a NotesDocumentCollection. You can use the NotesDocumentCollection methods GetFirstDocument and GetNextDocument to traverse the documents in the collection, or get the number of documents in the collection using the Count method. To clear the result of the FTSearch, (removing the document collection) use the view.Clear method.

Click here to see the example.

Dim session As New NotesSession 'Declare session as a new Notes session
Dim db As NotesDatabase
'Declare db as a Notes Database
Dim view As NotesView
'Declare view as a Notes View
Dim doc As NotesDocument
'Declare doc as a Notes Document
Dim UpIndex As Integer
'Declare UpIndex as type integer
Dim NumDocs As Integer
'Declare NumDocs as type integer
Dim GotSubject As Variant
'Declare GotSubject as type variant
Set db = session.CurrentDatabase
'Set db to the current Notes database (open)
Set view = db.GetView("Beginning")
'Set view to a view called "Beginning"
If db.IsFTIndexed Then
'If the database is indexed, ask user if it should be updated
UpIndex = Messagebox("Update database full text index before searching for documents?",51,"Create Index?")
If UpIndex = 6 Then
Call db.UpdateFTIndex(True)
'Use the database method UpdateFTIndex to update the index
End If
End If
NumDocs = view.FTSearch("""Document""", 0)
'Search for any documents containing the word Document
If numDocs <> 0 Then
'Checks to see if any docs were found and added to the NotesDocumentCollection
Set doc = view.GetFirstDocument()
'Get the first document in the NotesDocumentCollection
While Not(doc Is Nothing)
'Loop until all the documents have been retrieved
GotSubject = doc.ChapterTitletxt
'GotSubject retrieves the contents of the text item ChapterTitletxt
Messagebox Cstr(GotSubject(0))
'Display the contents. Notice GotSubject is now a one element array
Set doc = view.GetNextDocument(doc)
'Get the next document in the NotesDocumentCollection
Wend
view.Clear 'Clear the results of the FTSearch
End If