use of com.rbmhtechnology.vind.model.value.LatLng in project vind by RBMHTechnology.
the class TestServerTest method testLocationDescriptor.
@Test
public void testLocationDescriptor() {
SingleValueFieldDescriptor.LocationFieldDescriptor<LatLng> locationSingle = new FieldDescriptorBuilder().setFacet(true).buildLocationField("locationSingle");
MultiValueFieldDescriptor.LocationFieldDescriptor<LatLng> locationMulti = new FieldDescriptorBuilder().setFacet(true).buildMultivaluedLocationField("locationMulti");
DocumentFactory assets = new DocumentFactoryBuilder("asset").addField(locationSingle).addField(locationMulti).build();
Document doc1 = assets.createDoc("1").setValue(locationSingle, new LatLng(10, 10)).setValues(locationMulti, new LatLng(15, 15));
Document doc2 = assets.createDoc("2").setValue(locationSingle, new LatLng(20, 20)).setValues(locationMulti, new LatLng(11, 11));
Document doc3 = assets.createDoc("3").setValues(locationMulti, new LatLng(10, 10), new LatLng(20, 20));
SearchServer server = testSearchServer.getSearchServer();
server.index(doc1);
server.index(doc2);
server.index(doc3);
server.commit();
// test bbox filter
FulltextSearch searchAll = Search.fulltext().filter(locationSingle.withinBBox(new LatLng(10, 10), new LatLng(11, 1)));
SearchResult searchResult = server.execute(searchAll, assets).print();
assertEquals("LatLng filter 'within' does not filter properly single value fields", 1, searchResult.getNumOfResults());
// test bbox filter multivalue
searchAll = Search.fulltext().filter(locationMulti.withinBBox(new LatLng(10, 10), new LatLng(12, 12)));
searchResult = server.execute(searchAll, assets).print();
assertEquals("LatLng filter 'within' does not filter properly mutivalue fields", 2, searchResult.getNumOfResults());
// test circle filter
searchAll = Search.fulltext().filter(locationSingle.withinCircle(new LatLng(10, 10), 1));
searchResult = server.execute(searchAll, assets).print();
assertEquals("LatLng filter 'within' does not filter properly singlevalue fields", 1, searchResult.getNumOfResults());
searchAll = Search.fulltext().filter(locationMulti.withinCircle(new LatLng(10, 10), 160));
searchResult = server.execute(searchAll, assets).print();
assertEquals("LatLng filter 'within' does not filter properly singlevalue fields", 2, searchResult.getNumOfResults());
// test retrieving geodist
// TODO this feature is a little hacky, but should be easy to clean uo
searchAll = Search.fulltext().geoDistance(locationSingle, new LatLng(5, 5));
searchResult = server.execute(searchAll, assets).print();
assertEquals("Distance is not appended to results", 782.78015, searchResult.getResults().get(0).getDistance(), 0.001);
// test sorting
// TODO does not yet work (parsing error)
searchAll = Search.fulltext().sort(Sort.SpecialSort.distance()).geoDistance(locationSingle, new LatLng(30, 30));
;
searchResult = server.execute(searchAll, assets).print();
assertTrue("Distance sorting is not correct", searchResult.getResults().get(0).getDistance() < searchResult.getResults().get(1).getDistance());
}
Aggregations