Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into downgradeRunnerImage
Browse files Browse the repository at this point in the history
* upstream/main:
  Refactor the isUnwantedText (JabRef#12369)
  Searching for entries with empty field (JabRef#12376)
  Downgrade Ubuntu (JabRef#12375)
  • Loading branch information
Siedlerchr committed Jan 12, 2025
2 parents ffb33a8 + 2cd83df commit 7cfb793
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,24 @@ private boolean isFarAway(TextPosition previous, TextPosition current) {
return Math.abs(Xgap) > XspaceThreshold && Math.abs(Ygap) > YspaceThreshold;
}

private boolean isUnwantedText(TextPosition previousTextPosition, TextPosition textPosition) {
private boolean isUnwantedText(TextPosition previousTextPosition, TextPosition textPosition,
Map<Float, TextPosition> lastPositionMap, float fontSize) {
// This indicates that the text is at the start of the line, so it is needed.
if (textPosition == null || previousTextPosition == null) {
return false;
}
// We use the font size to identify titles. Blank characters don't have a font size, so we discard them.
// The space will be added back in the final result, but not in this method.
if (StringUtil.isBlank(textPosition.getUnicode())) {
return true;
}
// The title usually don't in the bottom 10% of a page.
return (textPosition.getPageHeight() - textPosition.getYDirAdj())
< (textPosition.getPageHeight() * 0.1);
// Titles are generally not located in the bottom 10% of a page.
if ((textPosition.getPageHeight() - textPosition.getYDirAdj()) < (textPosition.getPageHeight() * 0.1)) {
return true;
}
// Characters in a title typically remain close together,
// so a distant character is unlikely to be part of the title.
return lastPositionMap.containsKey(fontSize) && isFarAway(lastPositionMap.get(fontSize), textPosition);
}

private Optional<String> findLargestFontText(List<TextPosition> textPositions) {
Expand All @@ -271,8 +279,7 @@ private Optional<String> findLargestFontText(List<TextPosition> textPositions) {
for (TextPosition textPosition : textPositions) {
float fontSize = textPosition.getFontSizeInPt();
// Exclude unwanted text based on heuristics
if (isUnwantedText(previousTextPosition, textPosition) ||
(lastPositionMap.containsKey(fontSize) && isFarAway(lastPositionMap.get(fontSize), textPosition))) {
if (isUnwantedText(previousTextPosition, textPosition, lastPositionMap, fontSize)) {
continue;
}
fontSizeTextMap.putIfAbsent(fontSize, new StringBuilder());
Expand Down
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 7cfb793

Please sign in to comment.