Wednesday, 24 October 2012

Adding search highlighting to Notes documents

As part of a recent upgrade to our FT Search Manager product, we added a workaround/hack to offer (optional) search highlighting to Notes Mail documents.

For quite some time, this functionality has been 'available' in standard Notes Full Text searches, although it seems pretty hit and miss, and usually doesn't work with MIME content. As for the Agent property ''Store highlights in document", we've never found a way to use it (has anyone?)

So to add our own version, we used a Javascript handler on the result document to allow the search result HTML to call a LotusScript function. 

That function firstly backs up the target document, then converts MIME content to Rich Text, then parses the Rich Text using standard NotesRichTextNavigator, Range and Style techniques, adding word highlighting. It then saves the document and opens it, navigating to the first instance of a search phrase. Straight after loading the document, the code restores the original content of the document from the backup.

Hence the document loads with search results highlighted, but if you Reply With History or Forward (or re-open the document from mail), it uses the original document, as normal.

This function is only applied to mail search results, because;
a) mail doesn't generally get modified after delivery.        
b) there is limited chance of conflicts due to other users editing the document at the same time.
c) unread marks don't change.



This makes searching a lot more efficient, because you don't need to read the entire document looking for your target data, and you can use Ctrl-G to quickly move to the next instance of the search phrase.

For example, a search for 'ibm +partner*' might show a result like this;



Opening the result will display all the search phrases highlighted, and also scroll to the first match found, no matter it's location in the document;



The downsides;

1. If you edit/save a document opened from the search results, you'll be prompted with a save conflict.
2. Editing the document means the LastModified/LastAccessed properties change, which may affect archiving and replication. 

It's a hack - but it's optional, and a tradeoff between providing a more useful search experience, and the two downsides mentioned above.