Query query = parser.parse( "equiptype:Cisco" );
org.hibernate.search.FullTextQuery hibQuery = session.createFullTextQuery( query, Departments.class );
hibQuery.setProjection( FullTextQuery.THIS, FullTextQuery.DOCUMENT );
ScrollableResults projections = hibQuery.scroll();
assertNotNull( projections );
projections.beforeFirst();
projections.next();
Object[] projection = projections.get();
assertTrue( "DOCUMENT incorrect", projection[0] instanceof Departments );
assertEquals( "id incorrect", 1, ((Departments)projection[0]).getId() );
assertTrue( "DOCUMENT incorrect", projection[1] instanceof Document );
assertEquals( "DOCUMENT size incorrect", 8, ( (Document) projection[1] ).getFields().size() );
assertNotNull( "equiptype is null", ( (Document) projection[1] ).getField("equiptype") );
assertEquals( "equiptype incorrect", "Cisco", ( (Document) projection[1] ).getField("equiptype" ).stringValue() );
assertNotNull( "branchnetwork is null", ( (Document) projection[1] ).getField("branchnetwork") );
assertEquals( "branchnetwork incorrect", "Salt Lake City 1A", ( (Document) projection[1] ).getField("branchnetwork" ).stringValue() );
projections.next();
projection = projections.get();
assertTrue( "DOCUMENT incorrect", projection[0] instanceof Departments );
assertEquals( "id incorrect", 4, ((Departments)projection[0]).getId() );
assertTrue( "DOCUMENT incorrect", projection[1] instanceof Document );
assertEquals( "DOCUMENT size incorrect", 8, ( (Document) projection[1] ).getFields().size() );
assertNotNull( "equiptype is null", ( (Document) projection[1] ).getField("equiptype") );
assertEquals( "equiptype incorrect", "Cisco", ( (Document) projection[1] ).getField("equiptype" ).stringValue() );
assertNotNull( "branchnetwork is null", ( (Document) projection[1] ).getField("branchnetwork") );
assertEquals( "branchnetwork incorrect", "St. George 1D", ( (Document) projection[1] ).getField("branchnetwork" ).stringValue() );
assertTrue("incorrect result count returned", projections.isLast());
//cleanup
for (Object element : s.createQuery( "from " + Departments.class.getName() ).list()) s.delete( element );
tx.commit();
s.close();
}