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

io.sphere.sdk.search.model.TermFacetBaseSearchModel Maven / Gradle / Ivy

There is a newer version: 1.0.0-M26
Show newest version
package io.sphere.sdk.search.model;

import io.sphere.sdk.models.Base;
import io.sphere.sdk.search.*;

import javax.annotation.Nullable;

import java.util.function.Function;

import static java.util.Collections.singletonList;

/**
 * Model to build term facets.
 * This class is abstract to force the subclass to select the methods that need to be highlighted and/or extended.
 * @param  type of the resource
 * @param  type of the value
 */
abstract class TermFacetBaseSearchModel extends Base implements FacetSearchModel {
    protected final SearchModel searchModel;
    protected final Function typeSerializer;
    @Nullable
    protected final String alias;

    TermFacetBaseSearchModel(final SearchModel searchModel, final Function typeSerializer, final String alias) {
        this.searchModel = searchModel;
        this.typeSerializer = typeSerializer;
        this.alias = alias;
    }

    TermFacetBaseSearchModel(final SearchModel searchModel, final Function typeSerializer) {
        this(searchModel, typeSerializer, null);
    }

    @Override
    @Nullable
    public String getAlias() {
        return alias;
    }

    @Override
    public TermFacetExpression allTerms() {
        return new TermFacetExpressionImpl<>(searchModel, typeSerializer, alias);
    }

    @Override
    public FilteredFacetExpression onlyTerm(final V value) {
        return onlyTerm(singletonList(value));
    }

    @Override
    public FilteredFacetExpression onlyTerm(final Iterable values) {
        return new FilteredFacetExpressionImpl<>(searchModel, typeSerializer, values, alias);
    }

    @Override
    public FilteredFacetExpression onlyTermAsString(final Iterable values) {
        return new FilteredFacetExpressionImpl<>(searchModel, TypeSerializer.ofString(), values, alias);
    }

    /**
     * Generates an expression to obtain the facets of the attribute for all values.
     * For example: a possible faceted classification could be ["red": 4, "yellow": 2, "blue": 1].
     * @return a facet expression for all values
     * @deprecated use {@link #allTerms()} instead
     */
    @Deprecated
    public TermFacetExpression byAllTerms() {
        return new TermFacetExpressionImpl<>(searchModel, typeSerializer, alias);
    }

    /**
     * Generates an expression to obtain the facet of the attribute for only the given value.
     * For example: a possible faceted classification for "red" could be ["red": 4].
     * @param value the value from which to obtain the facet
     * @return a facet expression for only the given value
     * @deprecated use {@link #onlyTerm(Object)}
     */
    @Deprecated
    public FilteredFacetExpression byTerm(final V value) {
        return onlyTerm(singletonList(value));
    }

    /**
     * Generates an expression to obtain the facets of the attribute for only the given values.
     * For example: a possible faceted classification for ["red", "blue"] could be ["red": 4, "blue": 1].
     * @param values the values from which to obtain the facets
     * @return a facet expression for only the given values
     * @deprecated use {@link #onlyTerm(Iterable)}
     */
    @Deprecated
    public FilteredFacetExpression byTerm(final Iterable values) {
        return new FilteredFacetExpressionImpl<>(searchModel, typeSerializer, values, alias);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy