Package org.hibernate.search.test.spatial

Examples of org.hibernate.search.test.spatial.POI


*/
public class SpatialQueryingJPATest extends JPATestCase {

  @Test
  public void testDistanceProjection() throws Exception {
    POI poi = new POI( 1, "Distance to 24,32 : 0", 24.0d, 32.0d, "" );
    POI poi2 = new POI( 2, "Distance to 24,32 : 10.16", 24.0d, 31.9d, "" );
    POI poi3 = new POI( 3, "Distance to 24,32 : 11.12", 23.9d, 32.0d, "" );
    POI poi4 = new POI( 4, "Distance to 24,32 : 15.06", 23.9d, 32.1d, "" );
    POI poi5 = new POI( 5, "Distance to 24,32 : 22.24", 24.2d, 32.0d, "" );
    POI poi6 = new POI( 6, "Distance to 24,32 : 24.45", 24.2d, 31.9d, "" );

    FullTextEntityManager em = Search.getFullTextEntityManager( factory.createEntityManager() );

    em.getTransaction().begin();
    em.persist( poi );
View Full Code Here


    em.close();
  }

  @Test
  public void testDistanceSort() throws Exception {
    POI poi = new POI( 1, "Distance to 24,32 : 0", 24.0d, 32.0d, "" );
    POI poi2 = new POI( 2, "Distance to 24,32 : 10.16", 24.0d, 31.9d, "" );
    POI poi3 = new POI( 3, "Distance to 24,32 : 11.12", 23.9d, 32.0d, "" );
    POI poi4 = new POI( 4, "Distance to 24,32 : 15.06", 23.9d, 32.1d, "" );
    POI poi5 = new POI( 5, "Distance to 24,32 : 22.24", 24.2d, 32.0d, "" );
    POI poi6 = new POI( 6, "Distance to 24,32 : 24.45", 24.2d, 31.9d, "" );

    FullTextEntityManager em = Search.getFullTextEntityManager( factory.createEntityManager() );

    em.getTransaction().begin();
    em.persist( poi );
View Full Code Here

        {50.78361600, 6.07003500},
        {50.76066667, 6.08866667},
        {50.77683333, 6.08466667},
        {50.77650000, 6.08416667},
    } ) {
      em.persist( new POI( cnt, "Test_" + cnt, c[0], c[1], "" ) );
      ++cnt;
    }
    em.getTransaction().commit();


    em.getTransaction().begin();
    double centerLatitude = 50.7753455;
    double centerLongitude = 6.083886799999959;

    final QueryBuilder builder = em.getSearchFactory().buildQueryBuilder().forEntity( POI.class ).get();

    org.apache.lucene.search.Query luceneQuery = builder.spatial().onCoordinates( "location" )
        .within( 1.8097233616663808, Unit.KM )
          .ofLatitude( centerLatitude )
          .andLongitude( centerLongitude )
        .createQuery();

    FullTextQuery hibQuery = em.createFullTextQuery( luceneQuery, POI.class );
    Sort distanceSort = new Sort( new DistanceSortField( centerLatitude, centerLongitude, "location" ) );
    hibQuery.setSort( distanceSort );
    hibQuery.setMaxResults( 1000 );
    hibQuery.setProjection( FullTextQuery.THIS, FullTextQuery.SPATIAL_DISTANCE );
    hibQuery.setSpatialParameters( centerLatitude, centerLongitude, "location" );
    List<Object[]> results = hibQuery.getResultList();

    for ( Object[] result : results ) {
      POI poi = (POI)result[0];
      String message = poi.getName() + " (" + poi.getLatitude() + ", " + poi.getLongitude() + ") is not at "
          + centerLatitude + ", " + centerLongitude;

      Assert.assertThat( message, ( (Double) result[1] ).doubleValue(), is( not( 0.0 ) ) );
    }
View Full Code Here

    em.close();
  }

  @Test
  public void testDistanceSortWithMaxResult() throws Exception {
    POI poi = new POI( 1, "Distance to 24,32 : 0", 24.0d, 32.0d, "" );
    POI poi2 = new POI( 2, "Distance to 24,32 : 10.16", 24.0d, 31.9d, "" );
    POI poi3 = new POI( 3, "Distance to 24,32 : 11.12", 23.9d, 32.0d, "" );
    POI poi4 = new POI( 4, "Distance to 24,32 : 15.06", 23.9d, 32.1d, "" );
    POI poi5 = new POI( 5, "Distance to 24,32 : 22.24", 24.2d, 32.0d, "" );
    POI poi6 = new POI( 6, "Distance to 24,32 : 24.45", 24.2d, 31.9d, "" );

    FullTextEntityManager em = Search.getFullTextEntityManager( factory.createEntityManager() );

    em.getTransaction().begin();
    em.persist( poi );
View Full Code Here

TOP

Related Classes of org.hibernate.search.test.spatial.POI

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.