From 6e2823a4c00125613cdc5a581c9dfbfcb6cba5eb Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 9 Jun 2021 16:41:15 +0100 Subject: [PATCH] Invert boolean filter expressions to consider nulls as false --- packages/standard-components/src/lucene.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/standard-components/src/lucene.js b/packages/standard-components/src/lucene.js index fbeaecbdd7..93abad3159 100644 --- a/packages/standard-components/src/lucene.js +++ b/packages/standard-components/src/lucene.js @@ -13,7 +13,9 @@ export const buildLuceneQuery = filter => { notEmpty: {}, } if (Array.isArray(filter)) { - filter.forEach(({ operator, field, type, value }) => { + // Build up proper range filters + filter.forEach(expression => { + const { operator, field, type, value } = expression if (operator.startsWith("range")) { if (!query.range[field]) { query.range[field] = { @@ -33,10 +35,26 @@ export const buildLuceneQuery = filter => { query.range[field].high = value } } else if (query[operator]) { - query[operator][field] = value + if (type === "boolean") { + // Transform boolean filters to cope with null. + // "equals false" needs to be "not equals true" + // "not equals false" needs to be "equals true" + if (operator === "equal" && value === "false") { + query.notEqual[field] = "true" + } else if (operator === "notEqual" && value === "false") { + query.equal[field] = "true" + } else { + query[operator][field] = value + } + } else { + query[operator][field] = value + } } }) } + + console.log(query) + return query }