follow up to: sorted ftsearch results in XPages (with code!)
Julian Buss, January 26th, 2010
Tags:  Development 
This is a follow up to my previous post about sorted ftsearch results, and it is inspired by ideas Tommy Valand wrote about.

The problem with my previous approach was, that I could not cache the result. So while using a pager, or on re-sorting, all the expensive work (doing the ftsearch, getting all NotesViewEntries) was done over and over again. I could not cache the result, since the TreeMap contained Notes objects which are recyled after the page is delivered to the browser.

Now I created a "fake" NotesViewEntry object which only stored Java objects. So after doing the ftsearch, I create one fake NotesViewEntry for each real NotesViewEntry, and store that in the TreeMap. Then I get the sorted list of values (as Array) out of the TreeMap and store that into the viewScope.

On pagination I simply return that cached Array, and on re-sort I use that Array to re-sort the values. The ftsearch and looping over the NotesViewEntries is done only exactly once during the lifetime of the page.

I didn't implement the descending sort order yet, but that shouldn't be hard since the TreeMap.values() collection can be reversed by one single method call.

So, here is my current code as RTF download (sorry for that, but when I tried to put the code in this blog post, I reached the size limit of blog posts...): ynNotesView code.
The code contains lots of comments and should be easy to understand.

I'm happy about any comments how to improve that code further.
I am a software developer, consultant and one of the founders of YouAtNotes. You can hire me if you're looking for an expert in
IBM XPages
IBM Domino development
Workflow for IBM Domino
Mobile Apps for Domino or XPages
Just drop a note to sales@youatnotes.com.

Thanks for reading and have a nice time here!

Please note my Apps for iPhone and iPad: NotesBook: takes your Lotus Notes Notebook (Journal) to your iPhone and iPad xpageswiki.com: huge XPages Tips & Tricks collection for iPhone and iPad