apache / apache/lucene

Highlighter picks wrong offset for fragment boundaries [LUCENE-2587]

Open
#3,661 15 comments 0 reactions 0 assignees View on GitHub
affects-version:3.0.2 legacy-jira-label:newdev legacy-jira-priority:Trivial module:highlighter type:bug
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

I have written a new Fragmenter since we need fragments for hitlines to be on sentence boundaries and not cross paragraphs.
When using it with org.apache.lucene.search.highlight.Highlighter, I get hitlines that starts with ". ", "? ", "! "...

Consider the text "A b c d e. F g h i j! K l m n o. "
which become the tokenstream : (A) (b) (c) (d) (e) (F) (g) (h) 🛈 (j) (K) (l) (m) 👎 (o)

If the fragmenter return isNewFragment() = true on F and K and Highlighter pick the middle fragment, lets say we search on "g" the hitline becomes:
". F <B>g</B> h i j"

The reason, it seems, is that the offset to the fragment boundaries found by taking the endOffset of the last token in a fragment ,
not the startOffset of the first.

TJ

---
Migrated from [LUCENE-2587](https://issues.apache.org/jira/browse/LUCENE-2587) by Terje Eggestad, 3 votes, updated Aug 15 2022
Environment:
```
Java 6 + Lucene 3.0.2
```

Attachments: [IMSentenceFragmenter.java](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-2587/IMSentenceFragmenter.java), [LUCENE-2587.patch](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-2587/LUCENE-2587.patch), [TestIMSentenceFragmenter.java](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-2587/TestIMSentenceFragmenter.java)
Pull requests: https://github.com/apache/lucene/pull/1069

Contributor guide

Open the contributing guide

Research direction

Read the attached IMSentenceFragmenter.java and TestIMSentenceFragmenter.java, then review LUCENE-2587.patch alongside org.apache.lucene.search.highlight.Highlighter. Use the reported sentence-boundary example as the reproduction; done means the selected hitline no longer begins with punctuation and the attached test demonstrates correct fragment offsets.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.