mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 02:14:54 +00:00
parent
51179f162a
commit
5bea3898a9
@ -19,8 +19,10 @@
|
||||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.apache.lucene.document.LatLonDocValuesField;
|
||||
import org.apache.lucene.document.LatLonPoint;
|
||||
import org.apache.lucene.geo.Polygon;
|
||||
import org.apache.lucene.search.IndexOrDocValuesQuery;
|
||||
import org.apache.lucene.search.MatchNoDocsQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
@ -199,7 +201,13 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder<GeoPolygonQuery
|
||||
lons[i] = p.lon();
|
||||
}
|
||||
|
||||
return LatLonPoint.newPolygonQuery(fieldType.name(), new Polygon(lats, lons));
|
||||
Polygon polygon = new Polygon(lats, lons);
|
||||
Query query = LatLonPoint.newPolygonQuery(fieldType.name(), polygon);
|
||||
if (fieldType.hasDocValues()) {
|
||||
Query dvQuery = LatLonDocValuesField.newSlowPolygonQuery(fieldType.name(), polygon);
|
||||
query = new IndexOrDocValuesQuery(query, dvQuery);
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,11 +19,15 @@
|
||||
|
||||
package org.elasticsearch.index.query;
|
||||
|
||||
import org.apache.lucene.document.LatLonDocValuesField;
|
||||
import org.apache.lucene.document.LatLonPoint;
|
||||
import org.apache.lucene.search.IndexOrDocValuesQuery;
|
||||
import org.apache.lucene.search.MatchNoDocsQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
import org.elasticsearch.test.AbstractQueryTestCase;
|
||||
import org.elasticsearch.test.geo.RandomShapeGenerator;
|
||||
import org.elasticsearch.test.geo.RandomShapeGenerator.ShapeType;
|
||||
@ -53,12 +57,30 @@ public class GeoPolygonQueryBuilderTests extends AbstractQueryTestCase<GeoPolygo
|
||||
if (randomBoolean()) {
|
||||
builder.ignoreUnmapped(randomBoolean());
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doAssertLuceneQuery(GeoPolygonQueryBuilder queryBuilder, Query query, QueryShardContext context) throws IOException {
|
||||
// todo LatLonPointInPolygon is package private
|
||||
MappedFieldType fieldType = context.fieldMapper(queryBuilder.fieldName());
|
||||
if (fieldType == null) {
|
||||
assertTrue("Found no indexed geo query.", query instanceof MatchNoDocsQuery);
|
||||
} else { // TODO: Test case when there are no docValues
|
||||
Query indexQuery = ((IndexOrDocValuesQuery) query).getIndexQuery();
|
||||
String expectedFieldName = expectedFieldName(queryBuilder.fieldName());
|
||||
List<GeoPoint> points = queryBuilder.points();
|
||||
double[] lats = new double[points.size()];
|
||||
double[] lons = new double[points.size()];
|
||||
for (int i =0; i < points.size(); i++) {
|
||||
lats[i] = points.get(i).getLat();
|
||||
lons[i] = points.get(i).getLon();
|
||||
}
|
||||
org.apache.lucene.geo.Polygon polygon = new org.apache.lucene.geo.Polygon(lats, lons);
|
||||
assertEquals(LatLonPoint.newPolygonQuery(expectedFieldName, polygon), indexQuery);
|
||||
Query dvQuery = ((IndexOrDocValuesQuery) query).getRandomAccessQuery();
|
||||
assertEquals(LatLonDocValuesField.newSlowPolygonQuery(expectedFieldName, polygon), dvQuery);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<GeoPoint> randomPolygon() {
|
||||
@ -196,9 +218,8 @@ public class GeoPolygonQueryBuilderTests extends AbstractQueryTestCase<GeoPolygo
|
||||
|
||||
private void assertGeoPolygonQuery(String query) throws IOException {
|
||||
QueryShardContext context = createShardContext();
|
||||
parseQuery(query).toQuery(context);
|
||||
// TODO LatLonPointInPolygon is package private, need a closeTo check on the query
|
||||
// since some points can be computed from the geohash
|
||||
GeoPolygonQueryBuilder queryBuilder = (GeoPolygonQueryBuilder) parseQuery(query);
|
||||
doAssertLuceneQuery(queryBuilder, queryBuilder.toQuery(context), context);
|
||||
}
|
||||
|
||||
public void testFromJson() throws IOException {
|
||||
|
Loading…
x
Reference in New Issue
Block a user