lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <cutt...@apache.org>
Subject Re: Lucene Search Result with Line Numbers?
Date Mon, 11 Apr 2005 17:54:53 GMT
cerberus yao wrote:
>   Does anyone knows how to add the Lucene search results with Line
> number in original source content?

When you display each hit, first scan the text and build an array 
containing the positions of each newline.  Then use the highlighter (in 
contrib/highlighter) to find fragments:

   TextFragment[] frags = highlighter.getBestTextFragments(...);

Finally, display these fragments as complete lines by searching the 
array of line starts for the first fragment's start position to find the 
start line, and the last fragment's end position to find the last line.

Doug

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message