Opened 6 years ago

Closed 6 years ago

#1717 closed defect (fixed)

Unstable order of descending sorts

Reported by: fbennett Owned by: simon
Priority: critical Milestone:
Component: uncategorized Version: 2.0
Keywords: Cc:

Description (last modified by fbennett)

A user style (the user being the UN Economic Commission for Latin America and the Caribbean) returns varying year-suffix assignments on each refresh of a wordprocessor document.

adamsmith isolated the issue to descending sorts. The descending sort function in csl.js was returning undefined for matching keys. The patch returns zero instead, which produces a stable result.

If this could be pushed and released fairly soon, it would be splendid.

Attachments (4)

descending-sort-fix.patch (451 bytes) - added by fbennett 6 years ago.
sort-refix.patch (386 bytes) - added by fbennett 6 years ago.
sort-darerefix.patch (653 bytes) - added by fbennett 6 years ago.
the-right-fix.patch (572 bytes) - added by fbennett 6 years ago.

Download all attachments as: .zip

Change History (15)

Changed 6 years ago by fbennett

comment:1 Changed 6 years ago by ajlyon

I saw those lines in csl.js and thought: "Well, that's a pretty straightforward. -1 and +1. There can't be any problem with that." I think I'll have to keep my day job.

Thanks for looking at this with fresh and processor-aware eyes.

comment:2 Changed 6 years ago by dstillman

  • Owner changed from dstillman to simon
  • Status changed from new to assigned

comment:3 in reply to: ↑ description Changed 6 years ago by fbennett

  • Description modified (diff)

Replying to fbennett:

A user style (the user being the UN Economic Commission for Latin America and the Caribbean) returns year-suffix assignments on each refresh of a wordprocessor document.

adamsmith isolated the issue to descending sorts. The descending sort function in csl.js was returning undefined for matching keys. The patch returns zero instead, which produces a stable result.

If this could be pushed and released fairly soon, it would be splendid.

comment:4 Changed 6 years ago by simon

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [6519]) closes #1717, Unstable order of descending sorts (thank to Frank)

Changed 6 years ago by fbennett

comment:5 Changed 6 years ago by fbennett

As the world knows, I messed up; the first patch filed broke sorting on several, perhaps many styles.

The followup, sort-refix.patch, has been confirmed to fix descending-sort stability in the ECLAC style, and to work with the Oecologia for which the breakage was first reported.

comment:6 Changed 6 years ago by fbennett

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:7 Changed 6 years ago by fbennett

  • Resolution set to fixed
  • Status changed from reopened to closed

comment:8 Changed 6 years ago by fbennett

  • Resolution fixed deleted
  • Status changed from closed to reopened

Still problems with second-tier keys. Chicago Author-Date is coming up with a descending sort on the second key, where the first key matches.

http://forums.zotero.org/discussion/14151/bibliography-not-in-alphabetical-order-as-per-selected-style/#CommentBody_69696

I don't fully understand how the sorting code works in csl.js, but the attached sort-darerefix.patch change produces the expected result for Chicago Author-Date, and a stable sort for ECLAC. It's an intuitive change more than anything else; the comment to the code I've commented out says that it was introduced to produce a stable sort, and it looks as though it converts what is trying to flip a 0 (equivalent) result one way or the other. If the other change (introducing the zero in the earlier block) stabilizes the ECLAC sort, possibly this later block is not necessary.

Seems to work with my limited testing, anyway.

Changed 6 years ago by fbennett

comment:9 Changed 6 years ago by dstillman

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [6620]) Fixes #1717, Unstable order of descending sorts

comment:10 Changed 6 years ago by fbennett

  • Resolution fixed deleted
  • Status changed from closed to reopened

Another reproducible error, against the third patch, and on this trip back to the code I spotted the original source of the ECLAC stability error -- it was a silly thing, hiding in plain sight. The attached changefile "the-right-fix.patch" reverts previous changes and inverts the sort using 0 > x and x > 0, rather than 1 > x and x > 1.

This issue has called back so often it deserves its own ringtone.

http://www.youtube.com/watch?v=rW9-FOLG-iA&feature=fvst

Changed 6 years ago by fbennett

comment:11 Changed 6 years ago by dstillman

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [6633]) Fixes #1717, Unstable order of descending sorts, maybe

Note: See TracTickets for help on using tickets.