SORTED view in XPages after a fulltext search
Julian Buss, January 13th, 2010
Tags:  XPages 
Everyone knows Nathan T. Freemans Tigerstyle demo. It's a good demo, and it shows how to overcome the limitation that a filtered view (filtered by a category, for example) is not sorted anymore in the XPages world.

But there is one usecase left: if you did a fulltext search on a view, then the results are sorted "by relevance", whatever that means. In the user's eye the view is not sorted at all after the search.
So, if you thought you could build cool "filterable" views by building some nice UI in that a user can select some criterias, compute a fulltext query out of that, do a fulltext search and display the result - forget it. The fact that the results are not sorted is a no-go for most usecases. And,  beside that, the user also expects that he can re-sort the view after the search by any column.

Bad, isn't it? IBM is aware of that problem, and hopefully they will come up with a build-in solution in the near future. But that's not for sure.

But, you know me, I would not write such a blog entry if I would not have any solution on the horizon :-)

Indeed, I spent the best part of yesterday's evening on that problem, without luck. Even today under the shower only a faint of an idea crossed my mind (normally when cracking that sort of problems a shower in the morning always helps...).
Luckily, the faint got stronger and envolved to a real idea, for which I did some prototyping and it works so far.

So, my solution / workaround (whatever you want to call it) needs some testing regarding memory consumption et al, but it works basically and I think we can use it in production in the near future.

I hope I can post code when my tests are finished, but for you other XPages pros out there, here is an outline of the idea:

- get the NotesView
- do a ftsearch on the NotesView
- get the NotesViewEntryCollection of the already searched view
- loop over all NotesViewEntry elements of the collection (which has max 5000 entries)
- add each NotesViewEntry to a java.util.TreeMap with an entry's column value as the key
- return the values of the TreeMap to a repeat control.

Quite easy, and just some lines of code. Works together with a pager control and is relatively fast.
On a slow server at my office the whole process takes under two seconds for a result of about 4.000 NotesViewEntrys.

The beauty in that solution is that you don't need to sort anymore, since the TreeMap is sorted automatically.

What do you think about that solution? It there anything left to optimize?

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