Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cbuescher committed Jan 16, 2025
1 parent d727818 commit 53bab11
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 109 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@
*/
package org.elasticsearch.xpack.spatial.index.mapper;

import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.TotalHits;
import org.apache.lucene.store.Directory;
import org.apache.lucene.tests.index.RandomIndexWriter;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.geo.GeoJson;
import org.elasticsearch.common.geo.Orientation;
import org.elasticsearch.common.geo.ShapeRelation;
import org.elasticsearch.common.geo.SpatialStrategy;
import org.elasticsearch.geo.GeometryTestUtils;
import org.elasticsearch.geometry.Circle;
import org.elasticsearch.geometry.Geometry;
import org.elasticsearch.geometry.MultiPoint;
import org.elasticsearch.geometry.Point;
Expand All @@ -27,12 +33,14 @@
import org.elasticsearch.index.mapper.AbstractShapeGeometryFieldMapper.AbstractShapeGeometryFieldType;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentParsingException;
import org.elasticsearch.index.mapper.LuceneDocument;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.index.query.GeoShapeQueryBuilder;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.legacygeo.mapper.LegacyGeoShapeFieldMapper;
import org.elasticsearch.legacygeo.mapper.LegacyGeoShapeFieldMapper.GeoShapeFieldType;
Expand Down Expand Up @@ -390,6 +398,38 @@ public void testGeoShapeLegacyMerge() throws Exception {
assertFieldWarnings("strategy");
}

public void testGeoShapeLegacyCircle() throws Exception {
IndexVersion version = IndexVersionUtils.randomPreviousCompatibleVersion(random(), IndexVersions.V_8_0_0);
MapperService mapperService = createMapperService(version, fieldMapping(b -> {
b.field("type", getFieldName());
b.field("strategy", "recursive");
b.field("tree", "geohash");
}));
assertCriticalWarnings(
"Parameter [strategy] is deprecated and will be removed in a future version",
"Parameter [tree] is deprecated and will be removed in a future version"
);

try (Directory directory = newDirectory()) {
RandomIndexWriter iw = new RandomIndexWriter(random(), directory);
Circle circle = new Circle(30, 50, 77000);

LuceneDocument doc = mapperService.documentMapper().parse(source(b -> {
b.field("field");
GeoJson.toXContent(circle, b, null);
})).rootDoc();
iw.addDocument(doc);
iw.close();
try (DirectoryReader reader = DirectoryReader.open(directory)) {
SearchExecutionContext context = createSearchExecutionContext(mapperService, newSearcher(reader));
GeoShapeQueryBuilder queryBuilder = new GeoShapeQueryBuilder("field", new Circle(30, 50, 77000));
TopDocs docs = context.searcher().search(queryBuilder.toQuery(context), 1);
assertThat(docs.totalHits.value(), equalTo(1L));
assertThat(docs.totalHits.relation(), equalTo(TotalHits.Relation.EQUAL_TO));
}
}
}

private void assertFieldWarnings(String... fieldNames) {
String[] warnings = new String[fieldNames.length];
for (int i = 0; i < fieldNames.length; ++i) {
Expand Down

0 comments on commit 53bab11

Please sign in to comment.