@Test public void testExplanation() throws Exception { FullTextSession s = Search.getFullTextSession( openSession() ); Transaction tx = s.beginTransaction(); Dvd dvd = new Dvd( "The dark knight", "Batman returns with his best enemy the Joker. The dark side of this movies shows up pretty quickly" ); s.persist( dvd ); dvd = new Dvd( "Wall-e", "The tiny little robot comes to Earth after the dark times and tries to clean it" ); s.persist( dvd ); tx.commit(); s.clear(); tx = s.beginTransaction(); Map<String, Float> boosts = new HashMap<String, Float>( 2 ); boosts.put( "title", new Float( 4 ) ); boosts.put( "description", new Float( 1 ) ); MultiFieldQueryParser parser = new MultiFieldQueryParser( new String[]{ "title", "description" }, TestConstants.standardAnalyzer, boosts ); Query luceneQuery = parser.parse( "dark" ); FullTextQuery ftQuery = s.createFullTextQuery( luceneQuery, Dvd.class ) .setProjection( FullTextQuery.DOCUMENT_ID, FullTextQuery.EXPLANATION, FullTextQuery.THIS ); @SuppressWarnings("unchecked") List<Object[]> results = ftQuery.list(); assertEquals( 2, results.size() ); for ( Object[] result : results ) { assertEquals( ftQuery.explain( (Integer) result[0] ).toString(), result[1].toString() ); s.delete( result[2] ); } tx.commit(); s.close(); } @Override