How to merge results from two different queries

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to merge results from two different queries

Fred-2
I've got a combination of filters for the list controller action. The result list is constructed by using the DetachedCriteria. The list is then passed to the view with pagination control. All is fine.

Now, I need to enable the free text search box (one of the filters) to match regular expressions (in addition to the free text search handled above). So I added logic to construct another list of matched results using regular expressions.

The question is, how best to merge the two lists above (bear in mind that there may be duplications) in the correct order and maintain pagination?
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: How to merge results from two different queries

Nathan Wells
Well, that's an interesting question. In short, the answer is you can't. At least, not without adding an inordinate amount of complexity and performance problems.

I think what you want to do is craft your query in such a way that one list is returned. Otherwise, you'll be forced to implement all the pagination and comparator logic yourself. Which is, in fact, the whole point of a database.

Hope this helps.

Nathan Wells


On Tue, Nov 13, 2012 at 8:32 AM, Fred <[hidden email]> wrote:
I've got a combination of filters for the list controller action. The result list is constructed by using the DetachedCriteria. The list is then passed to the view with pagination control. All is fine.

Now, I need to enable the free text search box (one of the filters) to match regular expressions (in addition to the free text search handled above). So I added logic to construct another list of matched results using regular expressions.

The question is, how best to merge the two lists above (bear in mind that there may be duplications) in the correct order and maintain pagination?
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: How to merge results from two different queries

Fred-2
Thanks a lot Nathan. I followed your advice and it worked fine.

On 14 Nov 2012, at 15:19, Nathan Wells wrote:

Well, that's an interesting question. In short, the answer is you can't. At least, not without adding an inordinate amount of complexity and performance problems.

I think what you want to do is craft your query in such a way that one list is returned. Otherwise, you'll be forced to implement all the pagination and comparator logic yourself. Which is, in fact, the whole point of a database.

Hope this helps.

Nathan Wells


On Tue, Nov 13, 2012 at 8:32 AM, Fred <[hidden email]> wrote:
I've got a combination of filters for the list controller action. The result list is constructed by using the DetachedCriteria. The list is then passed to the view with pagination control. All is fine.

Now, I need to enable the free text search box (one of the filters) to match regular expressions (in addition to the free text search handled above). So I added logic to construct another list of matched results using regular expressions.

The question is, how best to merge the two lists above (bear in mind that there may be duplications) in the correct order and maintain pagination?
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email