use of org.apache.lucene.spatial.prefix.tree.QuadPrefixTree in project lucene-solr by apache.
the class DistanceStrategyTest method parameters.
@ParametersFactory(argumentFormatting = "strategy=%s")
public static Iterable<Object[]> parameters() {
List<Object[]> ctorArgs = new ArrayList<>();
SpatialContext ctx = SpatialContext.GEO;
SpatialPrefixTree grid;
SpatialStrategy strategy;
grid = new QuadPrefixTree(ctx, 25);
strategy = new RecursivePrefixTreeStrategy(grid, "recursive_quad");
ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
grid = new GeohashPrefixTree(ctx, 12);
strategy = new TermQueryPrefixTreeStrategy(grid, "termquery_geohash");
ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
grid = new PackedQuadPrefixTree(ctx, 25);
strategy = new RecursivePrefixTreeStrategy(grid, "recursive_packedquad");
ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
strategy = PointVectorStrategy.newInstance(ctx, "pointvector");
ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
// Can't test this without un-inverting since PVS legacy config didn't have docValues.
// However, note that Solr's tests use UninvertingReader and thus test this.
// strategy = PointVectorStrategy.newLegacyInstance(ctx, "pointvector_legacy");
// ctorArgs.add(new Object[]{strategy.getFieldName(), strategy});
strategy = BBoxStrategy.newInstance(ctx, "bbox");
ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
strategy = new SerializedDVStrategy(ctx, "serialized");
ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
return ctorArgs;
}
use of org.apache.lucene.spatial.prefix.tree.QuadPrefixTree in project lucene-solr by apache.
the class RandomSpatialOpFuzzyPrefixTreeTest method setupQuadGrid.
private void setupQuadGrid(int maxLevels, boolean packedQuadPrefixTree) {
//non-geospatial makes this test a little easier (in gridSnap), and using boundary values 2^X raises
// the prospect of edge conditions we want to test, plus makes for simpler numbers (no decimals).
SpatialContextFactory factory = new SpatialContextFactory();
factory.geo = false;
factory.worldBounds = new RectangleImpl(0, 256, -128, 128, null);
this.ctx = factory.newSpatialContext();
//A fairly shallow grid, and default 2.5% distErrPct
if (maxLevels == -1)
//max 64k cells (4^8), also 256*256
maxLevels = randomIntBetween(1, 8);
if (packedQuadPrefixTree) {
this.grid = new PackedQuadPrefixTree(ctx, maxLevels);
} else {
this.grid = new QuadPrefixTree(ctx, maxLevels);
}
this.strategy = newRPT();
}
use of org.apache.lucene.spatial.prefix.tree.QuadPrefixTree in project lucene-solr by apache.
the class HeatmapFacetCounterTest method testQueryCircle.
@Test
public void testQueryCircle() throws IOException {
//overwrite setUp; non-geo bounds is more straight-forward; otherwise 88,88 would actually be practically north,
final SpatialContextFactory spatialContextFactory = new SpatialContextFactory();
spatialContextFactory.geo = false;
spatialContextFactory.worldBounds = new RectangleImpl(-90, 90, -90, 90, null);
ctx = spatialContextFactory.newSpatialContext();
final int LEVEL = 4;
grid = new QuadPrefixTree(ctx, LEVEL);
strategy = new RecursivePrefixTreeStrategy(grid, getTestClass().getSimpleName());
Circle circle = ctx.makeCircle(0, 0, 89);
//top-right, inside bbox of circle but not the circle
adoc("0", ctx.makePoint(88, 88));
//clearly inside; dead center in fact
adoc("1", ctx.makePoint(0, 0));
commit();
final HeatmapFacetCounter.Heatmap heatmap = HeatmapFacetCounter.calcFacets((PrefixTreeStrategy) strategy, indexSearcher.getTopReaderContext(), null, circle, LEVEL, 1000);
//assert that only one point is found, not 2
boolean foundOne = false;
for (int count : heatmap.counts) {
switch(count) {
case 0:
break;
case 1:
//this is the first
assertFalse(foundOne);
foundOne = true;
break;
default:
fail("counts should be 0 or 1: " + count);
}
}
assertTrue(foundOne);
}
use of org.apache.lucene.spatial.prefix.tree.QuadPrefixTree in project lucene-solr by apache.
the class JtsPolygonTest method testBadPrefixTreePrune.
/**
* A PrefixTree pruning optimization gone bad.
* See <a href="https://issues.apache.org/jira/browse/LUCENE-4770">LUCENE-4770</a>.
*/
@Test
public void testBadPrefixTreePrune() throws Exception {
Shape area = ctx.readShapeFromWkt("POLYGON((-122.83 48.57, -122.77 48.56, -122.79 48.53, -122.83 48.57))");
SpatialPrefixTree trie = new QuadPrefixTree(ctx, 12);
TermQueryPrefixTreeStrategy strategy = new TermQueryPrefixTreeStrategy(trie, "geo");
Document doc = new Document();
doc.add(new TextField("id", "1", Store.YES));
Field[] fields = strategy.createIndexableFields(area, 0.025);
for (Field field : fields) {
doc.add(field);
}
addDocument(doc);
Point upperleft = ctx.makePoint(-122.88, 48.54);
Point lowerright = ctx.makePoint(-122.82, 48.62);
Query query = strategy.makeQuery(new SpatialArgs(SpatialOperation.Intersects, ctx.makeRectangle(upperleft, lowerright)));
commit();
TopDocs search = indexSearcher.search(query, 10);
ScoreDoc[] scoreDocs = search.scoreDocs;
for (ScoreDoc scoreDoc : scoreDocs) {
System.out.println(indexSearcher.doc(scoreDoc.doc));
}
assertEquals(1, search.totalHits);
}
use of org.apache.lucene.spatial.prefix.tree.QuadPrefixTree in project lucene-solr by apache.
the class TestTermQueryPrefixGridStrategy method testNGramPrefixGridLosAngeles.
@Test
public void testNGramPrefixGridLosAngeles() throws IOException {
SpatialContext ctx = SpatialContext.GEO;
TermQueryPrefixTreeStrategy prefixGridStrategy = new TermQueryPrefixTreeStrategy(new QuadPrefixTree(ctx), "geo");
Shape point = ctx.makePoint(-118.243680, 34.052230);
Document losAngeles = new Document();
losAngeles.add(new StringField("name", "Los Angeles", Field.Store.YES));
for (Field field : prefixGridStrategy.createIndexableFields(point)) {
losAngeles.add(field);
}
//just for diagnostics
losAngeles.add(new StoredField(prefixGridStrategy.getFieldName(), point.toString()));
addDocumentsAndCommit(Arrays.asList(losAngeles));
// This won't work with simple spatial context...
SpatialArgsParser spatialArgsParser = new SpatialArgsParser();
// TODO... use a non polygon query
// SpatialArgs spatialArgs = spatialArgsParser.parse(
// "Intersects(POLYGON((-127.00390625 39.8125,-112.765625 39.98828125,-111.53515625 31.375,-125.94921875 30.14453125,-127.00390625 39.8125)))",
// new SimpleSpatialContext());
// Query query = prefixGridStrategy.makeQuery(spatialArgs, fieldInfo);
// SearchResults searchResults = executeQuery(query, 1);
// assertEquals(1, searchResults.numFound);
}
Aggregations