io.sphere.sdk.search.model.RangeTermFacetBaseSearchModel Maven / Gradle / Ivy
package io.sphere.sdk.search.model;
import io.sphere.sdk.search.RangeFacetExpression;
import java.util.List;
import java.util.function.Function;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
/**
* Model to build range and 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 RangeTermFacetBaseSearchModel> extends TermFacetBaseSearchModel {
RangeTermFacetBaseSearchModel(final SearchModel searchModel, final Function typeSerializer, final String alias) {
super(searchModel, typeSerializer, alias);
}
RangeTermFacetBaseSearchModel(final SearchModel searchModel, final Function typeSerializer) {
super(searchModel, typeSerializer);
}
/**
* Generates an expression to obtain the facet of the attribute for any range.
* For example: a possible faceted classification could be ["-40": 4, "105": 2, "4": 1].
* Notice that this method generates a facet expression with two ranges: (-∞, 0] and [0, +∞), therefore two results should be expected.
* @return a facet expression for all values
*/
public RangeFacetExpression allRanges() {
return onlyRangeAsString(asList(FacetRange.lessThan("0"), FacetRange.atLeast("0")));
}
/**
* Generates an expression to obtain the facet of the attribute for only the given range.
* For example: a possible faceted classification for [3, 5] could be ["3": 4, "5": 2, "4": 1].
* @param range the range of values to be present in the facet
* @return a facet expression for only the given range
*/
public RangeFacetExpression onlyRange(final FacetRange range) {
return onlyRange(singletonList(range));
}
/**
* Generates an expression to obtain the facet of the attribute for only the given ranges.
* For example: a possible faceted classification for [[3, 5], [8, 9]] could be ["3": 4, "9": 3, "5": 2, "4": 1].
* @param ranges the ranges of values to be present in the facet
* @return a facet expression for only the given ranges
*/
public RangeFacetExpression onlyRange(final Iterable> ranges) {
return new RangeFacetExpressionImpl<>(searchModel, typeSerializer, ranges, alias);
}
/**
* Generates an expression to obtain the facet of the attribute for only the given range.
* For example: a possible faceted classification for [3, 5] could be ["3": 4, "5": 2, "4": 1].
* @param lowerEndpoint the lower endpoint of the range of values to be present in the facet, inclusive
* @param upperEndpoint the upper endpoint of the range of values to be present in the facet, inclusive
* @return a facet expression for only the given range
*/
public RangeFacetExpression onlyRange(final V lowerEndpoint, final V upperEndpoint) {
return onlyRange(FacetRange.of(lowerEndpoint, upperEndpoint));
}
/**
* Generates an expression to obtain the facet of the attribute for only values greater than or equal to the given value.
* For example: a possible faceted classification for [3, +∞) could be ["15": 6, "3": 4, "9": 3, "5": 2, "4": 1].
* @param value the lower endpoint of the range [v, +∞)
* @return a facet expression for only the given range
*/
public RangeFacetExpression onlyGreaterThanOrEqualTo(final V value) {
return onlyRange(FacetRange.atLeast(value));
}
/**
* Generates an expression to obtain the facet of the attribute for only values less than the given value.
* For example: a possible faceted classification for (-∞, 5) could be ["3": 4, "1": 3, "4": 1].
* @param value the upper endpoint of the range (-∞, v)
* @return a facet expression for only the given range
*/
public RangeFacetExpression onlyLessThan(final V value) {
return onlyRange(FacetRange.lessThan(value));
}
/**
* Generates an expression to obtain the facet of the attribute for only the given range.
* For example: a possible faceted classification for [3, 5] could be ["3": 4, "5": 2, "4": 1].
* @param range the range of values (as string) to be present in the facet
* @return a facet expression for only the given range
*/
public RangeFacetExpression onlyRangeAsString(final FacetRange range) {
return onlyRangeAsString(singletonList(range));
}
/**
* Generates an expression to obtain the facet of the attribute for only the given ranges.
* For example: a possible faceted classification for [[3, 5], [8, 9]] could be ["3": 4, "9": 3, "5": 2, "4": 1].
* @param ranges the ranges of values (as string) to be present in the facet
* @return a facet expression for only the given ranges
*/
public RangeFacetExpression onlyRangeAsString(final Iterable> ranges) {
return new RangeFacetExpressionImpl<>(searchModel, TypeSerializer.ofString(), ranges, alias);
}
/**
* Generates an expression to obtain the facet of the attribute for only the given range.
* For example: a possible faceted classification for [3, 5] could be ["3": 4, "5": 2, "4": 1].
* @param lowerEndpoint the lower endpoint of the range of values to be present in the facet, inclusive
* @param upperEndpoint the upper endpoint of the range of values to be present in the facet, inclusive
* @return a facet expression for only the given range
* @deprecated use {@link #onlyRangeAsString(FacetRange)}
*/
@Deprecated
public RangeFacetExpression onlyRangeAsString(final String lowerEndpoint, final String upperEndpoint) {
final List> ranges = singletonList(FacetRange.of(lowerEndpoint, upperEndpoint));
return new RangeFacetExpressionImpl<>(searchModel, TypeSerializer.ofString(), ranges, alias);
}
/**
* Generates an expression to obtain the facet of the attribute for only the given range.
* For example: a possible faceted classification for [3, 5] could be ["3": 4, "5": 2, "4": 1].
* @param range the range of values to be present in the facet
* @return a facet expression for only the given range
* @deprecated use {@link #onlyRange(FacetRange)}
*/
@Deprecated
public RangeFacetExpression byRange(final FacetRange range) {
return onlyRange(singletonList(range));
}
/**
* Generates an expression to obtain the facet of the attribute for only the given ranges.
* For example: a possible faceted classification for [[3, 5], [8, 9]] could be ["3": 4, "9": 3, "5": 2, "4": 1].
* @param ranges the ranges of values to be present in the facet
* @return a facet expression for only the given ranges
* @deprecated use {@link #onlyRange(Iterable)}
*/
@Deprecated
public RangeFacetExpression byRange(final Iterable> ranges) {
return new RangeFacetExpressionImpl<>(searchModel, typeSerializer, ranges, alias);
}
/**
* Generates an expression to obtain the facet of the attribute for only the given range.
* For example: a possible faceted classification for [3, 5] could be ["3": 4, "5": 2, "4": 1].
* @param lowerEndpoint the lower endpoint of the range of values to be present in the facet, inclusive
* @param upperEndpoint the upper endpoint of the range of values to be present in the facet, inclusive
* @return a facet expression for only the given range
* @deprecated use {@link #onlyRange(Comparable, Comparable)}
*/
@Deprecated
public RangeFacetExpression byRange(final V lowerEndpoint, final V upperEndpoint) {
return onlyRange(FacetRange.of(lowerEndpoint, upperEndpoint));
}
/**
* Generates an expression to obtain the facet of the attribute for only values greater than or equal to the given value.
* For example: a possible faceted classification for [3, +∞) could be ["15": 6, "3": 4, "9": 3, "5": 2, "4": 1].
* @param value the lower endpoint of the range [v, +∞)
* @return a facet expression for only the given range
* @deprecated use {@link #onlyGreaterThanOrEqualTo(Comparable)}
*/
@Deprecated
public RangeFacetExpression byGreaterThanOrEqualTo(final V value) {
return onlyRange(FacetRange.atLeast(value));
}
/**
* Generates an expression to obtain the facet of the attribute for only values less than the given value.
* For example: a possible faceted classification for (-∞, 5] could be ["3": 4, "1": 3, "5": 2, "4": 1].
* @param value the upper endpoint of the range (-∞, v]
* @return a facet expression for only the given range
* @deprecated use {@link #onlyLessThan(Comparable)}
*/
@Deprecated
public RangeFacetExpression byLessThan(final V value) {
return onlyRange(FacetRange.lessThan(value));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy