Search in sources :

Example 1 with LatLng

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());
}
Also used : SearchServer(com.rbmhtechnology.vind.api.SearchServer) SearchResult(com.rbmhtechnology.vind.api.result.SearchResult) LatLng(com.rbmhtechnology.vind.model.value.LatLng) MultiValueFieldDescriptor(com.rbmhtechnology.vind.model.MultiValueFieldDescriptor) Document(com.rbmhtechnology.vind.api.Document) SolrInputDocument(org.apache.solr.common.SolrInputDocument) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) Test(org.junit.Test)

Aggregations

Document (com.rbmhtechnology.vind.api.Document)1 SearchServer (com.rbmhtechnology.vind.api.SearchServer)1 FulltextSearch (com.rbmhtechnology.vind.api.query.FulltextSearch)1 SearchResult (com.rbmhtechnology.vind.api.result.SearchResult)1 MultiValueFieldDescriptor (com.rbmhtechnology.vind.model.MultiValueFieldDescriptor)1 LatLng (com.rbmhtechnology.vind.model.value.LatLng)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 Test (org.junit.Test)1