lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Karl Øie <>
Subject Re: Lucene Search Result with Line Numbers?
Date Mon, 11 Apr 2005 12:28:31 GMT
Most indexing creates a Lucene document for each Source document. What 
would need is to create a Lucene document for each line.

String src_doc = "";
int line_number = 0;
while(reader!=EOF) {
	String line = reader.readLine();
	Document ld = new Document();
	ld.add(new Field("id", src_doc, true, true, false));
	ld.add(new Field("line", ""+line_number, true, true, false));
	ld.add(new Field("text", line.toString(), false, true, true));

This will create a small lucene document for each line, upon search you 
will find documents based on the content of the line and the line 
number as a field. The reason syntax highlighting works without 
creating a lucene document for each line is because syntax highlighting 
bases its result on groups of occurencies of text, not line numbers.

Mvh Karl Øie

On 11. apr. 2005, at 11.50, cerberus yao wrote:

> Hi, Lucene users:
>   Does anyone knows how to add the Lucene search results with Line
> number in original source content?
>   for example:
>      I have a file "" which is indexed by lucene.
>      When I search inside the index, how to enhance the search result
> with line number in
>   ps. the lucene sandbox has a highlighter for search result. where
> can I find a line number decorator for search results?
>  Thx.
>  Best regards,
> --
> Charley, Chang-Li Yao
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:
- there is nothing wrong with using linux. if that's the lifestyle you 
want to live, i wont judge you. i just wont support you at the parades.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message