lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Karl Øie <k...@gan.no>
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 = "crash.java";
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));
	index_writer.addDocument(ld);
	line_number++;
}

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 "Test.java" which is indexed by lucene.
>      When I search inside the index, how to enhance the search result
> with line number in Test.java?
>
>   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: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
- 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: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message