lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From syedfa <fayyazud...@gmail.com>
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
question:

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
     highlighter.setTextFragmenter(fragmenter);
     high.setTextFragmenter(fragment);
     
        for(int i=0; i<hits.length(); i++){
         Document doc=hits.doc(i);
         String lns = doc.get("LINES");
         TokenStream lines = analyser.tokenStream("LINES", new
StringReader(lns));
         String highlightedLines = highlighter.getBestFragment(lines, lns);
         String highlight = high.getBestFragment(lines, lns);
         SearchResult resultBean = new SearchResult();
         resultBean.setNarrator(hits.doc(i).get("SPEAKER"));
         resultBean.setQuote(highlightedLines);
         resultBean.setHitResult(highlight);
         searchResult.add(resultBean);
         System.out.println(resultBean.getNarrator());
         System.out.println(resultBean.getHitResult());
         System.out.println("");
         //System.out.println(resultBean.getQuote());
         System.out.println("");
         System.out.println("");
         System.out.println("");
        }
        
        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.

Sincerely;
Fayyaz

markrmiller wrote:
> 
> Check out NullFragmenter.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-return-entire-resultset-which-includes-the-highlighted-keywords-tp17354272p17427121.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
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