test fixes
This commit is contained in:
parent
8d488c5088
commit
f1da2bb54c
|
@ -23,6 +23,7 @@ import com.spatial4j.core.context.SpatialContext;
|
||||||
import com.spatial4j.core.distance.DistanceUtils;
|
import com.spatial4j.core.distance.DistanceUtils;
|
||||||
import com.spatial4j.core.exception.InvalidShapeException;
|
import com.spatial4j.core.exception.InvalidShapeException;
|
||||||
import com.spatial4j.core.shape.Shape;
|
import com.spatial4j.core.shape.Shape;
|
||||||
|
|
||||||
import org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy;
|
import org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy;
|
||||||
import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree;
|
import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree;
|
||||||
import org.apache.lucene.spatial.query.SpatialArgs;
|
import org.apache.lucene.spatial.query.SpatialArgs;
|
||||||
|
@ -43,8 +44,8 @@ import org.elasticsearch.common.geo.builders.PolygonBuilder;
|
||||||
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
||||||
import org.elasticsearch.common.io.Streams;
|
import org.elasticsearch.common.io.Streams;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
|
||||||
import org.elasticsearch.index.query.GeohashCellQuery;
|
import org.elasticsearch.index.query.GeohashCellQuery;
|
||||||
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
import org.elasticsearch.search.SearchHit;
|
import org.elasticsearch.search.SearchHit;
|
||||||
import org.elasticsearch.test.ESIntegTestCase;
|
import org.elasticsearch.test.ESIntegTestCase;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -56,7 +57,6 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -65,9 +65,19 @@ import java.util.Random;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
import static org.elasticsearch.index.query.QueryBuilders.geoBoundingBoxQuery;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
|
import static org.elasticsearch.index.query.QueryBuilders.geoDistanceQuery;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.elasticsearch.index.query.QueryBuilders.geoHashCellQuery;
|
||||||
|
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||||
|
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
||||||
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFirstHit;
|
||||||
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||||
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits;
|
||||||
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasId;
|
||||||
|
import static org.hamcrest.Matchers.anyOf;
|
||||||
|
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -506,34 +516,28 @@ public class GeoFilterIT extends ESIntegTestCase {
|
||||||
|
|
||||||
expectedCounts.put(geoHashCellQuery("pin", point).neighbors(true).precision(precision), 1L + neighbors.size());
|
expectedCounts.put(geoHashCellQuery("pin", point).neighbors(true).precision(precision), 1L + neighbors.size());
|
||||||
|
|
||||||
logger.info("random testing of setting");
|
|
||||||
|
|
||||||
List<GeohashCellQuery.Builder> filterBuilders = new ArrayList<>(expectedCounts.keySet());
|
List<GeohashCellQuery.Builder> filterBuilders = new ArrayList<>(expectedCounts.keySet());
|
||||||
for (int j = filterBuilders.size() * 2 * randomIntBetween(1, 5); j > 0; j--) {
|
for (GeohashCellQuery.Builder builder : filterBuilders) {
|
||||||
Collections.shuffle(filterBuilders, getRandom());
|
try {
|
||||||
for (GeohashCellQuery.Builder builder : filterBuilders) {
|
long expectedCount = expectedCounts.get(builder);
|
||||||
try {
|
SearchResponse response = client().prepareSearch("locations").setQuery(QueryBuilders.matchAllQuery())
|
||||||
long expectedCount = expectedCounts.get(builder);
|
.setPostFilter(builder).setSize((int) expectedCount).get();
|
||||||
SearchResponse response = client().prepareSearch("locations").setQuery(QueryBuilders.matchAllQuery())
|
assertHitCount(response, expectedCount);
|
||||||
.setPostFilter(builder).setSize((int) expectedCount).get();
|
String[] expectedIds = expectedResults.get(builder);
|
||||||
assertHitCount(response, expectedCount);
|
if (expectedIds == null) {
|
||||||
String[] expectedIds = expectedResults.get(builder);
|
ArrayList<String> ids = new ArrayList<>();
|
||||||
if (expectedIds == null) {
|
for (SearchHit hit : response.getHits()) {
|
||||||
ArrayList<String> ids = new ArrayList<>();
|
ids.add(hit.id());
|
||||||
for (SearchHit hit : response.getHits()) {
|
|
||||||
ids.add(hit.id());
|
|
||||||
}
|
|
||||||
expectedResults.put(builder, ids.toArray(Strings.EMPTY_ARRAY));
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
expectedResults.put(builder, ids.toArray(Strings.EMPTY_ARRAY));
|
||||||
assertSearchHits(response, expectedIds);
|
continue;
|
||||||
|
|
||||||
} catch (AssertionError error) {
|
|
||||||
throw new AssertionError(error.getMessage() + "\n geohash_cell filter:" + builder, error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assertSearchHits(response, expectedIds);
|
||||||
|
|
||||||
|
} catch (AssertionError error) {
|
||||||
|
throw new AssertionError(error.getMessage() + "\n geohash_cell filter:" + builder, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// NORELEASE these should be tested in GeohashCellQueryBuilderTests
|
// NORELEASE these should be tested in GeohashCellQueryBuilderTests
|
||||||
|
|
Loading…
Reference in New Issue