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

com.stratio.cassandra.lucene.search.condition.builder.ConditionBuilder Maven / Gradle / Ivy

/**
 * Copyright (C) 2014 Stratio (http://stratio.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.stratio.cassandra.lucene.search.condition.builder;

import com.stratio.cassandra.lucene.search.condition.Condition;
import com.stratio.cassandra.lucene.util.Builder;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.annotate.JsonSubTypes;
import org.codehaus.jackson.annotate.JsonTypeInfo;

/**
 * {@link Builder} for creating new {@link Condition}s.
 *
 * @param  The type of the {@link Condition} to be created.
 * @param  The specific type of the {@link ConditionBuilder}.
 * @author Andres de la Pena {@literal }
 */
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes({@JsonSubTypes.Type(value = AllConditionBuilder.class, name = "all"),
               @JsonSubTypes.Type(value = BitemporalConditionBuilder.class, name = "bitemporal"),
               @JsonSubTypes.Type(value = BooleanConditionBuilder.class, name = "boolean"),
               @JsonSubTypes.Type(value = ContainsConditionBuilder.class, name = "contains"),
               @JsonSubTypes.Type(value = DateRangeConditionBuilder.class, name = "date_range"),
               @JsonSubTypes.Type(value = FuzzyConditionBuilder.class, name = "fuzzy"),
               @JsonSubTypes.Type(value = GeoDistanceConditionBuilder.class, name = "geo_distance"),
               @JsonSubTypes.Type(value = GeoBBoxConditionBuilder.class, name = "geo_bbox"),
               @JsonSubTypes.Type(value = GeoShapeConditionBuilder.class, name = "geo_shape"),
               @JsonSubTypes.Type(value = LuceneConditionBuilder.class, name = "lucene"),
               @JsonSubTypes.Type(value = MatchConditionBuilder.class, name = "match"),
               @JsonSubTypes.Type(value = NoneConditionBuilder.class, name = "none"),
               @JsonSubTypes.Type(value = PhraseConditionBuilder.class, name = "phrase"),
               @JsonSubTypes.Type(value = PrefixConditionBuilder.class, name = "prefix"),
               @JsonSubTypes.Type(value = RangeConditionBuilder.class, name = "range"),
               @JsonSubTypes.Type(value = RegexpConditionBuilder.class, name = "regexp"),
               @JsonSubTypes.Type(value = WildcardConditionBuilder.class, name = "wildcard")})
public abstract class ConditionBuilder> implements Builder {

    /** The boost for the {@link Condition} to be built. */
    @JsonProperty("boost")
    protected Float boost;

    /**
     * Sets the boost for the {@link Condition} to be built. Documents matching this condition will (in addition to the
     * normal weightings) have their score multiplied by {@code boost}.
     *
     * @param boost the boost
     * @return this with the specified boost
     */
    @SuppressWarnings("unchecked")
    public K boost(float boost) {
        this.boost = boost;
        return (K) this;
    }

    /**
     * Sets the boost for the {@link Condition} to be built. Documents matching this condition will (in addition to the
     * normal weightings) have their score multiplied by {@code boost}.
     *
     * @param boost he boost
     * @return this with the specified boost
     */
    @SuppressWarnings("unchecked")
    public K boost(Number boost) {
        this.boost = boost == null ? null : boost.floatValue();
        return (K) this;
    }

    /**
     * Returns the {@link Condition} represented by this builder.
     *
     * @return a new condition
     */
    @Override
    public abstract T build();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy