Card Order of Siblings not preserved in filtered deck

kittenwhisky's Avatar

kittenwhisky

09 Dec, 2019 01:47 PM

I have a filtered deck searching for new cards with a specific tag, displayed in random order:
Search: is:new tag:"SomeTag" Order: Random

The pulled note type has 2 card siblings, Card 1 and Card 2.

The issue: I regularly see Card 2 before their Card 1 siblings in this filtered deck (when both Cards are new). Desired Behaviour: Be shown Card 1 first, then Card 2 (ie preserve the Card Order) of a given note, even though the Note Order of all notes is randomized.

In the browser, I checked the card info of these wrongly ordered cards:

  • both siblings are new
  • both siblings have the same position (although the actual position gets randomized in the filtered deck)
  • neither sibling is buried or suspended

Why is it pulling in Card 2 first, before Card 1? How can I ensure the front-most sibling is shown first please?

The relevant manual entry seems to suggest that the card order of siblings should be preserved, but this might only be referring to Regular Decks, not Filtered Decks.

When you **select random order**, Anki will randomize your notes, keeping the cards of a given note close together. The cards of a given note are **shown in the order their card types appear in**, so that siblings are introduced consistently - otherwise you could end up in a state where some notes had all their cards introduced and other notes had only one or two.
  1. 1 Posted by kittenwhisky on 09 Dec, 2019 01:54 PM

    kittenwhisky's Avatar

    By the way, I'm using Anki 2.1 Desktop (Windows) with Experimental Scheduler V2 enabled.

  2. Support Staff 2 Posted by Damien Elmes on 09 Dec, 2019 09:54 PM

    Damien Elmes's Avatar

    If you use the randomize option in a filtered deck, it completely shuffles the cards. If you use the randomize option described in the manual, and sort the filtered deck by due, the sibling order should be preserved.

  3. 3 Posted by kittenwhisky on 10 Dec, 2019 02:04 PM

    kittenwhisky's Avatar

    Thanks for taking the time to respond.

    As suggested, I changed the deck options to show new cards in random order in the home deck. I then set the Filtered Deck to show in Order Due. However, sibling order wasn't preserved.

    I've checked the source code in schedv2.py as to why that might be:

    In theory, Anki fetches new cards by preserving the card order:
    def _fillNew: select id from cards where did = ? and queue = 0 order by due, ord

    So if 2 siblings have the same due value, then the 1st-order sibling should be shown first.

    However, in practice, no cards in a filtered deck ever have the same Due value. Even when Anki builds the filtered deck sorting by Due.

    1) "Show Filtered Cards by Order Due" option fetches cards without considering the card order.

             def _dynOrder(self, o, l):
                        ....
                 elif o == DYN_DUE:
                        t = "c.due"
                        ...
    

    The returned card list may therefore have this order :

    filteredCards = [ ... , (c.id=Card-2, c.due=5), (c.id=Card-1, c.due=5) , ... ]

    2) The fetched card order is then "solidified" by re-assigning each card a unique due value of -100000 or higher:

        def _moveToDyn(self, did, ids, start=-100000):
            deck = self.col.decks.get(did)
                  ...
            **due = start**
            for id in ids:
                data.append((did, due, u, id))
                **due += 1**
                  ...
    

    so this might result in:

    filteredCards = [ ... , (c.id=Card-2, c.due=-99000), (c.id=Card-1, c.due=-98999) , ... ]


    3) When Anki then hits _fillNew, it will necessarily show Card 2 before Card 1, as it now has a lower due value.



    I think this can be handled by amending the sort order in the filter search query;

      def _dynOrder(self, o, l):
             ...
         elif o == DYN_DUE:
             t = "c.due"  --->  **CHANGE TO: t = "c.due, c.ord" **
            ...
    

    Would this be something that you might consider implementing please?

    Alternatively, I might be able to do a monkey patch if you don't think this should generally be the case.

  4. Support Staff 4 Posted by Damien Elmes on 10 Dec, 2019 10:18 PM

    Damien Elmes's Avatar

    Ah, the second sort clause was only added to the normal review process about a year ago, and this case got missed - I've just pushed an update to GitHub.

  5. 5 Posted by kittenwhisky on 11 Dec, 2019 05:32 PM

    kittenwhisky's Avatar

    Thank you for the quick response and changes! I can see the changes on github.

    How do actually install the updated version please? I tried the latest beta from here but the new card order feature doesn't seem to work.

    Will I need to run anki from source?

  6. Support Staff 6 Posted by Damien Elmes on 12 Dec, 2019 01:36 AM

    Damien Elmes's Avatar

    It's been included in the latest beta.

  7. 7 Posted by kittenwhisky on 12 Dec, 2019 11:14 PM

    kittenwhisky's Avatar

    thanks so much!

  8. kittenwhisky closed this discussion on 12 Dec, 2019 11:14 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac