Domino Code Fragment

Code Name*
Creating a Search Agent
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.18.224.38.3
Description*
Creating a Search Agent
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Where : Agent

Solution :

Sub Initialize
'-- For each Query document selected by the Agent :
'-- This script will perform searches of multiple Notes databases based on the criteria in the
'-- queryText field in the current document and return the results as a one newsletter response document
'-- per database to the original query document

'-- Get unprocessed document collection from Current Database
Dim Session As New NotesSession
Dim currentdb As NotesDatabase
Set currentdb = Session.CurrentDatabase

Dim unprocessed As NotesDocumentCollection
Set unprocessed = currentdb.unprocesseddocuments

'-- This array hold the names of the Notes DBs from which we search
Dim dbpath(2) As String
dbpath(0) = "PGN2\Newstand\news1.nsf"
dbpath(1) = "PGN2\Newstand\news2.nsf"
dbpath(2) = "PGN2\Newstand\news3.nsf"

'-- Iterate through collection
Dim doc As NotesDocument
Set doc = unprocessed.getfirstdocument

Do While Not (doc Is Nothing)


'-- Process Media Documents Only
If doc.form(0) = "Media Search" Then

'-- Get the search string from the document
Dim FTQuery As String
FTQuery = doc.QueryText(0)

'-- Search all databases (defined) by array
For i = 0 To 2

'-- Open the database and update the index
Dim db As New NotesDatabase("",dbpath(i))
Call db.UpdateFTIndex(True)

'-- Perform the Full Text Search, returning the results
Dim collection As NotesDocumentCollection
Set collection = db.FTSearch(FTQuery,0)

'-- If matches are found, create a newsletter object using the matching document collection.
If collection.count > 0 Then

'-- Create Newsletter object

Set newsletter = New NotesNewsletter(collection)

'-- SubjectItemName is the field from the news db which provides the newsletter subject values
newsletter.SubjectItemName = "Head"
newsletter.DoScore = False
newsletter.DoSubject = True

'-- Create Newsletter document
Dim Resultsdoc As NotesDocument
Set Resultsdoc = newsletter.FormatMsgWithDoclinks(currentdb)

'-- Make the Newsletter document a response to the query document
Call ResultsDoc.MakeResponse(doc)

'-- Set Form name and Title
ResultsDoc.Form = "Media Search Results"
ResultsDoc.Title = "Search Results : " & collection.count & " matches found."

'-- Save the newsletter document
Call ResultsDoc.save(True,True)

End If
Next i
End If

'-- Get next document
Set doc = unprocessed.getnextdocument(doc)

Loop

End Sub