Thanks for your reply. Even if I transferred the entire routine to xpage, it didn't really do much on the performance. What improved the speed was actually improving the actual code itself. Instead of doing 3 getEntriesByKey, I just did it once and just looped through it to see which document fits what criteria.
Thanks again.