lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mark harwood <markharw...@yahoo.co.uk>
Subject Re: Highlighter: how to specify text from external source?
Date Tue, 08 Feb 2005 15:19:11 GMT
Here's a rough example using a database:

 Hits hits=searcher.search(q);
 int numDocs=Math.min(10, hits.length());
 Analyzer analyzer=new WhitespaceAnalyzer();

 PreparedStatement ps=conn.prepareStatement("select
docText from myTable where pk=?");
            for(int i=0;i<numDocs;i++)
            {
          //get the key from Lucene storage
                int
rdbmsKey=Integer.parseInt(hits.doc(i).get("rdbmsKey"));
          //pass it to RDBMS query
                ps.setInt(1,rdbmsKey);
    	    if(rs.next())
    	    {

    	        String docText=rs.getString(1);
                TokenStream tokenStream =             
      analyzer.tokenStream("contents", new
StringReader(docText));
                String hilite=
highlighter.getBestFragments(tokenStream,
docText,3,"...");


    	    }
            }
...finally
{
          DBUtils.tidy(conn,ps,rs);
}


	
	
		
___________________________________________________________ 
ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com

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