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

sirius.search.constraints.ValueInField Maven / Gradle / Ivy

Go to download

Provides a thin layer above Elasticsearch (Fluent Query API, Automatic Mapping, Utilities)

The newest version!
/*
 * Made with all the love in the world
 * by scireum in Remshalden, Germany
 *
 * Copyright by scireum GmbH
 * http://www.scireum.de - [email protected]
 */

package sirius.search.constraints;

import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

/**
 * Represents a constraint which verifies that the given list field contains at least the given value.
 */
public class ValueInField implements Constraint {

    private final Object value;
    private final String field;

    /*
     * Use the #on(Object, String) factory method
     */
    private ValueInField(Object value, String field) {
        this.value = FieldEqual.transformFilterValue(value);
        this.field = field;
    }

    /**
     * Creates a new constraint which verifies that the given field contains at least the given value.
     *
     * @param value the value to check for
     * @param field the field to check
     * @return the newly created constraint
     */
    public static ValueInField on(Object value, String field) {
        return new ValueInField(value, field);
    }

    @Override
    public QueryBuilder createQuery() {
        return QueryBuilders.termQuery(field, value);
    }

    @Override
    public String toString(boolean skipConstraintValues) {
        return "'" + (skipConstraintValues ? "?" : value) + "' IN " + field;
    }

    @Override
    public String toString() {
        return toString(false);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy