Accessing all dbs in given folder on server

Hello All,

Iam trying to create an agent which searches for a key word on all mail dbs in data\mail path on a particular server.

Ex: Search “IBMserver” for the word “Notes” in every mail file in the folder \mail

Can anyone give me an Idea !!

Thank you in advance!!!

-NP

Subject: Accessing all dbs in given folder on server

You have 2 options:

  1. Easiest option, set up a multiple database full text index and search using the global search functionality (see the Administrators Help for information on this).

  2. Do some code. Below is a squirrely way of doing it, but you get the idea…

Sub Initialize

On Error Goto oops ' this will just skip a db (in case there is a problem searching it)

Dim sess As New NotesSession

Dim loopdb As NotesDatabase

Set loopdb = sess.CurrentDatabase ' getting the current database so we know what server we're running on

Dim dbdir As New NotesDbDirectory (loopdb.Server) ' get all databases for the current server

Dim coll As NotesDocumentCollection

Dim tempdoc As NotesDocument

Dim newsletter As NotesNewsletter



' get the search term

Dim srchTerm As String

srchTerm = Inputbox("What", "What are you searching for?")



' create an email to hold the results

Dim maildoc As New NotesDocument(loopdb)

maildoc.Form = "Memo"

maildoc.SendTo = sess.CommonUserName

maildoc.Subject = "Search of " & loopdb.Server & " mail databases for " & srchTerm

Dim rtitem As New NotesRichTextItem (maildoc, "Body")



' loop through the databases on the server

Set loopdb = dbdir.GetFirstDatabase(1247) ' getting databases only (not templates)

Do Until loopdb Is Nothing

	

	' check and see if the database we're on is in the mail directory

	If Instr(loopdb.FilePath, "mail\") > 0 Then

		Print "on " & loopdb.Title

		

		' have to open it to search (dbdir methods don't open the database when they get it)

		loopdb.Open "",""

		

		' do a search of the database (assuming the dbs have a ft index and you have access to the database)

		Set coll = loopdb.FTSearch(srchTerm, 0)

		

		' if there is a collection, grab its results

		If coll.Count > 0 Then

			

			' turn the collection into a newsletter document

			Set newsletter = New NotesNewsletter(coll)

			Set tempdoc = newsletter.FormatMsgWithDoclinks(loopdb)

			

			' pop this newsletter document into our email

			tempdoc.RenderToRTItem rtitem

			

			rtitem.AddNewLine 2

		End If 'end checking to see if we have results

		

	End If

resumehere:

	' keep looping through databases

	Set loopdb = dbdir.GetNextDatabase

Loop



' go ahead and send the email

maildoc.Send False

Exit Sub

oops:

rtitem.AppendText "PROBLEM WITH: " & loopdb.Title

rtitem.AddNewLine 1

Resume resumehere

End Sub

Subject: RE: Accessing all dbs in given folder on server

Hello Jeanne,

Thanks for your valuable information.

I have developed almost the same, but failed to hold the server name and the filepath. Moreover Iam not using newsletter.

I will defenetely try this.

Does this FTsearch work for multiple keyword search ?! I would be great if you could give me a hint on this.

Thank you vey much for your great work.

-NP

Subject: RE: Accessing all dbs in given folder on server

Try it out, the agent code I gave you functions as coded if you put it in a database on the server you are searching (I made a minor tweak, so if you copied it already copy it again).

Then, start mucking around. For the FTSearch, it will do a search same as whatever you would type in the search bar in a notes client. So, you could put in “apples, oranges” in the input box and it would function same as if you did it through the client full text search. You can get as complicated as you need to same as in client, i.e. “(apples AND oranges) NOT bananas”, or “fruit, a*”. Just play around with typing different stuff in the input box.

Lastly, I used a newsletter simply because it handily provides links to the documents. You can certainly use some other method, I’ve also done it by looping through the collection and writing info about the document on each line. Whatever suits you.

Subject: RE: Accessing all dbs in given folder on server

Jeanne,

Will do some work around and test it.

Thanks again for your quick and great response.

-NP

Subject: Accessing all dbs in given folder on server

Your big problem is going to be getting each database, since presumably you don’t want to hard code that.

You can walk the collection of databases using the NotesDbDirectory.GetFirstDatabase command.

Sub Initialize

Dim dbdir As New NotesDbDirectory(“ServerName”)

Dim db As NotesDatabase

Set db = dbdir.GetFirstDatabase(DATABASE)

While Not (db Is Nothing)

’ Check if db.path contains your foldername.

’ Do your search thing here.

Set db = dbdir.GetNextDatabase

Wend

End Sub

Subject: RE: Accessing all dbs in given folder on server

Hello Brian,

Thanks for your quick response.

This is a manual agent.

The thing is, i need to run this agent only on mail dbs(which usually resides@ domino\data\mail), not on all dbs on the server.

I can change the server name, if I want to run it on other server.

So, any ideas to get work only mail dbs.

Thanks,

-NP

Subject: RE: Accessing all dbs in given folder on server

Well, that was the idea behind the ‘Check if path contains your foldername’ comment.

Yes, it would look at all the DBs, but you could act only on DBs that have ‘mail’ in the filepath property.

Subject: RE: Accessing all dbs in given folder on server

When you get the handle to the notesdatabase, check its template name. There’s a property on notesdatabase for that.

Subject: RE: Accessing all dbs in given folder on server

Oooo, that’s smarter.