本文整理汇总了Java中org.elasticsearch.common.geo.ShapeRelation类的典型用法代码示例。如果您正苦于以下问题:Java ShapeRelation类的具体用法?Java ShapeRelation怎么用?Java ShapeRelation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ShapeRelation类属于org.elasticsearch.common.geo包,在下文中一共展示了ShapeRelation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: GeoShapeQueryBuilder
import org.elasticsearch.common.geo.ShapeRelation; //导入依赖的package包/类
/**
* Read from a stream.
*/
public GeoShapeQueryBuilder(StreamInput in) throws IOException {
super(in);
fieldName = in.readString();
if (in.readBoolean()) {
shape = in.readNamedWriteable(ShapeBuilder.class);
indexedShapeId = null;
indexedShapeType = null;
} else {
shape = null;
indexedShapeId = in.readOptionalString();
indexedShapeType = in.readOptionalString();
indexedShapeIndex = in.readOptionalString();
indexedShapePath = in.readOptionalString();
}
relation = ShapeRelation.readFromStream(in);
strategy = in.readOptionalWriteable(SpatialStrategy::readFromStream);
ignoreUnmapped = in.readBoolean();
}
示例2: RangeQueryBuilder
import org.elasticsearch.common.geo.ShapeRelation; //导入依赖的package包/类
/**
* Read from a stream.
*/
public RangeQueryBuilder(StreamInput in) throws IOException {
super(in);
fieldName = in.readString();
from = in.readGenericValue();
to = in.readGenericValue();
includeLower = in.readBoolean();
includeUpper = in.readBoolean();
timeZone = in.readOptionalTimeZone();
String formatString = in.readOptionalString();
if (formatString != null) {
format = Joda.forPattern(formatString);
}
if (in.getVersion().onOrAfter(Version.V_5_2_0_UNRELEASED)) {
String relationString = in.readOptionalString();
if (relationString != null) {
relation = ShapeRelation.getRelationByName(relationString);
}
}
}
示例3: rangeQuery
import org.elasticsearch.common.geo.ShapeRelation; //导入依赖的package包/类
@Override
public Query rangeQuery(String field, Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper,
ShapeRelation relation, @Nullable DateTimeZone timeZone, @Nullable DateMathParser parser,
QueryShardContext context) {
DateTimeZone zone = (timeZone == null) ? DateTimeZone.UTC : timeZone;
DateMathParser dateMathParser = (parser == null) ?
new DateMathParser(DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER) : parser;
Long low = lowerTerm == null ? Long.MIN_VALUE :
dateMathParser.parse(lowerTerm instanceof BytesRef ? ((BytesRef) lowerTerm).utf8ToString() : lowerTerm.toString(),
context::nowInMillis, false, zone);
Long high = upperTerm == null ? Long.MAX_VALUE :
dateMathParser.parse(upperTerm instanceof BytesRef ? ((BytesRef) upperTerm).utf8ToString() : upperTerm.toString(),
context::nowInMillis, false, zone);
return super.rangeQuery(field, low, high, includeLower, includeUpper, relation, zone, dateMathParser, context);
}
示例4: testShapeFilterWithRandomGeoCollection
import org.elasticsearch.common.geo.ShapeRelation; //导入依赖的package包/类
public void testShapeFilterWithRandomGeoCollection() throws Exception {
// Create a random geometry collection.
GeometryCollectionBuilder gcb = RandomShapeGenerator.createGeometryCollection(random());
logger.info("Created Random GeometryCollection containing {} shapes", gcb.numShapes());
client().admin().indices().prepareCreate("test").addMapping("type", "location", "type=geo_shape,tree=quadtree")
.execute().actionGet();
XContentBuilder docSource = gcb.toXContent(jsonBuilder().startObject().field("location"), null).endObject();
client().prepareIndex("test", "type", "1").setSource(docSource).setRefreshPolicy(IMMEDIATE).get();
ShapeBuilder filterShape = (gcb.getShapeAt(randomIntBetween(0, gcb.numShapes() - 1)));
GeoShapeQueryBuilder filter = QueryBuilders.geoShapeQuery("location", filterShape);
filter.relation(ShapeRelation.INTERSECTS);
SearchResponse result = client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.matchAllQuery())
.setPostFilter(filter).get();
assertSearchResponse(result);
assertHitCount(result, 1);
}
示例5: testContainsShapeQuery
import org.elasticsearch.common.geo.ShapeRelation; //导入依赖的package包/类
public void testContainsShapeQuery() throws Exception {
// Create a random geometry collection.
Rectangle mbr = xRandomRectangle(random(), xRandomPoint(random()), true);
GeometryCollectionBuilder gcb = createGeometryCollectionWithin(random(), mbr);
client().admin().indices().prepareCreate("test").addMapping("type", "location", "type=geo_shape,tree=quadtree" )
.execute().actionGet();
XContentBuilder docSource = gcb.toXContent(jsonBuilder().startObject().field("location"), null).endObject();
client().prepareIndex("test", "type", "1").setSource(docSource).setRefreshPolicy(IMMEDIATE).get();
// index the mbr of the collection
EnvelopeBuilder env = new EnvelopeBuilder(new Coordinate(mbr.getMinX(), mbr.getMaxY()), new Coordinate(mbr.getMaxX(), mbr.getMinY()));
docSource = env.toXContent(jsonBuilder().startObject().field("location"), null).endObject();
client().prepareIndex("test", "type", "2").setSource(docSource).setRefreshPolicy(IMMEDIATE).get();
ShapeBuilder filterShape = (gcb.getShapeAt(randomIntBetween(0, gcb.numShapes() - 1)));
GeoShapeQueryBuilder filter = QueryBuilders.geoShapeQuery("location", filterShape)
.relation(ShapeRelation.CONTAINS);
SearchResponse response = client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.matchAllQuery())
.setPostFilter(filter).get();
assertSearchResponse(response);
assertThat(response.getHits().getTotalHits(), greaterThan(0L));
}
示例6: testGeoShape
import org.elasticsearch.common.geo.ShapeRelation; //导入依赖的package包/类
public void testGeoShape() throws IOException {
GeoShapeQueryBuilder qb = geoShapeQuery(
"pin.location",
ShapeBuilders.newMultiPoint(
new CoordinatesBuilder()
.coordinate(0, 0)
.coordinate(0, 10)
.coordinate(10, 10)
.coordinate(10, 0)
.coordinate(0, 0)
.build()));
qb.relation(ShapeRelation.WITHIN);
qb = geoShapeQuery(
"pin.location",
"DEU",
"countries");
qb.relation(ShapeRelation.WITHIN)
.indexedShapeIndex("shapes")
.indexedShapePath("location");
}
示例7: testRangeQuery
import org.elasticsearch.common.geo.ShapeRelation; //导入依赖的package包/类
public void testRangeQuery() throws Exception {
Settings indexSettings = Settings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(randomAsciiOfLengthBetween(1, 10), indexSettings);
QueryShardContext context = new QueryShardContext(0, idxSettings, null, null, null, null, null, xContentRegistry(),
null, null, () -> nowInMillis);
RangeFieldMapper.RangeFieldType ft = new RangeFieldMapper.RangeFieldType(type);
ft.setName(FIELDNAME);
ft.setIndexOptions(IndexOptions.DOCS);
ShapeRelation relation = RandomPicks.randomFrom(random(), ShapeRelation.values());
boolean includeLower = random().nextBoolean();
boolean includeUpper = random().nextBoolean();
Object from = nextFrom();
Object to = nextTo(from);
assertEquals(getExpectedRangeQuery(relation, from, to, includeLower, includeUpper),
ft.rangeQuery(from, to, includeLower, includeUpper, relation, context));
}
示例8: testSimple
import org.elasticsearch.common.geo.ShapeRelation; //导入依赖的package包/类
/**
* Create a simple heatmap over the indexed docs and verify that no cell has
* more than that number of docs
*/
public void testSimple() throws Exception {
EnvelopeBuilder env = new EnvelopeBuilder(new Coordinate(mbr.getMinX(), mbr.getMaxY()),
new Coordinate(mbr.getMaxX(), mbr.getMinY()));
GeoShapeQueryBuilder geo = QueryBuilders.geoShapeQuery("location", env).relation(ShapeRelation.WITHIN);
SearchResponse response2 = client().prepareSearch("idx")
.addAggregation(heatmap("heatmap1").geom(geo).field("location").gridLevel(7).maxCells(100)).execute().actionGet();
GeoHeatmap filter2 = response2.getAggregations().get("heatmap1");
assertThat(filter2, notNullValue());
assertThat(filter2.getName(), equalTo("heatmap1"));
int maxHeatmapValue = 0;
for (int i = 0; i < filter2.getCounts().length; i++) {
maxHeatmapValue = Math.max(maxHeatmapValue, filter2.getCounts()[i]);
}
assertTrue(maxHeatmapValue <= numTag1Docs);
}
示例9: getArgs
import org.elasticsearch.common.geo.ShapeRelation; //导入依赖的package包/类
public static SpatialArgs getArgs(ShapeBuilder shape, ShapeRelation relation) {
switch (relation) {
case DISJOINT:
return new SpatialArgs(SpatialOperation.IsDisjointTo, shape.build());
case INTERSECTS:
return new SpatialArgs(SpatialOperation.Intersects, shape.build());
case WITHIN:
return new SpatialArgs(SpatialOperation.IsWithin, shape.build());
case CONTAINS:
return new SpatialArgs(SpatialOperation.Contains, shape.build());
default:
throw new IllegalArgumentException("invalid relation [" + relation + "]");
}
}
示例10: testInvalidRelation
import org.elasticsearch.common.geo.ShapeRelation; //导入依赖的package包/类
public void testInvalidRelation() throws IOException {
ShapeBuilder shape = RandomShapeGenerator.createShapeWithin(random(), null);
GeoShapeQueryBuilder builder = new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, shape);
builder.strategy(SpatialStrategy.TERM);
expectThrows(IllegalArgumentException.class, () -> builder.relation(randomFrom(ShapeRelation.DISJOINT, ShapeRelation.WITHIN)));
GeoShapeQueryBuilder builder2 = new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, shape);
builder2.relation(randomFrom(ShapeRelation.DISJOINT, ShapeRelation.WITHIN));
expectThrows(IllegalArgumentException.class, () -> builder2.strategy(SpatialStrategy.TERM));
GeoShapeQueryBuilder builder3 = new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, shape);
builder3.strategy(SpatialStrategy.TERM);
expectThrows(IllegalArgumentException.class, () -> builder3.relation(randomFrom(ShapeRelation.DISJOINT, ShapeRelation.WITHIN)));
}
示例11: getExpectedRangeQuery
import org.elasticsearch.common.geo.ShapeRelation; //导入依赖的package包/类
private Query getExpectedRangeQuery(ShapeRelation relation, Object from, Object to, boolean includeLower, boolean includeUpper) {
switch (type) {
case DATE:
return getDateRangeQuery(relation, (DateTime)from, (DateTime)to, includeLower, includeUpper);
case INTEGER:
return getIntRangeQuery(relation, (int)from, (int)to, includeLower, includeUpper);
case LONG:
return getLongRangeQuery(relation, (long)from, (long)to, includeLower, includeUpper);
case DOUBLE:
return getDoubleRangeQuery(relation, (double)from, (double)to, includeLower, includeUpper);
default:
return getFloatRangeQuery(relation, (float)from, (float)to, includeLower, includeUpper);
}
}
示例12: getIntRangeQuery
import org.elasticsearch.common.geo.ShapeRelation; //导入依赖的package包/类
private Query getIntRangeQuery(ShapeRelation relation, int from, int to, boolean includeLower, boolean includeUpper) {
int[] lower = new int[] {from + (includeLower ? 0 : 1)};
int[] upper = new int[] {to - (includeUpper ? 0 : 1)};
if (relation == ShapeRelation.WITHIN) {
return IntRangeField.newWithinQuery(FIELDNAME, lower, upper);
} else if (relation == ShapeRelation.CONTAINS) {
return IntRangeField.newContainsQuery(FIELDNAME, lower, upper);
}
return IntRangeField.newIntersectsQuery(FIELDNAME, lower, upper);
}
示例13: getLongRangeQuery
import org.elasticsearch.common.geo.ShapeRelation; //导入依赖的package包/类
private Query getLongRangeQuery(ShapeRelation relation, long from, long to, boolean includeLower, boolean includeUpper) {
long[] lower = new long[] {from + (includeLower ? 0 : 1)};
long[] upper = new long[] {to - (includeUpper ? 0 : 1)};
if (relation == ShapeRelation.WITHIN) {
return LongRangeField.newWithinQuery(FIELDNAME, lower, upper);
} else if (relation == ShapeRelation.CONTAINS) {
return LongRangeField.newContainsQuery(FIELDNAME, lower, upper);
}
return LongRangeField.newIntersectsQuery(FIELDNAME, lower, upper);
}
示例14: getFloatRangeQuery
import org.elasticsearch.common.geo.ShapeRelation; //导入依赖的package包/类
private Query getFloatRangeQuery(ShapeRelation relation, float from, float to, boolean includeLower, boolean includeUpper) {
float[] lower = new float[] {includeLower ? from : Math.nextUp(from)};
float[] upper = new float[] {includeUpper ? to : Math.nextDown(to)};
if (relation == ShapeRelation.WITHIN) {
return FloatRangeField.newWithinQuery(FIELDNAME, lower, upper);
} else if (relation == ShapeRelation.CONTAINS) {
return FloatRangeField.newContainsQuery(FIELDNAME, lower, upper);
}
return FloatRangeField.newIntersectsQuery(FIELDNAME, lower, upper);
}
示例15: getDoubleRangeQuery
import org.elasticsearch.common.geo.ShapeRelation; //导入依赖的package包/类
private Query getDoubleRangeQuery(ShapeRelation relation, double from, double to, boolean includeLower, boolean includeUpper) {
double[] lower = new double[] {includeLower ? from : Math.nextUp(from)};
double[] upper = new double[] {includeUpper ? to : Math.nextDown(to)};
if (relation == ShapeRelation.WITHIN) {
return DoubleRangeField.newWithinQuery(FIELDNAME, lower, upper);
} else if (relation == ShapeRelation.CONTAINS) {
return DoubleRangeField.newContainsQuery(FIELDNAME, lower, upper);
}
return DoubleRangeField.newIntersectsQuery(FIELDNAME, lower, upper);
}