Example usage for org.apache.lucene.spatial.prefix PrefixTreeStrategy getDistErrPct

List of usage examples for org.apache.lucene.spatial.prefix PrefixTreeStrategy getDistErrPct

Introduction

In this page you can find the example usage for org.apache.lucene.spatial.prefix PrefixTreeStrategy getDistErrPct.

Prototype

public double getDistErrPct() 

Source Link

Usage

From source file:org.elasticsearch.index.mapper.geo.GeoShapeFieldMapperTests.java

License:Apache License

@Test
public void testDefaultConfiguration() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
            .startObject("location").field("type", "geo_shape").endObject().endObject().endObject().endObject()
            .string();/*from   w w  w .j  ava2  s  . c o  m*/

    DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
    FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
    assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

    GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
    PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

    assertThat(strategy.getDistErrPct(), equalTo(GeoShapeFieldMapper.Defaults.DISTANCE_ERROR_PCT));
    assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
    assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoShapeFieldMapper.Defaults.GEOHASH_LEVELS));
}

From source file:org.elasticsearch.index.mapper.geo.GeoShapeFieldMapperTests.java

License:Apache License

@Test
public void testGeohashConfiguration() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
            .startObject("location").field("type", "geo_shape").field("tree", "geohash")
            .field("tree_levels", "4").field("distance_error_pct", "0.1").endObject().endObject().endObject()
            .endObject().string();/*from   w w  w.  j a va  2  s  .  c  om*/

    DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
    FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
    assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

    GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
    PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

    assertThat(strategy.getDistErrPct(), equalTo(0.1));
    assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
    assertThat(strategy.getGrid().getMaxLevels(), equalTo(4));
}

From source file:org.elasticsearch.index.mapper.geo.GeoShapeFieldMapperTests.java

License:Apache License

@Test
public void testQuadtreeConfiguration() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
            .startObject("location").field("type", "geo_shape").field("tree", "quadtree")
            .field("tree_levels", "6").field("distance_error_pct", "0.5").endObject().endObject().endObject()
            .endObject().string();//from  ww w  . jav a  2 s.co  m

    DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
    FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
    assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

    GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
    PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

    assertThat(strategy.getDistErrPct(), equalTo(0.5));
    assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
    assertThat(strategy.getGrid().getMaxLevels(), equalTo(6));
}

From source file:org.elasticsearch.index.mapper.geo.GeoShapeFieldMapperTests.java

License:Apache License

@Test
public void testLevelPrecisionConfiguration() throws IOException {
    {//from ww w. j  ava2 s. co  m
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "quadtree").field("tree_levels", "6").field("precision", "70m")
                .field("distance_error_pct", "0.5").endObject().endObject().endObject().endObject().string();

        DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
        FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
        /* 70m is more precise so it wins */
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.quadTreeLevelsForPrecision(70d)));
    }

    {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "geohash").field("tree_levels", "6").field("precision", "70m")
                .field("distance_error_pct", "0.5").endObject().endObject().endObject().endObject().string();

        DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
        FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
        /* 70m is more precise so it wins */
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.geoHashLevelsForPrecision(70d)));
    }

    {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "geohash").field("tree_levels", GeoUtils.geoHashLevelsForPrecision(70d) + 1)
                .field("precision", "70m").field("distance_error_pct", "0.5").endObject().endObject()
                .endObject().endObject().string();

        DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
        FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.geoHashLevelsForPrecision(70d) + 1));
    }

    {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "quadtree").field("tree_levels", GeoUtils.quadTreeLevelsForPrecision(70d) + 1)
                .field("precision", "70m").field("distance_error_pct", "0.5").endObject().endObject()
                .endObject().endObject().string();

        DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
        FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.quadTreeLevelsForPrecision(70d) + 1));
    }
}

From source file:org.elasticsearch.index.mapper.geo.GeoShapeFieldMapperTests.java

License:Apache License

@Test
public void testLevelDefaults() throws IOException {
    {// w  ww. j a  v  a  2 s  . c o  m
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "quadtree").field("distance_error_pct", "0.5").endObject().endObject()
                .endObject().endObject().string();

        DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
        FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
        /* 50m is default */
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.quadTreeLevelsForPrecision(50d)));
    }

    {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "geohash").field("distance_error_pct", "0.5").endObject().endObject().endObject()
                .endObject().string();

        DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
        FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
        /* 50m is default */
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.geoHashLevelsForPrecision(50d)));
    }
}

From source file:org.elasticsearch.index.mapper.GeoShapeFieldMapperTests.java

License:Apache License

