Skip to content

Commit

Permalink
fix order by note content size, closes #3488
Browse files Browse the repository at this point in the history
  • Loading branch information
zadam committed Jan 5, 2023
1 parent 161b45a commit 218f526
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions src/services/search/expressions/order_by_and_limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@ class OrderByAndLimitExp extends Expression {
}

// if both are numbers then parse them for numerical comparison
// beware that isNaN will return false for empty string and null
if (valA.trim() !== "" && valB.trim() !== "" && !isNaN(valA) && !isNaN(valB)) {
if (this.isNumber(valA) && this.isNumber(valB)) {
valA = parseFloat(valA);
valB = parseFloat(valB);
}

if (!valA && !valB) {
// the attribute is not defined in either note so continue to next order definition
// the attribute value is empty/zero in both notes so continue to the next order definition
continue;
} else if (!valB || valA < valB) {
return smaller;
Expand All @@ -77,6 +76,17 @@ class OrderByAndLimitExp extends Expression {

return noteSet;
}

isNumber(x) {
if (typeof x === 'number') {
return true;
} else if (typeof x === 'string') {
// isNaN will return false for blank string
return x.trim() !== "" && !isNaN(x);
} else {
return false;
}
}
}

module.exports = OrderByAndLimitExp;
4 changes: 2 additions & 2 deletions src/services/search/value_extractor.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use strict";

/**
* Search string is lower cased for case insensitive comparison. But when retrieving properties
* we need case sensitive form so we have this translation object.
* Search string is lower cased for case-insensitive comparison. But when retrieving properties
* we need case-sensitive form, so we have this translation object.
*/
const PROP_MAPPING = {
"noteid": "noteId",
Expand Down

0 comments on commit 218f526

Please sign in to comment.