use of org.apache.lucene.spatial.query.UnsupportedSpatialOperation in project lucene-solr by apache.
the class TermQueryPrefixTreeStrategy method makeQuery.
@Override
public Query makeQuery(SpatialArgs args) {
final SpatialOperation op = args.getOperation();
if (op != SpatialOperation.Intersects)
throw new UnsupportedSpatialOperation(op);
Shape shape = args.getShape();
int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, distErrPct));
//--get a List of BytesRef for each term we want (no parents, no leaf bytes))
final int GUESS_NUM_TERMS;
if (shape instanceof Point)
//perfect guess
GUESS_NUM_TERMS = detailLevel;
else
//should this be a method on SpatialPrefixTree?
GUESS_NUM_TERMS = 4096;
//shared byte array for all terms
BytesRefBuilder masterBytes = new BytesRefBuilder();
List<BytesRef> terms = new ArrayList<>(GUESS_NUM_TERMS);
CellIterator cells = grid.getTreeCellIterator(shape, detailLevel);
while (cells.hasNext()) {
Cell cell = cells.next();
if (!cell.isLeaf())
continue;
//null because we want a new BytesRef
BytesRef term = cell.getTokenBytesNoLeaf(null);
//We copy out the bytes because it may be re-used across the iteration. This also gives us the opportunity
// to use one contiguous block of memory for the bytes of all terms we need.
masterBytes.grow(masterBytes.length() + term.length);
masterBytes.append(term);
//don't need; will reset later
term.bytes = null;
term.offset = masterBytes.length() - term.length;
terms.add(term);
}
//doing this now because if we did earlier, it's possible the bytes needed to grow()
for (BytesRef byteRef : terms) {
byteRef.bytes = masterBytes.bytes();
}
//TODO an automatonQuery might be faster?
return new TermInSetQuery(getFieldName(), terms);
}
use of org.apache.lucene.spatial.query.UnsupportedSpatialOperation in project lucene-solr by apache.
the class BBoxStrategy method makeQuery.
//---------------------------------
// Query Building
//---------------------------------
// Utility on SpatialStrategy?
// public Query makeQueryWithValueSource(SpatialArgs args, ValueSource valueSource) {
// return new CustomScoreQuery(makeQuery(args), new FunctionQuery(valueSource));
//or...
// return new BooleanQuery.Builder()
// .add(new FunctionQuery(valueSource), BooleanClause.Occur.MUST)//matches everything and provides score
// .add(filterQuery, BooleanClause.Occur.FILTER)//filters (score isn't used)
// .build();
// }
@Override
public Query makeQuery(SpatialArgs args) {
Shape shape = args.getShape();
if (!(shape instanceof Rectangle))
throw new UnsupportedOperationException("Can only query by Rectangle, not " + shape);
Rectangle bbox = (Rectangle) shape;
Query spatial;
// Useful for understanding Relations:
// http://edndoc.esri.com/arcsde/9.1/general_topics/understand_spatial_relations.htm
SpatialOperation op = args.getOperation();
if (op == SpatialOperation.BBoxIntersects)
spatial = makeIntersects(bbox);
else if (op == SpatialOperation.BBoxWithin)
spatial = makeWithin(bbox);
else if (op == SpatialOperation.Contains)
spatial = makeContains(bbox);
else if (op == SpatialOperation.Intersects)
spatial = makeIntersects(bbox);
else if (op == SpatialOperation.IsEqualTo)
spatial = makeEquals(bbox);
else if (op == SpatialOperation.IsDisjointTo)
spatial = makeDisjoint(bbox);
else if (op == SpatialOperation.IsWithin)
spatial = makeWithin(bbox);
else {
//no Overlaps support yet
throw new UnsupportedSpatialOperation(op);
}
return new ConstantScoreQuery(spatial);
}
use of org.apache.lucene.spatial.query.UnsupportedSpatialOperation in project lucene-solr by apache.
the class RecursivePrefixTreeStrategy method makeQuery.
@Override
public Query makeQuery(SpatialArgs args) {
final SpatialOperation op = args.getOperation();
Shape shape = args.getShape();
int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, distErrPct));
if (op == SpatialOperation.Intersects) {
if (isGridAlignedShape(args.getShape())) {
return makeGridShapeIntersectsQuery(args.getShape());
}
return new IntersectsPrefixTreeQuery(shape, getFieldName(), grid, detailLevel, prefixGridScanLevel);
} else if (op == SpatialOperation.IsWithin) {
return new WithinPrefixTreeQuery(shape, getFieldName(), grid, detailLevel, prefixGridScanLevel, //-1 flag is slower but ensures correct results
-1);
} else if (op == SpatialOperation.Contains) {
return new ContainsPrefixTreeQuery(shape, getFieldName(), grid, detailLevel, multiOverlappingIndexedShapes);
}
throw new UnsupportedSpatialOperation(op);
}
use of org.apache.lucene.spatial.query.UnsupportedSpatialOperation in project lucene-solr by apache.
the class BBoxStrategy method makeQuery.
//---------------------------------
// Query Building
//---------------------------------
// Utility on SpatialStrategy?
// public Query makeQueryWithValueSource(SpatialArgs args, ValueSource valueSource) {
// return new CustomScoreQuery(makeQuery(args), new FunctionQuery(valueSource));
//or...
// return new BooleanQuery.Builder()
// .add(new FunctionQuery(valueSource), BooleanClause.Occur.MUST)//matches everything and provides score
// .add(filterQuery, BooleanClause.Occur.FILTER)//filters (score isn't used)
// .build();
// }
@Override
public Query makeQuery(SpatialArgs args) {
Shape shape = args.getShape();
if (!(shape instanceof Rectangle))
throw new UnsupportedOperationException("Can only query by Rectangle, not " + shape);
Rectangle bbox = (Rectangle) shape;
Query spatial;
// Useful for understanding Relations:
// http://edndoc.esri.com/arcsde/9.1/general_topics/understand_spatial_relations.htm
SpatialOperation op = args.getOperation();
if (op == SpatialOperation.BBoxIntersects)
spatial = makeIntersects(bbox);
else if (op == SpatialOperation.BBoxWithin)
spatial = makeWithin(bbox);
else if (op == SpatialOperation.Contains)
spatial = makeContains(bbox);
else if (op == SpatialOperation.Intersects)
spatial = makeIntersects(bbox);
else if (op == SpatialOperation.IsEqualTo)
spatial = makeEquals(bbox);
else if (op == SpatialOperation.IsDisjointTo)
spatial = makeDisjoint(bbox);
else if (op == SpatialOperation.IsWithin)
spatial = makeWithin(bbox);
else {
//no Overlaps support yet
throw new UnsupportedSpatialOperation(op);
}
return new ConstantScoreQuery(spatial);
}
use of org.apache.lucene.spatial.query.UnsupportedSpatialOperation 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);
}
}
Aggregations