-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-923 Integrate geocode into test harness
- Loading branch information
1 parent
b6b8187
commit a3eeaa0
Showing
2 changed files
with
78 additions
and
82 deletions.
There are no files selected for viewing
82 changes: 0 additions & 82 deletions
82
hibernate-search-orm/src/test/java/org/hibernate/search/test/spatial/IndexingTest.java
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
...rnate-search-orm/src/test/java/org/hibernate/search/test/spatial/SpatialIndexingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.hibernate.search.test.spatial; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Assert; | ||
|
||
import org.hibernate.Transaction; | ||
import org.hibernate.search.FullTextSession; | ||
import org.hibernate.search.Search; | ||
import org.hibernate.search.spatial.Point; | ||
import org.hibernate.search.spatial.SpatialQueryBuilder; | ||
import org.hibernate.search.test.SearchTestCase; | ||
|
||
public class SpatialIndexingTest extends SearchTestCase { | ||
|
||
public void testIndexing() throws Exception { | ||
POI poi = new POI( 1, "Test", 24.0d, 32.0d, "" ); | ||
FullTextSession fullTextSession = Search.getFullTextSession( openSession() ); | ||
|
||
Transaction tx = fullTextSession.beginTransaction(); | ||
fullTextSession.save( poi ); | ||
tx.commit(); | ||
|
||
tx = fullTextSession.beginTransaction(); | ||
Point center = Point.fromDegrees( 24, 31.5 ); // 50.79 km fromBoundingCircle 24.32 | ||
|
||
org.apache.lucene.search.Query luceneQuery = SpatialQueryBuilder.buildGridQuery( center, 50, "location" ); | ||
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery( luceneQuery, POI.class ); | ||
List results = hibQuery.list(); | ||
Assert.assertEquals( 1, results.size() ); | ||
|
||
org.apache.lucene.search.Query luceneQuery2 = SpatialQueryBuilder.buildGridQuery( center, 1, "location" ); | ||
org.hibernate.Query hibQuery2 = fullTextSession.createFullTextQuery( luceneQuery2, POI.class ); | ||
List results2 = hibQuery2.list(); | ||
Assert.assertEquals( 0, results2.size() ); | ||
|
||
org.apache.lucene.search.Query luceneQuery3 = SpatialQueryBuilder.buildDistanceQuery( | ||
center, | ||
50, | ||
"location" | ||
); | ||
org.hibernate.Query hibQuery3 = fullTextSession.createFullTextQuery( luceneQuery3, POI.class ); | ||
List results3 = hibQuery3.list(); | ||
Assert.assertEquals( 0, results3.size() ); | ||
|
||
org.apache.lucene.search.Query luceneQuery4 = SpatialQueryBuilder.buildSpatialQuery( | ||
center, | ||
50, | ||
"location" | ||
); | ||
org.hibernate.Query hibQuery4 = fullTextSession.createFullTextQuery( luceneQuery4, POI.class ); | ||
List results4 = hibQuery4.list(); | ||
Assert.assertEquals( 0, results4.size() ); | ||
|
||
org.apache.lucene.search.Query luceneQuery5 = SpatialQueryBuilder.buildSpatialQuery( | ||
center, | ||
51, | ||
"location" | ||
); | ||
org.hibernate.Query hibQuery5 = fullTextSession.createFullTextQuery( luceneQuery5, POI.class ); | ||
List results5 = hibQuery5.list(); | ||
Assert.assertEquals( 1, results5.size() ); | ||
|
||
List<?> pois = fullTextSession.createQuery( "from " + POI.class.getName() ).list(); | ||
for (Object entity : pois) { | ||
fullTextSession.delete( entity ); | ||
} | ||
tx.commit(); | ||
fullTextSession.close(); | ||
} | ||
|
||
@Override | ||
protected Class<?>[] getAnnotatedClasses() { | ||
return new Class<?>[] { | ||
POI.class | ||
}; | ||
} | ||
} |