lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From syedfa <>
Subject Re: How to return entire resultset which includes the highlighted keywords
Date Fri, 23 May 2008 14:40:59 GMT

Thanks so much for your reply Mr.Miller, that's exactly what I was trying to
accomplish!  :-)

I have however, run into another problem now, and thus I have a follow up

My goal is to provide a set of results like google to the user that presents
a set of results with the keyword highlighted along with about two lines of
text surrounding it.  When the user clicks on this link, they should be able
to see the entire block of text with the highlighted keyword on the next
page.  I have found that I am able to do one or the other (i.e. retrieve the
entire block of text with the highlighted keyword, or the highlighted
keyword and just the surrounding text, but not both at the same time).
My code where I am trying to do this is as follows:

     QueryScorer scorer = new QueryScorer(parser);
     Highlighter highlighter = new Highlighter(scorer);  //reference to
highlight the keyword in the entire block of text
     Highlighter high = new Highlighter(scorer); //reference to highlight
the keyword in the surrounding text
     Fragmenter fragmenter = new NullFragmenter();  //reference to retrieve
the entire block of text
     Fragmenter fragment = new SimpleFragmenter(250);// reference to
retrieve the surrounding text
        for(int i=0; i<hits.length(); i++){
         Document doc=hits.doc(i);
         String lns = doc.get("LINES");
         TokenStream lines = analyser.tokenStream("LINES", new
         String highlightedLines = highlighter.getBestFragment(lines, lns);
         String highlight = high.getBestFragment(lines, lns);
         SearchResult resultBean = new SearchResult();
        System.err.println("Found " + hits.length() + " document(s)(in " +
(end-start) + " milliseconds) that matched query '" + q + "':"); 
        return searchResult;        

How would I accomplish this?  Based on my above code, what am I doing wrong? 
My code retrieves the entire block of text with the highilghted keyword
correctly, but I am getting null as my output when I try to print the
results of the highlighted keyword and the surrounding text.

Thanks again for all of your help.


markrmiller wrote:
> Check out NullFragmenter.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

View this message in context:
Sent from the Lucene - Java Users mailing list archive at

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

View raw message