em.clear();
em.getTransaction().begin();
final QueryBuilder builder = em.getSearchFactory().buildQueryBuilder().forEntity( Clock.class ).get();
Query query = builder.keyword().onField( "brand" ).matching( "Seiko" ).createQuery();
FullTextQuery hibernateQuery = em.createFullTextQuery( query, Clock.class );
List results = hibernateQuery.getResultList();
assertEquals( 500, results.size() );
em.clear();
query = builder.keyword().onField( "brand" ).matching( "Swatch" ).createQuery();
hibernateQuery = em.createFullTextQuery( query, Clock.class );
hibernateQuery.limitExecutionTimeTo( 1, TimeUnit.NANOSECONDS );
List result = hibernateQuery.getResultList();
System.out.println( "Result size early: " + result.size() );
assertEquals( "Test early failure, before the number of results are even fetched", 0, result.size() );
if ( result.size() == 0 ) {
//sometimes, this
assertTrue( hibernateQuery.hasPartialResults() );
}
em.clear();
//We cannot test intermediate limit, Lucene / hibernate: too unpredictable
// hibernateQuery = fts.createFullTextQuery( query, Clock.class );
// hibernateQuery.limitFetchingTime( 1000, TimeUnit.NANOSECONDS );
// results = hibernateQuery.list();
// System.out.println("Result size partial: " + results.size() );
// assertTrue("Regular failure when some elements are fetched", 0 < results.size() && results.size() < 500 );
// assertTrue( hibernateQuery.hasPartialResults() );
//
// fts.clear();
hibernateQuery = em.createFullTextQuery( query, Clock.class );
hibernateQuery.limitExecutionTimeTo( 30, TimeUnit.SECONDS );
results = hibernateQuery.getResultList();
assertEquals( "Test below limit termination", 500, results.size() );
assertFalse( hibernateQuery.hasPartialResults() );
em.getTransaction().commit();
em.clear();