summaryrefslogtreecommitdiff
path: root/ext/bg/js/dictionary.js
diff options
context:
space:
mode:
authorAlex Yatskov <FooSoft@users.noreply.github.com>2019-11-13 18:51:50 -0800
committerGitHub <noreply@github.com>2019-11-13 18:51:50 -0800
commitb1659522b30cecc0583745da5a44fdd75660274a (patch)
tree89c17fa51f91ee43b1a206a9ae2d7b5721892ae9 /ext/bg/js/dictionary.js
parent7d9d45ae10302582ce7431bd72ec4f8604dc5e65 (diff)
parent7333873244ccaeeefe01bd3a63447f39dd4f3bbe (diff)
Merge pull request #274 from toasted-nutbread/lookup-wildcards
Lookup wildcards
Diffstat (limited to 'ext/bg/js/dictionary.js')
-rw-r--r--ext/bg/js/dictionary.js40
1 files changed, 12 insertions, 28 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index a4cf34ed..9aa0af9c 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -55,39 +55,23 @@ function dictRowsSort(rows, options) {
function dictTermsSort(definitions, dictionaries=null) {
return definitions.sort((v1, v2) => {
+ let i;
if (dictionaries !== null) {
- const p1 = (dictionaries[v1.dictionary] || {}).priority || 0;
- const p2 = (dictionaries[v2.dictionary] || {}).priority || 0;
- if (p1 > p2) {
- return -1;
- } else if (p1 < p2) {
- return 1;
- }
+ i = (
+ ((dictionaries[v2.dictionary] || {}).priority || 0) -
+ ((dictionaries[v1.dictionary] || {}).priority || 0)
+ );
+ if (i !== 0) { return i; }
}
- const sl1 = v1.source.length;
- const sl2 = v2.source.length;
- if (sl1 > sl2) {
- return -1;
- } else if (sl1 < sl2) {
- return 1;
- }
+ i = v2.source.length - v1.source.length;
+ if (i !== 0) { return i; }
- const rl1 = v1.reasons.length;
- const rl2 = v2.reasons.length;
- if (rl1 < rl2) {
- return -1;
- } else if (rl1 > rl2) {
- return 1;
- }
+ i = v2.reasons.length - v1.reasons.length;
+ if (i !== 0) { return i; }
- const s1 = v1.score;
- const s2 = v2.score;
- if (s1 > s2) {
- return -1;
- } else if (s1 < s2) {
- return 1;
- }
+ i = v2.score - v1.score;
+ if (i !== 0) { return i; }
return v2.expression.toString().localeCompare(v1.expression.toString());
});