[ 
https://issues.apache.org/jira/browse/LUCENE-2587?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13142967#comment-13142967
 ] 

Terje Eggestad commented on LUCENE-2587:
----------------------------------------

Sorry for the delay in responding, it's been a year since I looked at this...

I don't have a complete test case as of right now, but I'll upload my 
fragmenter. 
The code is a bit messy, but works by finding all fragment boundaries on 
start(text,tokenstream)
The algorithm is a s follows
- first find paragraphs (marked as "\n\n")
- then chop up paragraphs on "." as close to max length as possible
- if fragments(sentences) are too long, try breaking on "," or ";", else on 
white space

The problem comes since the org.apache.lucene.search.highlight.Highlighter uses 
the end char offset of the last token in the  previous fragment, +1 , as the 
start char offset in the TextFragment.textStartPos
As I'm rereading the Highligther.java code now, this is "hidden" beneath the 
length calculations of a fragment, which is is calculated as: (end char offset 
of last token) - (start char offset of first token), hence the stuff in between 
which is not in a token ultimately gets prepended on the resulting text.

I ultimately did a workaround by replacing leading ".", ",", "?", "!", then a 
trim() on the String Highlighter.getBestFragment() returns...

                
> Highlighter picks wrong offset for fragment boundaries
> ------------------------------------------------------
>
>                 Key: LUCENE-2587
>                 URL: https://issues.apache.org/jira/browse/LUCENE-2587
>             Project: Lucene - Java
>          Issue Type: Bug
>          Components: modules/highlighter
>    Affects Versions: 3.0.2
>         Environment: Java 6 + Lucene 3.0.2
>            Reporter: Terje Eggestad
>            Priority: Trivial
>              Labels: newdev
>         Attachments: IMSentenceFragmenter.java
>
>
> 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) (i) (j) (K) 
> (l) (m) (n) (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

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to