use of org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy 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.RecursivePrefixTreeStrategy in project janusgraph by JanusGraph.
the class LuceneIndex method getSpatialStrategy.
private SpatialStrategy getSpatialStrategy(String key, KeyInformation ki) {
SpatialStrategy strategy = spatial.get(key);
final Mapping mapping = Mapping.getMapping(ki);
final int maxLevels = ParameterType.INDEX_GEO_MAX_LEVELS.findParameter(ki.getParameters(), DEFAULT_GEO_MAX_LEVELS);
final double distErrorPct = ParameterType.INDEX_GEO_DIST_ERROR_PCT.findParameter(ki.getParameters(), DEFAULT_GEO_DIST_ERROR_PCT);
if (strategy == null) {
synchronized (spatial) {
if (!spatial.containsKey(key)) {
// strategy = new RecursivePrefixTreeStrategy(grid, key);
if (mapping == Mapping.DEFAULT) {
strategy = PointVectorStrategy.newInstance(ctx, key);
} else {
final SpatialPrefixTree grid = new QuadPrefixTree(ctx, maxLevels);
strategy = new RecursivePrefixTreeStrategy(grid, key);
((PrefixTreeStrategy) strategy).setDistErrPct(distErrorPct);
}
spatial.put(key, strategy);
} else
return spatial.get(key);
}
}
return strategy;
}
use of org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy in project janusgraph by JanusGraph.
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;
}
use of org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy in project elasticsearch by elastic.
the class GeoShapeQueryBuilder method doToQuery.
@Override
protected Query doToQuery(QueryShardContext context) {
if (shape == null) {
throw new UnsupportedOperationException("query must be rewritten first");
}
final ShapeBuilder shapeToQuery = shape;
final MappedFieldType fieldType = context.fieldMapper(fieldName);
if (fieldType == null) {
if (ignoreUnmapped) {
return new MatchNoDocsQuery();
} else {
throw new QueryShardException(context, "failed to find geo_shape field [" + fieldName + "]");
}
}
// TODO: This isn't the nicest way to check this
if (!(fieldType instanceof GeoShapeFieldMapper.GeoShapeFieldType)) {
throw new QueryShardException(context, "Field [" + fieldName + "] is not a geo_shape");
}
final GeoShapeFieldMapper.GeoShapeFieldType shapeFieldType = (GeoShapeFieldMapper.GeoShapeFieldType) fieldType;
PrefixTreeStrategy strategy = shapeFieldType.defaultStrategy();
if (this.strategy != null) {
strategy = shapeFieldType.resolveStrategy(this.strategy);
}
Query query;
if (strategy instanceof RecursivePrefixTreeStrategy && relation == ShapeRelation.DISJOINT) {
// this strategy doesn't support disjoint anymore: but it did
// before, including creating lucene fieldcache (!)
// in this case, execute disjoint as exists && !intersects
BooleanQuery.Builder bool = new BooleanQuery.Builder();
Query exists = ExistsQueryBuilder.newFilter(context, fieldName);
Query intersects = strategy.makeQuery(getArgs(shapeToQuery, ShapeRelation.INTERSECTS));
bool.add(exists, BooleanClause.Occur.MUST);
bool.add(intersects, BooleanClause.Occur.MUST_NOT);
query = new ConstantScoreQuery(bool.build());
} else {
query = new ConstantScoreQuery(strategy.makeQuery(getArgs(shapeToQuery, relation)));
}
return query;
}
use of org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy in project elasticsearch by elastic.
the class GeoFilterIT method testRelationSupport.
protected static boolean testRelationSupport(SpatialOperation relation) {
if (relation == SpatialOperation.IsDisjointTo) {
// disjoint works in terms of intersection
relation = SpatialOperation.Intersects;
}
try {
GeohashPrefixTree tree = new GeohashPrefixTree(SpatialContext.GEO, 3);
RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(tree, "area");
Shape shape = SpatialContext.GEO.makePoint(0, 0);
SpatialArgs args = new SpatialArgs(relation, shape);
strategy.makeQuery(args);
return true;
} catch (UnsupportedSpatialOperation e) {
final SpatialOperation finalRelation = relation;
ESLoggerFactory.getLogger(GeoFilterIT.class.getName()).info((Supplier<?>) () -> new ParameterizedMessage("Unsupported spatial operation {}", finalRelation), e);
return false;
}
}
Aggregations