1
votes

I have around 50 lotus notes databases which I need to search through (including RTFs and attachments) based on a rather complicated query (for example: If customer = a or b or c or d or e ... or z & product = x or y) then == match; and a tag to (e.g. tag = found or not found)

However, I wasn't sure the best way to go about this and wanted to check three options.

  1. Using Lotus' 'Search in View' should, after indexing, search all the databases - however I am unsure if it will accept a long, complicated search query

  2. Coding an agent in Lotus SCRIPT to basically perform the search in 1. but this might be a way of getting it to accept a complicated query

  3. Using external software (e.g. X1 Professional Search) to search outside of Lotus Notes (however I am not sure if I will be able to tag the files if I identify them in windows explorer).

Edit: My idea is:

Sub Initialise
Dim session as New NotesSession
Dim db as NotesDatabase
Dim dc as NotesDocumentCollection
Dim doc as NotesDocument
Dim searcy_query$

'On current database
Set db = session.CurrentDatabase
'Force index of database
Call db.UpdateFTIndex(True)

'Construct QUERY
search_query = "(Customer1|Customer2) & (Product1|Product2)"
'Search
Set dc = db.FTSearch(query, 0)

If dc.Count=0 Then
                Msgbox "No matches!"
                Exit Sub
End If

‘Tag the matched documents with “Flag”
Call dc.StampAll("Flag","Active)")
End Sub

However, I am not sure if this will return all matches and also regarding @TRIM and @UPPER (where to put them into the query as I will be searching all fields and RTFs rather than specific ones)

2
For all the DB, is it always the same search ? if yes use a view with the complexe select formula. Do you need exact result or approx ? If exactitude is important, I do not recommand FT index what about creating a view in all db that will be use in lotuscript ? What is the size of each DB?Emmanuel Gleizer
Hi @Emmanuel Gleizer, many thanks for your reply. It will always be the same search however I will not be searching the same fields, for example I always want to search for Cust1 or Cust 3 and Product 1 but these may be in different fields of the database or even attachments (and have no fields at all), etc. I would need exact results - all files in the database that contain (anywhere) mentions of Cust1, etc. I have updated my original post with a sample of code that I had on mind. Thanks very much for your help again!Ilia Karmanov

2 Answers

2
votes

First of all: Searching more than one database at a time can of course be done "manually" by searching each individual database, collection the results and find a way to present the documents "somehow" (what will not be easy, as documents from different databases cannot be shown in "one" view - you would need to use "shadow- documents" or a web- approach (e.g. XPages))

BUT: Lotus Notes has a built-in function to do this, it is called "Domain Indexer". You can read more about how to setup "domain index" in this IBM Link or in your administration help.

Examples for using the domain- index for multi- database- searches can be found in catalog.nsf in the form "DomainQuery".

The search- string does not have a limit as far as I know, so that you can do very complex searches with this technique and it gives you all the matches.

If you search for a LotusScript- Solution, check the documentation for NotesDatabase.ftdomainsearch for example code like this (taken from developer help):

The following code, when placed in a button on a search form within a directory catalog database, searches the directory for the specified query string, and returns all results.

Sub Click(Source As Button)
    Dim s As New NotesSession
    Dim db As NotesDatabase
    Dim w As New NotesUIWorkspace
    Dim uidoc As NotesUIDocument
    Dim doc as NotesDocument
    Dim quer As String
    Dim srdoc as NotesDocument


    Set db=s.CurrentDatabase
    Set uidoc = w.currentdocument
    uidoc.refresh
    Set doc=uidoc.Document

    quer=doc.query(0)

    On Error Resume Next     
    If db.isopen Then
        If Err <> 0 Then
            Messagebox STR_DBOPEN_ERROR, 0 , STR_ERROR
            Err = 0
            Exit Sub
        End If

        Set srdoc = db.ftdomainsearch(quer, 0)

        If Err <> 0 Then
            Messagebox STR_NDF , 0 , STR_LOTUS_NOTES
            Err=0
            Exit Sub
        End If

        srdoc.Form="SearchResults"
        Call w.EditDocument(False, srdoc, True)
    End If
End Sub
1
votes

If you also intend to search Rich Text, the simplier way is Full Text Search, you got the point!

The syntax for your query is:

generic_text or ([_CreationDate]<07.10.2014 and ([CustomerFieldName]="Smith" or [CustomerFieldName]="Wesson"))

For formating the Result, I'ld suggest looking at:AppendDocLink for something like:

Dim session As New NotesSession
Dim db As New NotesDatabase("", "resu.nsf")
Dim newDoc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument

Set newDoc = New NotesDocument( db )
Set rtitem = New NotesRichTextItem( newDoc, "Body" )
'you have to loop on your 50 DBs
'Search =>from your code
Set dc = db.FTSearch(query, 0)
while not doc is nothing 
     Call rtitem.AppendDocLink( doc, db.Title )
     Call rtitem.AddTab( 1 )
     Call rtitem.AppendText( doc.FieldImportantInResult( 0 ) )
     Call rtitem.AddNewLine( 1 )
     Set doc = dc.GetNextDocument( doc )
Wend
newDoc.save true, true
'this part is not to add it you plane to run your search in background
Dim w As New NotesUIWorkspace
Call w.EditDocument(False, newDoc, True)