use of org.apache.lucene.spatial.query.SpatialArgs in project lucene-solr by apache.
the class AbstractSpatialFieldType method createSpatialQuery.
//--------------------------------------------------------------
// Query Support
//--------------------------------------------------------------
/**
* Implemented for compatibility with geofilt & bbox query parsers:
* {@link SpatialQueryable}.
*/
@Override
public Query createSpatialQuery(QParser parser, SpatialOptions options) {
Point pt = SpatialUtils.parsePointSolrException(options.pointStr, ctx);
double distDeg = DistanceUtils.dist2Degrees(options.distance, options.radius);
Shape shape = ctx.makeCircle(pt, distDeg);
if (options.bbox)
shape = shape.getBoundingBox();
SpatialArgs spatialArgs = new SpatialArgs(SpatialOperation.Intersects, shape);
return getQueryFromSpatialArgs(parser, options.field, spatialArgs);
}
use of org.apache.lucene.spatial.query.SpatialArgs in project lucene-solr by apache.
the class DateRangeField method parseSpatialArgs.
@Override
protected SpatialArgs parseSpatialArgs(QParser parser, String externalVal) {
//We avoid SpatialArgsParser entirely because it isn't very Solr-friendly
final Shape shape = parseShape(externalVal);
final SolrParams localParams = parser.getLocalParams();
SpatialOperation op = SpatialOperation.Intersects;
if (localParams != null) {
String opStr = localParams.get(OP_PARAM);
if (opStr != null)
op = SpatialOperation.get(opStr);
}
return new SpatialArgs(op, shape);
}
use of org.apache.lucene.spatial.query.SpatialArgs in project lucene-solr by apache.
the class SpatialFileQueryMaker method makeQueryFromShape.
protected Query makeQueryFromShape(Shape shape) {
SpatialArgs args = new SpatialArgs(operation, shape);
if (!Double.isNaN(distErrPct))
args.setDistErrPct(distErrPct);
Query filterQuery = strategy.makeQuery(args);
if (score) {
//wrap with distance computing query
ValueSource valueSource = strategy.makeDistanceValueSource(shape.getCenter());
return new BooleanQuery.Builder().add(new FunctionQuery(valueSource), //matches everything and provides score
BooleanClause.Occur.MUST).add(filterQuery, //filters (score isn't used)
BooleanClause.Occur.FILTER).build();
} else {
// assume constant scoring
return filterQuery;
}
}
use of org.apache.lucene.spatial.query.SpatialArgs in project jena by apache.
the class SpatialIndexLucene method query$.
private List<Node> query$(IndexReader indexReader, Shape shape, int limit, SpatialOperation operation) throws IOException {
if (limit <= 0)
limit = MAX_N;
IndexSearcher indexSearcher = new IndexSearcher(indexReader);
SpatialArgs args = new SpatialArgs(operation, shape);
args.setDistErr(0.0);
Query query = strategy.makeQuery(args);
TopDocs docs = indexSearcher.search(query, limit);
List<Node> results = new ArrayList<>();
for (ScoreDoc sd : docs.scoreDocs) {
Document doc = indexSearcher.doc(sd.doc);
String[] values = doc.getValues(docDef.getEntityField());
for (String v : values) {
Node n = SpatialQueryFuncs.stringToNode(v);
results.add(n);
}
}
return results;
}
use of org.apache.lucene.spatial.query.SpatialArgs in project crate by crate.
the class MatchPredicate method geoMatch.
private Query geoMatch(LuceneQueryBuilder.Context context, List<Symbol> arguments, Object queryTerm) {
Map fields = (Map) ((Literal) arguments.get(0)).value();
String fieldName = (String) fields.keySet().iterator().next();
MappedFieldType fieldType = context.queryShardContext().getMapperService().fullName(fieldName);
GeoShapeFieldMapper.GeoShapeFieldType geoShapeFieldType = (GeoShapeFieldMapper.GeoShapeFieldType) fieldType;
String matchType = (String) ((Input) arguments.get(2)).value();
@SuppressWarnings("unchecked") Shape shape = GeoJSONUtils.map2Shape((Map<String, Object>) queryTerm);
ShapeRelation relation = ShapeRelation.getRelationByName(matchType);
assert relation != null : "invalid matchType: " + matchType;
PrefixTreeStrategy prefixTreeStrategy = geoShapeFieldType.defaultStrategy();
if (relation == ShapeRelation.DISJOINT) {
/**
* See {@link org.elasticsearch.index.query.GeoShapeQueryParser}:
*/
// 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 = new TermRangeQuery(fieldName, null, null, true, true);
Query intersects = prefixTreeStrategy.makeQuery(getArgs(shape, ShapeRelation.INTERSECTS));
bool.add(exists, BooleanClause.Occur.MUST);
bool.add(intersects, BooleanClause.Occur.MUST_NOT);
return new ConstantScoreQuery(bool.build());
}
SpatialArgs spatialArgs = getArgs(shape, relation);
return prefixTreeStrategy.makeQuery(spatialArgs);
}
Aggregations