public void testDefaultConfiguration() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
            .startObject("location").field("type", "geo_shape").endObject().endObject().endObject().endObject()
            .string();//  ww w.j  a  v  a  2s .c  o  m

    DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1",
            new CompressedXContent(mapping));
    FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
    assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

    GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
    PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();

    assertThat(strategy.getDistErrPct(), equalTo(0.025d));
    assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
    assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoShapeFieldMapper.Defaults.GEOHASH_LEVELS));
    assertThat(geoShapeFieldMapper.fieldType().orientation(),
            equalTo(GeoShapeFieldMapper.Defaults.ORIENTATION));
}

From source file:org.elasticsearch.index.mapper.GeoShapeFieldMapperTests.java

License:Apache License

public void testGeohashConfiguration() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
            .startObject("location").field("type", "geo_shape").field("tree", "geohash")
            .field("tree_levels", "4").field("distance_error_pct", "0.1").endObject().endObject().endObject()
            .endObject().string();//from   www  .  j a  v a 2  s.  c om

    DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1",
            new CompressedXContent(mapping));
    FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
    assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

    GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
    PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();

    assertThat(strategy.getDistErrPct(), equalTo(0.1));
    assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
    assertThat(strategy.getGrid().getMaxLevels(), equalTo(4));
}

From source file:org.elasticsearch.index.mapper.GeoShapeFieldMapperTests.java

License:Apache License

public void testQuadtreeConfiguration() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
            .startObject("location").field("type", "geo_shape").field("tree", "quadtree")
            .field("tree_levels", "6").field("distance_error_pct", "0.5").field("points_only", true).endObject()
            .endObject().endObject().endObject().string();

    DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1",
            new CompressedXContent(mapping));
    FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
    assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

    GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
    PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();

    assertThat(strategy.getDistErrPct(), equalTo(0.5));
    assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
    assertThat(strategy.getGrid().getMaxLevels(), equalTo(6));
    assertThat(strategy.isPointsOnly(), equalTo(true));
}

From source file:org.elasticsearch.index.mapper.GeoShapeFieldMapperTests.java

License:Apache License

public void testLevelPrecisionConfiguration() throws IOException {
    DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();

    {/*from w w  w.ja  v  a 2 s  .  co m*/
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "quadtree").field("tree_levels", "6").field("precision", "70m")
                .field("distance_error_pct", "0.5").endObject().endObject().endObject().endObject().string();

        DocumentMapper defaultMapper = parser.parse("type1", new CompressedXContent(mapping));
        FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
        // 70m is more precise so it wins
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.quadTreeLevelsForPrecision(70d)));
    }

    {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "quadtree").field("tree_levels", "26").field("precision", "70m").endObject()
                .endObject().endObject().endObject().string();

        DocumentMapper defaultMapper = parser.parse("type1", new CompressedXContent(mapping));
        FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();

        // distance_error_pct was not specified so we expect the mapper to take the highest precision between "precision" and
        // "tree_levels" setting distErrPct to 0 to guarantee desired precision
        assertThat(strategy.getDistErrPct(), equalTo(0.0));
        assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
        // 70m is less precise so it loses
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(26));
    }

    {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "geohash").field("tree_levels", "6").field("precision", "70m")
                .field("distance_error_pct", "0.5").endObject().endObject().endObject().endObject().string();

        DocumentMapper defaultMapper = parser.parse("type1", new CompressedXContent(mapping));
        FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
        // 70m is more precise so it wins
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.geoHashLevelsForPrecision(70d)));
    }

    {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "geohash").field("tree_levels", GeoUtils.geoHashLevelsForPrecision(70d) + 1)
                .field("precision", "70m").field("distance_error_pct", "0.5").endObject().endObject()
                .endObject().endObject().string();

        DocumentMapper defaultMapper = parser.parse("type1", new CompressedXContent(mapping));
        FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.geoHashLevelsForPrecision(70d) + 1));
    }

    {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "quadtree").field("tree_levels", GeoUtils.quadTreeLevelsForPrecision(70d) + 1)
                .field("precision", "70m").field("distance_error_pct", "0.5").endObject().endObject()
                .endObject().endObject().string();

        DocumentMapper defaultMapper = parser.parse("type1", new CompressedXContent(mapping));
        FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.quadTreeLevelsForPrecision(70d) + 1));
    }
}

From source file:org.elasticsearch.index.mapper.GeoShapeFieldMapperTests.java

License:Apache License

public void testLevelDefaults() throws IOException {
    DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
    {//ww w. j  a v  a2s.c  om
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "quadtree").field("distance_error_pct", "0.5").endObject().endObject()
                .endObject().endObject().string();

        DocumentMapper defaultMapper = parser.parse("type1", new CompressedXContent(mapping));
        FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
        /* 50m is default */
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.quadTreeLevelsForPrecision(50d)));
    }

    {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "geohash").field("distance_error_pct", "0.5").endObject().endObject().endObject()
                .endObject().string();

        DocumentMapper defaultMapper = parser.parse("type1", new CompressedXContent(mapping));
        FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
        /* 50m is default */
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.geoHashLevelsForPrecision(50d)));
    }
}