s.persist( getDepts4() );
s.flush();
tx.commit();
tx = s.beginTransaction();
FullTextSession session = Search.getFullTextSession( s );
// The equipment field is the manufacturer field in the
// Departments entity after being massaged by passing it
// through the EquipmentType class. This field is in
// the Lucene document but not in the Department entity itself.
QueryParser parser = new QueryParser( "equipment", new SimpleAnalyzer() );
// Check the second ClassBridge annotation
Query query = parser.parse( "equiptype:Cisco" );
org.hibernate.search.FullTextQuery hibQuery = session.createFullTextQuery( query, Departments.class );
List<Departments> result = hibQuery.list();
assertNotNull( result );
assertEquals( "incorrect number of results returned", 2, result.size() );
for (Departments d : result) {
assertEquals("incorrect manufacturer", "C", d.getManufacturer());
}
// No data cross-ups.
query = parser.parse( "branchnetwork:Kent Lewin" );
hibQuery = session.createFullTextQuery( query, Departments.class );
result = hibQuery.list();
assertNotNull( result );
assertTrue( "problem with field cross-ups", result.size() == 0 );
// Non-ClassBridge field.
parser = new QueryParser( "branchHead", new SimpleAnalyzer() );
query = parser.parse( "branchHead:Kent Lewin" );
hibQuery = session.createFullTextQuery( query, Departments.class );
result = hibQuery.list();
assertNotNull( result );
assertTrue( "incorrect entity returned, wrong branch head", result.size() == 1 );
assertEquals("incorrect entity returned", "Kent Lewin", ( result.get( 0 ) ).getBranchHead());
// Check other ClassBridge annotation.
parser = new QueryParser( "branchnetwork", new SimpleAnalyzer() );
query = parser.parse( "branchnetwork:st. george 1D" );
hibQuery = session.createFullTextQuery( query, Departments.class );
result = hibQuery.list();
assertNotNull( result );
assertEquals( "incorrect entity returned, wrong network", "1D", ( result.get( 0 ) ).getNetwork() );
assertEquals( "incorrect entity returned, wrong branch", "St. George", ( result.get( 0 ) ).getBranch() );
assertEquals( "incorrect number of results returned", 1, result.size() );