Searching mail and archives together

I am in the process of making what you are about to read an OpenNTF contribution but in the meantime I wanted to get some feed back on what I have come up with so far.  I wanted to extend the Lotus Notes client search with a Java plug-in that can be used in any version of Lotus Notes 8.x.  The first attempt here will really be to satisfy a customers direct need – which is basically search mail and any database stored in the local data directory under the “archives” folder.  We of course will make this configurable with a preference page and Eclipse preferences – which can then be controlled by an administrator through policies.

Search can be extended in a couple of places.  You can add your engine to the global search bar:

And the search option can show up in the right click menu when text is selected:

Continuing on, here is what I created and I figured I would just post some of the code here to give people a feel for how easy this really was.  I will go into detail about the search extension points in a later post; but what I really wanted to communicate here is I used basic back-end Java classes to accomplish this and I essentially relied on the Database Java object to do all of the search types.  The first thing I had to do was collect the results from the mail database and then iterate through all of the databases under the “archives” folder.  I gave the end user five different options for how to search, I started with Full Text but that can be very slow if your files are not indexed and then I added several other mechanisms:

  • Full Text
  • Body Field
  • Subject Field
  • Body and Subject Fields
  • Body and From Fields

As shown on the right, these options then show in the search page for the user to select how the database should be searched.

The main code is pretty simple, as I iterate through all databases I just pass the database and SearchQuery object into this private method and call the appropriate Search method on the Database object with the corresponding string or formula.  You can get an idea of it just by reading the code:

private DocumentCollection search(Database db, SearchQuery arg0) {
   try {
      if (arg0.getLocationID().equals("0"))  // Full Text
          return db.FTSearch(arg0.getText());
      else if (arg0.getLocationID().equals("1")) {  // Body Field
          return"@Contains(Body; "" + arg0.getText() + "")");
      } else if (arg0.getLocationID().equals("2")) {  // Subject Field
          return"@Contains(Subject; "" + arg0.getText() + "")");
      } else if (arg0.getLocationID().equals("3")) {  // Body and Subject fields
          return"@Contains(Body; "" + arg0.getText() + "") | @Contains(Subject; "" + arg0.getText() + "")");
      } else if (arg0.getLocationID().equals("4")) {  // Body and From fields
          return"@Contains(Body; "" + arg0.getText() + "") | @Contains(From; "" + arg0.getText() + "")");

   } catch (NotesException e) {

   return null;

You will notice I used the FTSearch method for the Full Text option and then I use the basic search method with a formula for the others.  After this method is called I then take all of the results and put them in a sorted collection by date – newer ones first.  This kind of stuff can also be controlled by preferences.

So, I have heard this request many times and now I ask, would an OpenNTF contribution using this approach be acceptable for the near term?

9 thoughts on “Searching mail and archives together

  1. Pingback: Searching mail and archives together » |

  2. Excellent. This will be really helpful. A few ideas for the setup part:
    1) [x] Create FTIndex if missing
    1a) [x] Include Journal in search
    2) Button: Select Archives from Archive setup
    3) Button: Scan for Archives (goes through the disk and looks for databases that are Archives – either by template name or the archive flag)
    4) [x] Search all databases (with a big fat warning)

    .. Can’t wait to play with it.
    🙂 stw

  3. This is sensational… we were only talking about wanting to release a search option for mail files and archives a few days ago. Can’t wait to get a hold of this!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.