Example usage for org.apache.lucene.spatial.query SpatialOperation get

List of usage examples for org.apache.lucene.spatial.query SpatialOperation get

Introduction

In this page you can find the example usage for org.apache.lucene.spatial.query SpatialOperation get.

Prototype

public static SpatialOperation get(String v) 

Source Link

Usage

From source file:org.apache.blur.analysis.type.spatial.SpatialArgsParser.java

License:Apache License

/**
 * Parses a string such as "Intersects(-10,20,-8,22) distErrPct=0.025".
 * //from  ww w .  java 2s .  c  om
 * @param v
 *          The string to parse. Mandatory.
 * @param shapeReadWriter
 *          The spatial shapeReadWriter. Mandatory.
 * @return Not null.
 * @throws IllegalArgumentException
 *           If there is a problem parsing the string.
 * @throws InvalidShapeException
 *           Thrown from {@link ShapeReadWriter#readShape(String)}
 */
public static SpatialArgs parse(String v, ShapeReadWriter<SpatialContext> shapeReadWriter)
        throws IllegalArgumentException, InvalidShapeException {
    int idx = v.indexOf('(');
    int edx = v.lastIndexOf(')');

    if (idx < 0 || idx > edx) {
        throw new IllegalArgumentException("missing parens: " + v, null);
    }

    SpatialOperation op = SpatialOperation.get(v.substring(0, idx).trim());

    String body = v.substring(idx + 1, edx).trim();
    if (body.length() < 1) {
        throw new IllegalArgumentException("missing body : " + v, null);
    }

    Shape shape = shapeReadWriter.readShape(body);
    SpatialArgs args = new SpatialArgs(op, shape);

    if (v.length() > (edx + 1)) {
        body = v.substring(edx + 1).trim();
        if (body.length() > 0) {
            Map<String, String> aa = parseMap(body);
            args.setDistErrPct(readDouble(aa.remove(DIST_ERR_PCT)));
            args.setDistErr(readDouble(aa.remove(DIST_ERR)));
            if (!aa.isEmpty()) {
                throw new IllegalArgumentException("unused parameters: " + aa, null);
            }
        }
    }
    args.validate();
    return args;
}

From source file:org.apache.solr.schema.DateRangeField.java

License:Apache License

@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);
    }/*from www . j  a  v a  2s  . co m*/
    return new SpatialArgs(op, shape);
}