Arrgh the attachment didn't make it here it goes, sorry:


//perform a standard lucene query searcher = new IndexSearcher(ramDir); Analyzer analyzer=new StandardAnalyzer(); Query query = QueryParser.parse("Kenne*", FIELD_NAME, analyzer); query=query.rewrite(reader); //necessary to expand search terms Hits hits = searcher.search(query);

//create an instance of the highlighter with the tags used to surround highlighted text
QueryHighlightExtractor highlighter =
new QueryHighlightExtractor(query, new StandardAnalyzer(), "<b>", "</b>");



for (int i = 0; i < hits.length(); i++)
{
String text = hits.doc(i).get(FIELD_NAME);
//call to highlight text with chosen tags
String highlightedText = highlighter.highlightText(text);
System.out.println(highlightedText);
}



If your documents are large you can select only the best fragments from each document like this:
//...as above example



int highlightFragmentSizeInBytes = 80;
int maxNumFragmentsRequired = 4;
String fragmentSeparator="...";
for (int i = 0; i < hits.length(); i++)
{
String text = hits.doc(i).get(FIELD_NAME);
String highlightedText = highlighter.getBestFragments(text,
highlightFragmentSizeInBytes,maxNumFragmentsRequired,fragmentSeparator);
System.out.println(highlightedText);
}


On May 21, 2004, at 9:22 AM, Claude Devarenne wrote:

Hi,

Here is the documentation Mark Harwood included in the original package. I followed his directorions and it worked for me. Let me know if this doesn't do it for you.

Claude



On May 21, 2004, at 4:29 AM, Karthik N S wrote:




Hi

 Please can some body give me a simple Example of

 org.apache.lucene.search.highlight.Highlighter

 I am trying to use it but unsucessfull


Karthik






















<image.tiff> WITH WARM REGARDS HAVE A NICE DAY [ N.S.KARTHIK]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to