Jump to content

Really Odd Processwire Sorting Behavior


joer80
 Share

Recommended Posts

Ok, I dont think I am crazy, but I just wanted to let you guys know this is what I seem to be seeing with processwire and sorting..

If you do a selector based search, say sort=price, and show paged results of that, the default process wire behavior seems to handle ties funny.

It looks like if there is a sort tie, it randomly shows one result before the other.  This was creating a bug in my program because there is a chance to not show a listing when you are paging through the results.

ie.  If there is a price tie between the last listing on page one, and the first listing one page 2, that item may or may not show as you are flipping through the pages because it may roll a page 2 when you are on page 1, and a page 1 when you are on page 2..  :\

To fix this, I just added a second sort option of title to my query.  That way there is never a tie since it would then show the results in title alphabetical.

Just thought I would let you guys know what I noticed and how I fixed it!

Can any of you guys confirm this behavior?  If so, do we need to mention it on the paging section of our documentation?

Thanks!

Link to comment
Share on other sites

  • 2 weeks later...

Doesn’t seem to happen for me. I’m also using the start and limit parameters and sorting by an integer field. This might have something to do with your DB configuration and thus not affect all PW sites equally. Perhaps posting your full selector string can shed some light on this, although I doubt anything short of using sort=random as a second parameter can explain this :D

In any case, if you sort by something you expect to tie frequently, it’s definitely bad practice to not specify a second field. Databases do all kinds of magic and usually can’t guarantee tables to be read in a reliable order. For perfect consistency (pages can have identical titles as well), best sort by ID, which must be unique anyway.

  • Like 2
Link to comment
Share on other sites

When your selling cars, its not always practical to sort by a unique id number.  Sometimes it is price, sometimes it is make + model, etc.  I can confirm it happens without random added with out of the box mysql.  I just thought I would mention it since I noticed them jumping around when I would hit page refresh.   Adding a second sort fixes it though.  I will try to post my selector when I get back to the office!

Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...