Avoid using db.Search, instead change the selection formula of the view using LS and simply get all the documents in the view.
I was working on a database that required a lot of HTML reports to be generated. For this I had to use the search method of the database as I wanted a collection of documents that were between a user specified date range and had to match certain other user specified search parameters. My approach was to build the search formula and then do a db.Search to get the document collection. This was taking a long time as the search method searches the entire database and then returns a document collection. I was thinking if I could just dynamically change the selection formula of a view and then I would just have to loop through a smaller subset of documents. I elaborated on a piece of code provided by Dan Velasco of Dominopower.com to come up with this solution.
The following code goes in a Lotus Script agent.
Sub Initialize Dim session As New NotesSession Dim currDB As NotesDatabase Dim view As NotesView Dim doc As NotesDocument Dim entryColl As NotesViewEntryCollection Set currDB=session.CurrentDatabase Set view=currDB.GetView("vwLineItem") ' This is the view whos selection formula I want to change Set doc=currDB.GetDocumentByUNID(view.UniversalID) ' Change the selection formula Call doc.ReplaceItemValue("$Formula",|SELECT form="frmLineItem" & @Begins(InvoiceNumber;"A01")|) ' just doing a computewithform for safety sake ..not that i have had a prob without using it. Call doc.computewithform(False,False) Call doc.save(True,True) ' this just returned all the documents with the new selection formula Set entryColl=view.AllEntries Print entryColl.Count End Sub
One thing to note is that once the formula is changed the view only displays the entries in the view. It no longer displays any data. You can do a ctrl + A and select all the documents but you will not be able to see data in the view.