Skip to content

Commit 87e2cf6

Browse files
author
Sebastian Benjamin
committed
Fix ranges on > and < operators
1 parent af57ac1 commit 87e2cf6

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

jbrowse/src/client/JBrowse/VariantSearch/operators.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ function fuzzyNumRange(field: string, raw: string | number) {
4242
return `[${floatValue - 0.000001} TO ${floatValue + 0.000001}]`
4343
}
4444

45+
function fuzzyGtRange(f: string, raw: string | number) {
46+
const floatValue = parseFloat(String(raw))
47+
const intValue = parseInt(String(raw), 10)
48+
if (floatValue !== intValue) {
49+
return `${f}:[${floatValue + 0.000001} TO *]`
50+
}
51+
return `${f}:{${intValue} TO *]`
52+
}
53+
54+
function fuzzyLtRange(f: string, raw: string | number) {
55+
const floatValue = parseFloat(String(raw))
56+
const intValue = parseInt(String(raw), 10)
57+
if (floatValue !== intValue) {
58+
return `${f}:[* TO ${floatValue - 0.000001}]`
59+
}
60+
return `${f}:[* TO ${intValue}}`
61+
}
62+
4563
export const OperatorRegistry: Record<OperatorKey, Operator> = {
4664
[OperatorKey.Equals]: {
4765
key: OperatorKey.Equals,
@@ -103,8 +121,7 @@ export const OperatorRegistry: Record<OperatorKey, Operator> = {
103121
[OperatorKey.NumericGt]: {
104122
key: OperatorKey.NumericGt,
105123
label: '>',
106-
generateLucene: (f, v: number) =>
107-
Number.isInteger(v) ? `${f}:{${v} TO *]` : `${f}:[${v + 0.000001} TO *]`,
124+
generateLucene: fuzzyGtRange,
108125
},
109126
[OperatorKey.NumericGte]: {
110127
key: OperatorKey.NumericGte,
@@ -114,8 +131,7 @@ export const OperatorRegistry: Record<OperatorKey, Operator> = {
114131
[OperatorKey.NumericLt]: {
115132
key: OperatorKey.NumericLt,
116133
label: '<',
117-
generateLucene: (f, v: number) =>
118-
Number.isInteger(v) ? `${f}:[* TO ${v}}` : `${f}:[* TO ${v - 0.000001}]`,
134+
generateLucene: fuzzyLtRange,
119135
},
120136
[OperatorKey.NumericLte]: {
121137
key: OperatorKey.NumericLte,

0 commit comments

Comments
 (0)