zopefoundation / Products.ZCatalog

Zope's indexing and search solution.
Other
5 stars 22 forks source link

Wrong sorting when using sort_limit #108

Closed gforcada closed 3 years ago

gforcada commented 4 years ago

Scenario: I have a folder full of documents and to make its listing I use the following catalog query:

        query = {
            'member_id': self.context.id,
            'portal_type': 'freitag.article.article',
            'sort_on': 'effective',
            'sort_order': 'reverse',
        }

While trying to make things faster (side note: this issue has nothing to do with performance) I decided to add a new query parameter to it: 'sort_limit': self.b_start + self.b_size * 2, but no matter what number I put on the sort_limit the elements are sorted differently :shrug:

As I guess that is quite difficult to get help, where would be the best place to add a test to check for that, so I can try to get a reproducible test to check it? :thinking:

d-maurer commented 4 years ago

Gil Forcada Codinachs wrote at 2020-7-2 08:50 -0700:

Scenario: I have a folder full of documents and to make its listing I use the following catalog query:

       query = {
           'member_id': self.context.id,
           'portal_type': 'freitag.article.article',
           'sort_on': 'effective',
           'sort_order': 'reverse',
       }

While trying to make things faster (side note: this issue has nothing to do with performance) I decided to add a new query parameter to it: 'sort_limit': self.b_start + self.b_size * 2, but no matter what number I put on the sort_limit the elements are sorted differently :shrug:

As I guess that is quite difficult to get help, where would be the best place to add a test to check for that, so I can try to get a reproducible test to check it? :thinking:

Look at the available ZCatalog tests. There are tests which test sorting. Copy one of those tests and adapt to include sort_limit.

agitator commented 3 years ago

I also ran into this on Plone 5.2 and 6. Sorting reverse on a collection result displays items already shown in the next batch page and over

gforcada commented 3 years ago

Yes, seems that is not only our setup then :) it is exactly as you said. Unfortunately our solution so far has been forcing the query to go through Solr (via collective.solr) :confused:

agitator commented 3 years ago

Imho every reverse sorted listing... Another workaround, at least for me, is to create an index that is reverse by default.