Skip to content

Commit

Permalink
Searching for entries with empty field (#12376)
Browse files Browse the repository at this point in the history
* Searching for entries with empty field

* Simplify condition
  • Loading branch information
LoayGhreeb authored Jan 10, 2025
1 parent 772f24b commit 94f0f4e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ public SqlQueryNode visitComparison(SearchParser.ComparisonContext ctx) {
setFlags(searchFlags, REGULAR_EXPRESSION, true, true);
}

// field = "" -> should find entries where the field is empty
// field != "" -> should find entries where the field is not empty
if (term.isEmpty()) {
if (searchFlags.contains(NEGATION)) {
searchFlags.remove(NEGATION);
} else {
searchFlags.add(NEGATION);
}
}

return getFieldQueryNode(field.toLowerCase(Locale.ROOT), term, searchFlags);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,38 @@ cte0 AS (
)
)
SELECT * FROM cte0 GROUP BY entryid"""
),

Arguments.of(
"file = \"\"",
"""
WITH
cte0 AS (
SELECT main_table.entryid
FROM bib_fields."tableName" AS main_table
WHERE main_table.entryid NOT IN (
SELECT inner_table.entryid
FROM bib_fields."tableName" AS inner_table
WHERE (
(inner_table.field_name = 'file') AND ((inner_table.field_value_literal ILIKE ('%%')) OR (inner_table.field_value_transformed ILIKE ('%%')))
)
)
)
SELECT * FROM cte0 GROUP BY entryid"""
),

Arguments.of(
"file != \"\"",
"""
WITH
cte0 AS (
SELECT main_table.entryid
FROM bib_fields."tableName" AS main_table
WHERE (
(main_table.field_name = 'file') AND ((main_table.field_value_literal ILIKE ('%%')) OR (main_table.field_value_transformed ILIKE ('%%')))
)
)
SELECT * FROM cte0 GROUP BY entryid"""
)
);
}
Expand Down

0 comments on commit 94f0f4e

Please sign in to comment.