Genii Weblog

Regular expression keyword search in Midas 4

Mon 4 Feb 2008, 05:53 PM



by Ben Langhinrichs
I've been playing around some to figure out how to demonstrate the power of regular expression support in Midas 4.  One of less obvious uses is with the RegexKeywords method, which returns a comma delimited list of text that matches the regular expression.  I ran a simple agent against the 2007 Business Partner forum to find all the SPRs that are mentioned explicitly, and found 39, 30 of them unique.  It took slightly less than 5 seconds, even though there are 12392 documents).  Because it wasn't just a full text search, I got back an array of words that I could work with in an application.  The agent, all 20 lines of it, is below:

Sub Initialize
   Dim session As New NotesSession
   Dim db As NotesDatabase
   Dim collection As NotesDocumentCollection
   Dim doc As NotesDocument
   Dim keywords As String
   Dim all_keywords As String
   Dim rtitem As New GeniiRTItem
 
   Set db = session.CurrentDatabase
   Set collection = db.UnprocessedDocuments
   Set doc = collection.GetFirstDocument
   While Not (doc Is Nothing)
      Call rtitem.ConnectBackend(doc.Handle, "Body", True)
      keywords = rtitem.Everything.RegexKeywords("(SPR|spr)\s?#\s?:?([A-Z])([A-Z0-9]{9,9})", "$2$3")
      If keywords <> "" Then all_keywords = all_keywords + ","+keywords
      Set doc = collection.GetNextDocument(doc)
   Wend
   Messagebox "SPRs: "+Join(Arrayunique(Split(Right(all_keywords, Len(all_keywords)-1), ",")))
End Sub

Copyright © 2008 Genii Software Ltd.

What has been said:

No documents found