lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markharw...@yahoo.co.uk
Subject Re: How to extract matching terms for a document given a query
Date Wed, 16 Jun 2004 20:06:03 GMT
>>The reason the current highlighter is not suitable for me, is that the
>>content of the document is not stored in the index

That shouldn't present a problem.
The working code example below was from a recent email discussion I had with someone who was
storing
text in a database. This simple example works shows highlighting working with no index in
sight.

===Begin code====
Analyzer a = new StandardAnalyzer();
Query q = QueryParser.parse("jennifer lopez","cached",a);
String s = "the unofficial home page Britney Spears Elizabeth Hurley Kirsten Dunst Anna Kournikova
Katie Holmes Katherine Heigl Jessica Alba Alyson Hannigan Jennifer Lopez Sarah Michelle Gellar";
Highlighter highlighter = new Highlighter(new QueryScorer(q));
TokenStream tokenstream = a.tokenStream("cached",new java.io.StringReader(s));
 String summary = highlighter.getBestFragments(tokenstream,s,3,"...");
System.out.println(summary);
=== end code =====

Cheers
Mark


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


Mime
View raw message