* @author John Griffin
*/
public class LuceneQueryTest extends SearchTestCase {
public void testList() throws Exception {
FullTextSession s = Search.getFullTextSession( openSession() );
Transaction tx = s.beginTransaction();
Clock clock = new Clock( 1, "Seiko" );
s.save( clock );
clock = new Clock( 2, "Festina" );
s.save( clock );
Book book = new Book( 1, "La chute de la petite reine a travers les yeux de Festina", "La chute de la petite reine a travers les yeux de Festina, blahblah" );
s.save( book );
book = new Book( 2, "La gloire de mon p�re", "Les deboires de mon p�re en v�lo" );
s.save( book );
tx.commit();
s.clear();
tx = s.beginTransaction();
QueryParser parser = new QueryParser( "title", new StopAnalyzer() );
Query query = parser.parse( "summary:noword" );
org.hibernate.Query hibQuery = s.createFullTextQuery( query, Clock.class, Book.class );
List result = hibQuery.list();
assertNotNull( result );
assertEquals( 0, result.size() );
query = parser.parse( "summary:Festina Or brand:Seiko" );
hibQuery = s.createFullTextQuery( query, Clock.class, Book.class );
result = hibQuery.list();
assertNotNull( result );
assertEquals( "Query with explicit class filter", 2, result.size() );
query = parser.parse( "summary:Festina Or brand:Seiko" );
hibQuery = s.createFullTextQuery( query, Clock.class );
result = hibQuery.list();
assertNotNull( result );
assertEquals( "Query with one class filter", 1, result.size() );
query = parser.parse( "summary:Festina Or brand:Seiko" );
hibQuery = s.createFullTextQuery( query );
result = hibQuery.list();
assertNotNull( result );
assertEquals( "Query with no class filter", 2, result.size() );
for (Object element : result) {
assertTrue( Hibernate.isInitialized( element ) );
s.delete( element );
}
s.flush();
query = parser.parse( "summary:Festina Or brand:Seiko" );
hibQuery = s.createFullTextQuery( query );
result = hibQuery.list();
assertNotNull( result );
assertEquals( "Query with delete objects", 0, result.size() );
for (Object element : s.createQuery( "from java.lang.Object" ).list()) s.delete( element );
tx.commit();
s.close();
}