fix: Handle zero-context matches in hyphenated words.#507
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes OCR snippet/highlight generation for matches spanning hyphenated words when the configured snippet context is zero, and addresses a related parser edge case where the last word of a fragment could be skipped.
Changes:
- Add logic in
OcrPassageFormatterto expand a passage when the last token is a highlighted hyphenation start so the continuation is included. - Adjust
OcrParseriteration to rely onreadNext(...)returningnullto signal end-of-stream, avoiding missed final tokens. - Add an hOCR fixture and a regression test covering a hyphenation match at a line break with
hl.ocr.contextSize=0.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/resources/data/hocr_hyphen.html | Adds hOCR sample containing a line-break hyphenation used by a new regression test. |
| src/test/java/com/github/dbmdz/solrocr/solr/HocrTest.java | Adds a test asserting passage expansion and correct highlights for a hyphenated match with zero context. |
| src/main/java/com/github/dbmdz/solrocr/lucene/OcrPassageFormatter.java | Implements passage expansion for highlighted hyphen-start-at-end cases; refactors fragment building to work from parsed boxes. |
| src/main/java/com/github/dbmdz/solrocr/formats/OcrParser.java | Changes parsing loop behavior and documents readNext(...) contract more explicitly. |
| pom.xml | Bumps project version to 0.9.6-SNAPSHOT. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
schmika
reviewed
Feb 11, 2026
9f51164 to
91634b8
Compare
schmika
reviewed
Feb 11, 2026
Comment on lines
+275
to
+277
| if (hyphenEnd.isHyphenated() | ||
| && !hyphenEnd.isHyphenStart() | ||
| && hyphenEnd.getDehyphenatedForm().equals(hyphenStart.getDehyphenatedForm())) { |
Contributor
There was a problem hiding this comment.
Could this check be a method of OcrBox? It might make it easier to understand at a glance what is being checked here.
Member
Author
There was a problem hiding this comment.
Good idea, I'll add OcrBox::isHyphenEndOf(OcrBox other) 👍🏾
Previously we would only return the first half of the hyphenated word and not expand the snippet region to contain the second half. This has now been fixed. During bugfixing, we also discovered a second bug related to this: If the second part of a hyphenated word was part of a fragment, and the last word in that fragment, it would be skipped during parsing of the fragment. Both of these issues have been fixed.
91634b8 to
40f65e3
Compare
schmika
approved these changes
Feb 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously we would only return the first half of the hyphenated word and not expand the snippet region to contain the second half. This has now been fixed.
During bugfixing, we also discovered a second bug related to this: If the second part of a hyphenated word was part of a fragment, and the last word in that fragment, it would be skipped during parsing of the fragment.
Both of these issues have been fixed.