For IntelliJ IDEA,
Android Studio or Eclipse



@Test public void testQueryOnClassBridgeField() { Session s = openSession(); FullTextSession session = Search.getFullTextSession( s ); Transaction tx = s.beginTransaction(); QueryDescriptor query = ElasticsearchQueries.fromQueryString( "fullName:\"Klaus Hergesheimer\"" ); List<?> result = session.createFullTextQuery( query, GolfPlayer.class ).list(); assertThat( result ).onProperty( "id" ).describedAs( "Class-bridge provided string field" ).containsOnly( 1L ); query = ElasticsearchQueries.fromQueryString( "age:34" ); result = session.createFullTextQuery( query, GolfPlayer.class ).list(); assertThat( result ).onProperty( "id" ).describedAs( "Class-bridge provided numeric field" ).containsOnly( 1L ); tx.commit(); s.close(); }
@Test public void testCombinedQueryOnIndexWithSortFieldAndIndexToBeUninverted() throws Exception { Transaction tx = fullTextSession.beginTransaction(); Query query = queryParser.parse( "name:Bill" ); FullTextQuery hibQuery = fullTextSession.createFullTextQuery( query, Plumber.class, BrickLayer.class ); Sort sort = new Sort( new SortField( "sortName", SortField.Type.STRING ) ); //ASC hibQuery.setSort( sort ); @SuppressWarnings("unchecked") List<Book> result = hibQuery.list(); assertNotNull( result ); assertThat( result ).onProperty( "name" ) .describedAs( "Expecting results from index with sort field and uninverted index in the correct sort order" ) .containsExactly( "Bill the brick layer", "Bill the plumber" ); tx.commit(); }
@Test public void testQueryOnNullToken() { Session s = openSession(); FullTextSession session = Search.getFullTextSession( s ); Transaction tx = s.beginTransaction(); QueryDescriptor query = ElasticsearchQueries.fromQueryString( "firstName:<NULL>" ); List<?> result = session.createFullTextQuery( query, GolfPlayer.class ).list(); assertThat( result ).onProperty( "id" ).describedAs( "Querying null-encoded String" ).containsOnly( 2L ); query = ElasticsearchQueries.fromQueryString( "dateOfBirth:1970-01-01" ); result = session.createFullTextQuery( query, GolfPlayer.class ).list(); assertThat( result ).onProperty( "id" ).describedAs( "Querying null-encoded Date" ).containsOnly( 2L ); query = ElasticsearchQueries.fromQueryString( "active:false" ); result = session.createFullTextQuery( query, GolfPlayer.class ).list(); assertThat( result ).onProperty( "id" ).describedAs( "Querying null-encoded Boolean" ).containsOnly( 2L ); query = ElasticsearchQueries.fromQueryString( "driveWidth:\\-1" ); result = session.createFullTextQuery( query, GolfPlayer.class ).list(); assertThat( result ).onProperty( "id" ).describedAs( "Querying null-encoded Integer" ).containsOnly( 2L ); tx.commit(); s.close(); }
.describedAs( "Sortable field via programmatic config" ) .containsExactly( (short) 3354, (short) 3454, (short) 3554 ); .describedAs( "Sortable field via programmatic config" ) .containsExactly( 1, 2, 3 );
assertThat( result ).onProperty( "id" ).describedAs( "Geo distance query" ).containsOnly( 1, 2, 3, 4 );
.describedAs( "Running delete-by-query for other tenant should not affect entities of this entity" ) .onProperty( "name" ) .containsOnly( "Metz", "Plenty" );
.describedAs( "Query results are not in the order expected as per configured field boosts" ) .onProperty( "id" ) .containsExactly( 2L, 4L, 3L, 1L );
.describedAs( "Retrieved facets - values" ) .containsExactly( "[, 50.0)", "[50.0, 1000.0)", "[1000.0, ]" ); assertThat( facets ).onProperty( "count" ) .describedAs( "Retrieved facets - counts" ) .containsExactly( 2, 1, 1 );
.setSort( new Sort( new DistanceSortField( 24, 32, "location" ) ) ) .list(); assertThat( result ).onProperty( "id" ).describedAs( "Geo distance query" ).containsOnly( 1, 2, 3 );
.describedAs( "Can load results originating from different id spaces, using different id types and names" ) .containsOnly( "Southern Florida College of Golf",