Search in sources :

Example 1 with MapListener

use of org.apache.solr.util.MapListener in project lucene-solr by apache.

the class AbstractSpatialFieldType method init.

@Override
protected void init(IndexSchema schema, Map<String, String> args) {
    super.init(schema, args);
    if (ctx == null) {
        // subclass can set this directly
        final String CTX_PARAM = "spatialContextFactory";
        final String OLD_SPATIAL4J_PREFIX = "com.spatial4j.core";
        final String NEW_SPATIAL4J_PREFIX = "org.locationtech.spatial4j";
        for (Map.Entry<String, String> argEntry : args.entrySet()) {
            // "JTS" is a convenience alias
            if (argEntry.getKey().equals(CTX_PARAM) && argEntry.getValue().equals("JTS")) {
                argEntry.setValue("org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory");
                continue;
            }
            // Warn about using old Spatial4j class names
            if (argEntry.getValue().contains(OLD_SPATIAL4J_PREFIX)) {
                log.warn("Replace '" + OLD_SPATIAL4J_PREFIX + "' with '" + NEW_SPATIAL4J_PREFIX + "' in your schema.");
                argEntry.setValue(argEntry.getValue().replace(OLD_SPATIAL4J_PREFIX, NEW_SPATIAL4J_PREFIX));
            }
        }
        //Solr expects us to remove the parameters we've used.
        MapListener<String, String> argsWrap = new MapListener<>(args);
        ctx = SpatialContextFactory.makeSpatialContext(argsWrap, schema.getResourceLoader().getClassLoader());
        args.keySet().removeAll(argsWrap.getSeenKeys());
    }
    final String distanceUnitsStr = args.remove("distanceUnits");
    if (distanceUnitsStr == null) {
        this.distanceUnits = ctx.isGeo() ? DistanceUnits.KILOMETERS : DistanceUnits.DEGREES;
    } else {
        this.distanceUnits = parseDistanceUnits(distanceUnitsStr);
        if (this.distanceUnits == null)
            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Must specify distanceUnits as one of " + DistanceUnits.getSupportedUnits() + " on field types with class " + getClass().getSimpleName());
    }
    final SupportedFormats fmts = ctx.getFormats();
    String format = args.remove(FORMAT);
    if (format == null) {
        format = "WKT";
    }
    shapeWriter = fmts.getWriter(format);
    shapeReader = fmts.getReader(format);
    if (shapeWriter == null) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown Shape Format: " + format);
    }
    if (shapeReader == null) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown Shape Format: " + format);
    }
    argsParser = newSpatialArgsParser();
}
Also used : MapListener(org.apache.solr.util.MapListener) Map(java.util.Map) SolrException(org.apache.solr.common.SolrException) SupportedFormats(org.locationtech.spatial4j.io.SupportedFormats)

Aggregations

Map (java.util.Map)1 SolrException (org.apache.solr.common.SolrException)1 MapListener (org.apache.solr.util.MapListener)1 SupportedFormats (org.locationtech.spatial4j.io.SupportedFormats)1