Skip to content

Commit 94f0f4e

Browse files
authored
Searching for entries with empty field (#12376)
* Searching for entries with empty field * Simplify condition
1 parent 772f24b commit 94f0f4e

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/main/java/org/jabref/logic/search/query/SearchToSqlVisitor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,16 @@ public SqlQueryNode visitComparison(SearchParser.ComparisonContext ctx) {
207207
setFlags(searchFlags, REGULAR_EXPRESSION, true, true);
208208
}
209209

210+
// field = "" -> should find entries where the field is empty
211+
// field != "" -> should find entries where the field is not empty
212+
if (term.isEmpty()) {
213+
if (searchFlags.contains(NEGATION)) {
214+
searchFlags.remove(NEGATION);
215+
} else {
216+
searchFlags.add(NEGATION);
217+
}
218+
}
219+
210220
return getFieldQueryNode(field.toLowerCase(Locale.ROOT), term, searchFlags);
211221
}
212222

src/test/java/org/jabref/logic/search/query/SearchQuerySQLConversionTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,38 @@ cte0 AS (
695695
)
696696
)
697697
SELECT * FROM cte0 GROUP BY entryid"""
698+
),
699+
700+
Arguments.of(
701+
"file = \"\"",
702+
"""
703+
WITH
704+
cte0 AS (
705+
SELECT main_table.entryid
706+
FROM bib_fields."tableName" AS main_table
707+
WHERE main_table.entryid NOT IN (
708+
SELECT inner_table.entryid
709+
FROM bib_fields."tableName" AS inner_table
710+
WHERE (
711+
(inner_table.field_name = 'file') AND ((inner_table.field_value_literal ILIKE ('%%')) OR (inner_table.field_value_transformed ILIKE ('%%')))
712+
)
713+
)
714+
)
715+
SELECT * FROM cte0 GROUP BY entryid"""
716+
),
717+
718+
Arguments.of(
719+
"file != \"\"",
720+
"""
721+
WITH
722+
cte0 AS (
723+
SELECT main_table.entryid
724+
FROM bib_fields."tableName" AS main_table
725+
WHERE (
726+
(main_table.field_name = 'file') AND ((main_table.field_value_literal ILIKE ('%%')) OR (main_table.field_value_transformed ILIKE ('%%')))
727+
)
728+
)
729+
SELECT * FROM cte0 GROUP BY entryid"""
698730
)
699731
);
700732
}

0 commit comments

Comments
 (0)