All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.elasticsearch.index.mapper.AbstractShapeGeometryFieldMapper Maven / Gradle / Ivy

There is a newer version: 8.13.4
Show newest version
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server
 * Side Public License, v 1.
 */
package org.elasticsearch.index.mapper;

import org.elasticsearch.common.Explicit;
import org.elasticsearch.common.geo.builders.ShapeBuilder;
import org.elasticsearch.common.geo.builders.ShapeBuilder.Orientation;
import org.elasticsearch.index.analysis.NamedAnalyzer;

import java.util.Collections;
import java.util.Map;
import java.util.function.Function;

/**
 * Base class for {@link GeoShapeFieldMapper} and {@link LegacyGeoShapeFieldMapper}
 */
public abstract class AbstractShapeGeometryFieldMapper extends AbstractGeometryFieldMapper {

    public static Parameter> coerceParam(Function> initializer,
                                                           boolean coerceByDefault) {
        return Parameter.explicitBoolParam("coerce", true, initializer, coerceByDefault);
    }

    public static Parameter> orientationParam(Function> initializer) {
        return new Parameter<>("orientation", true,
            () -> new Explicit<>(Orientation.RIGHT, false),
            (n, c, o) -> new Explicit<>(ShapeBuilder.Orientation.fromString(o.toString()), true),
            initializer)
            .setSerializer((b, f, v) -> b.field(f, v.value()), v -> v.value().toString());
    }

    public abstract static class AbstractShapeGeometryFieldType extends AbstractGeometryFieldType {

        private final Orientation orientation;

        protected AbstractShapeGeometryFieldType(String name, boolean isSearchable, boolean isStored, boolean hasDocValues,
                                                 boolean parsesArrayValue, Parser parser,
                                                 Orientation orientation, Map meta) {
            super(name, isSearchable, isStored, hasDocValues, parsesArrayValue, parser, meta);
            this.orientation = orientation;
        }

        public Orientation orientation() { return this.orientation; }
    }

    protected Explicit coerce;
    protected Explicit orientation;

    protected AbstractShapeGeometryFieldMapper(String simpleName, MappedFieldType mappedFieldType,
                                               Map indexAnalyzers,
                                               Explicit ignoreMalformed, Explicit coerce,
                                               Explicit ignoreZValue, Explicit orientation,
                                               MultiFields multiFields, CopyTo copyTo,
                                               Indexer indexer, Parser parser) {
        super(simpleName, mappedFieldType, indexAnalyzers, ignoreMalformed, ignoreZValue, multiFields, copyTo, indexer, parser);
        this.coerce = coerce;
        this.orientation = orientation;
    }

    protected AbstractShapeGeometryFieldMapper(String simpleName, MappedFieldType mappedFieldType,
                                               Explicit ignoreMalformed, Explicit coerce,
                                               Explicit ignoreZValue, Explicit orientation,
                                               MultiFields multiFields, CopyTo copyTo,
                                               Indexer indexer, Parser parser) {
        this(simpleName, mappedFieldType, Collections.emptyMap(),
            ignoreMalformed, coerce, ignoreZValue, orientation, multiFields, copyTo, indexer, parser);
    }

    @Override
    public final boolean parsesArrayValue() {
        return false;
    }

    public boolean coerce() {
        return coerce.value();
    }

    public Orientation orientation() {
        return orientation.value();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy