use of org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree in project lucene-solr by apache.
the class CompositeSpatialStrategy method makeQuery.
@Override
public Query makeQuery(SpatialArgs args) {
final SpatialOperation pred = args.getOperation();
if (pred == SpatialOperation.BBoxIntersects || pred == SpatialOperation.BBoxWithin) {
throw new UnsupportedSpatialOperation(pred);
}
if (pred == SpatialOperation.IsDisjointTo) {
// update class docs when it's added.
throw new UnsupportedSpatialOperation(pred);
}
final ShapePredicateValueSource predicateValueSource = new ShapePredicateValueSource(geometryStrategy.makeShapeValueSource(), pred, args.getShape());
//System.out.println("PredOpt: " + optimizePredicates);
if (pred == SpatialOperation.Intersects && optimizePredicates) {
// We have a smart Intersects impl
final SpatialPrefixTree grid = indexStrategy.getGrid();
//default to max precision
final int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, 0.0));
return new IntersectsRPTVerifyQuery(args.getShape(), indexStrategy.getFieldName(), grid, detailLevel, indexStrategy.getPrefixGridScanLevel(), predicateValueSource);
} else {
//The general path; all index matches get verified
SpatialArgs indexArgs;
if (pred == SpatialOperation.Contains) {
// note: we could map IsWithin as well but it's pretty darned slow since it touches all world grids
indexArgs = args;
} else {
//TODO add args.clone method with new predicate? Or simply make non-final?
indexArgs = new SpatialArgs(SpatialOperation.Intersects, args.getShape());
indexArgs.setDistErr(args.getDistErr());
indexArgs.setDistErrPct(args.getDistErrPct());
}
if (indexArgs.getDistErr() == null && indexArgs.getDistErrPct() == null) {
indexArgs.setDistErrPct(0.10);
}
final Query indexQuery = indexStrategy.makeQuery(indexArgs);
return new CompositeVerifyQuery(indexQuery, predicateValueSource);
}
}
use of org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree 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.SpatialPrefixTree in project ddf by codice.
the class TestGeoNamesQueryLuceneIndex method setUp.
@Before
public void setUp() throws IOException {
directoryIndex = spy(new GeoNamesQueryLuceneDirectoryIndex());
directoryIndex.setIndexLocation(null);
final SpatialPrefixTree grid = new GeohashPrefixTree(SPATIAL_CONTEXT, GeoNamesLuceneConstants.GEOHASH_LEVELS);
strategy = new RecursivePrefixTreeStrategy(grid, GeoNamesLuceneConstants.GEO_FIELD);
initializeIndex();
doReturn(directory).when(directoryIndex).openDirectory();
}
use of org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree in project ddf by codice.
the class GeoNamesLuceneIndexer method indexGeoEntries.
private void indexGeoEntries(final IndexWriter indexWriter, final List<GeoEntry> geoEntryList, final ProgressCallback progressCallback) throws IOException {
int progress = 0;
int currentEntry = 0;
final int numGeoEntries = geoEntryList.size();
final SpatialPrefixTree grid = new GeohashPrefixTree(SPATIAL_CONTEXT, GeoNamesLuceneConstants.GEOHASH_LEVELS);
final SpatialStrategy strategy = new RecursivePrefixTreeStrategy(grid, GeoNamesLuceneConstants.GEO_FIELD);
for (GeoEntry geoEntry : geoEntryList) {
addDocument(indexWriter, geoEntry, strategy);
if (currentEntry == (int) (numGeoEntries * (progress / 100.0f))) {
if (progressCallback != null) {
progressCallback.updateProgress(progress);
}
progress += 5;
}
++currentEntry;
}
// the work is complete.
if (progressCallback != null) {
progressCallback.updateProgress(100);
}
}
use of org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree in project titan by thinkaurelius.
the class LuceneExample method getSpatialStrategy.
private SpatialStrategy getSpatialStrategy(String key) {
SpatialStrategy strategy = spatial.get(key);
if (strategy == null) {
final int maxLevels = 11;
SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels);
strategy = new RecursivePrefixTreeStrategy(grid, key);
spatial.put(key, strategy);
}
return strategy;
}
Aggregations