word/finder: order by grade within levels
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 10 Feb 2022 03:21:22 +0000 (04:21 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 1 Mar 2022 20:02:26 +0000 (21:02 +0100)
tools/mkwordlist
word/finder.js

index 2e38a8d45ad34f1078db74b93ba5175d5b35121f..6f42fc86c6d46c67339eb61f0b11b53751ba631f 100755 (executable)
@@ -13,7 +13,7 @@ use Data::Dump 'pp';
 my %rows;
 if (my $lang = shift @ARGV) {
        my %filter = (lang => $lang);
-       my $cols = "ref, array_to_string(form || alt, '/'), prio, id, cat";
+       my $cols = "ref, array_to_string(form || alt, '/'), prio + coalesce(grade, 90) / 100::float, id, cat";
        %rows = $db->select(_word_ref => $cols, \%filter)->map_arrays;
        say pp \%rows
                =~ s/\\x\{([0-9A-F]+)\}/chr hex $1/ger;
index 606f0334432b5d3f3a48ed0b0f3b51f3f62a20d9..b1db273415ae27e51f7c40026c014673fd115543 100644 (file)
@@ -17,7 +17,11 @@ class WordFinder extends WordQuiz {
                        if (this.cats[ref]) {
                                // delve into subcategory
                                put(worditem, '.parent');
-                               this.add(worditem, this.cats[ref]);
+                               this.add(worditem, this.cats[ref].sort((a, b) => {
+                                       const [worda, wordb] = [this.data[a], this.data[b]];
+                                       return (worda[1] % 1) - (wordb[1] % 1)
+                                               || worda[0].localeCompare(wordb[0]);
+                               }));
                        }
                });
        }