Codota Logo
RangeFacetExpression
Code IndexAdd Codota to your IDE (free)

How to use
RangeFacetExpression
in
io.sphere.sdk.search

Best Java code snippets using io.sphere.sdk.search.RangeFacetExpression (Showing top 15 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Gson g =
  • Codota Iconnew Gson()
  • Codota IconGsonBuilder gsonBuilder;gsonBuilder.create()
  • Codota Iconnew GsonBuilder().create()
  • Smart code suggestions by Codota
}
origin: commercetools/commercetools-jvm-sdk

public RangeFacetResult getFacetResult(final RangeFacetExpression<T> facetExpression) {
  return getRangeFacetResult(facetExpression.resultPath());
}
origin: commercetools/commercetools-jvm-sdk

public SimpleRangeStats getRangeStatsOfAllRanges(final RangeFacetExpression<T> facetExpression) {
  final String facetResultPath = facetExpression.resultPath();
  final boolean facetIsOfTypeAllRanges = Optional.ofNullable(facetExpression.value())
      .map(v -> v.trim().equals(":range(* to \"0\"),(\"0\" to *)"))
      .orElse(false);
  if (facetIsOfTypeAllRanges) {
    final RangeFacetResult facetResult = getRangeFacetResult(facetResultPath);
    return getSimpleRangeStats(facetResult.getRanges());
  } else {
    throw new IllegalArgumentException("Facet result is not of type RangeFacetResult for all ranges, i.e. (* to \"0\"),(\"0\" to *): " + facetResultPath);
  }
}
origin: io.sphere.sdk.jvm/common

public RangeFacetExpression<T, V> onlyWithin(final Iterable<FacetRange<V>> ranges) {
  return new RangeFacetExpression<>(this, typeSerializer, ranges, alias);
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void buildsRangeFacetExpressionWithAlias() throws Exception {
  final RangeFacetExpression<Object> facet = RangeFacetExpression.of(ATTRIBUTE_PATH + RANGE_VALUE + AS_ALIAS);
  assertThat(facet.expression()).isEqualTo(ATTRIBUTE_PATH + RANGE_VALUE + AS_ALIAS);
  assertThat(facet.attributePath()).isEqualTo(ATTRIBUTE_PATH);
  assertThat(facet.value()).isEqualTo(RANGE_VALUE);
  assertThat(facet.alias()).isEqualTo(ALIAS);
  assertThat(facet.resultPath()).isEqualTo(ALIAS);
}
origin: commercetools/commercetools-jvm-sdk

private void testPagedSearchResultWithAllRanges(final List<RangeStats> rangeStats, final Consumer<SimpleRangeStats> test) {
  final RangeFacetExpression<Object> facetExpression = RangeFacetExpression.of("foo:range(* to \"0\"),(\"0\" to *)  as allRangesFacet");
  final Map<String, FacetResult> facets = new HashMap<>();
  facets.put(facetExpression.resultPath(), RangeFacetResult.of(rangeStats));
  final PagedSearchResult<Object> result = pagedSearchResult(facets);
  test.accept(result.getRangeStatsOfAllRanges(facetExpression));
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void usesAlias() throws Exception {
  final RangeTermFacetSearchModel<ProductProjection, BigDecimal> path = FACET_ATTR.ofNumber("size");
  assertThat(path.withAlias("my-facet").allTerms().expression()).isEqualTo("variants.attributes.size as my-facet");
  assertThat(path.withAlias("my-facet").onlyTerm(valueOf(38)).expression()).isEqualTo("variants.attributes.size:38 as my-facet");
  assertThat(path.withAlias("my-facet").onlyLessThan(valueOf(38)).expression()).isEqualTo("variants.attributes.size:range(* to 38) as my-facet");
}
origin: io.sphere.sdk.jvm/common

@SuppressWarnings("unchecked")
public <V extends Comparable<? super V>> Optional<RangeFacetResult<V>> getRangeFacetResult(final RangeFacetExpression<T, V> facetExpression) {
  return getFacetResult(facetExpression.buildResultPath()).map(facetResult -> {
    if (facetResult instanceof RangeFacetResult) {
      return (RangeFacetResult) facetResult;
    } else {
      // TODO Use another type of exception once exception task is finished
      throw new RuntimeException("Facet result is not of type RangeFacetResult: " + facetResult);
    }
  });
}
origin: io.sphere.sdk.jvm/common

  @Override
  public boolean equals(Object o) {
    return o != null && o instanceof FacetExpression && toSphereFacet().equals(((FacetExpression) o).toSphereFacet());
  }
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void buildsRangeFacetExpression() throws Exception {
  final RangeFacetExpression<Object> facet = RangeFacetExpression.of(ATTRIBUTE_PATH + RANGE_VALUE);
  assertThat(facet.expression()).isEqualTo(ATTRIBUTE_PATH + RANGE_VALUE);
  assertThat(facet.attributePath()).isEqualTo(ATTRIBUTE_PATH);
  assertThat(facet.value()).isEqualTo(RANGE_VALUE);
  assertThat(facet.alias()).isNull();
  assertThat(facet.resultPath()).isEqualTo(ATTRIBUTE_PATH);
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void buildsRangeFacetExpressionWithAlias() throws Exception {
  final RangeFacetExpression<Object> facet = RangeTermFacetSearchModel.of(ATTRIBUTE_PATH, ofNumber()).withAlias(ALIAS).onlyRange(FACET_RANGES);
  assertThat(facet.expression()).isEqualTo(ATTRIBUTE_PATH + RANGE_VALUE + AS_ALIAS);
  assertThat(facet.attributePath()).isEqualTo(ATTRIBUTE_PATH);
  assertThat(facet.value()).isEqualTo(RANGE_VALUE);
  assertThat(facet.alias()).isEqualTo(ALIAS);
  assertThat(facet.resultPath()).isEqualTo(ALIAS);
}
origin: commercetools/commercetools-jvm-sdk

private <T> void testPagedSearchResult(final Consumer<PagedSearchResult<T>> test) {
  final Map<String, FacetResult> facets = new HashMap<>();
  facets.put(TERM_FACET_EXPR.resultPath(), TERM_FACET_RESULT);
  facets.put(RANGE_FACET_EXPR.resultPath(), RANGE_FACET_RESULT);
  facets.put(FILTERED_FACET_EXPR.resultPath(), FILTERED_FACET_RESULT);
  final PagedSearchResult<T> result = pagedSearchResult(facets);
  test.accept(result);
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void buildsRangeFacetExpression() throws Exception {
  final RangeFacetExpression<Object> facet = RangeTermFacetSearchModel.of(ATTRIBUTE_PATH, ofNumber()).onlyRange(FACET_RANGES);
  assertThat(facet.expression()).isEqualTo(ATTRIBUTE_PATH + RANGE_VALUE);
  assertThat(facet.attributePath()).isEqualTo(ATTRIBUTE_PATH);
  assertThat(facet.value()).isEqualTo(RANGE_VALUE);
  assertThat(facet.alias()).isNull();
  assertThat(facet.resultPath()).isEqualTo(ATTRIBUTE_PATH);
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void termFacetResult() throws Exception {
  testPagedSearchResult(result -> {
    assertThat(result.getFacetResult(TERM_FACET_EXPR)).isEqualTo(TERM_FACET_RESULT);
    assertThat(result.getTermFacetResult("non-existent")).isNull();
    assertThatThrownBy(() -> result.getTermFacetResult(RANGE_FACET_EXPR.resultPath()))
        .isInstanceOf(IllegalArgumentException.class);
    assertThatThrownBy(() -> result.getTermFacetResult(FILTERED_FACET_EXPR.resultPath()))
        .isInstanceOf(IllegalArgumentException.class);
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void filteredFacetResult() throws Exception {
  testPagedSearchResult(result -> {
    assertThat(result.getFacetResult(FILTERED_FACET_EXPR)).isEqualTo(FILTERED_FACET_RESULT);
    assertThat(result.getFilteredFacetResult("non-existent")).isNull();
    assertThatThrownBy(() -> result.getFilteredFacetResult(TERM_FACET_EXPR.resultPath()))
        .isInstanceOf(IllegalArgumentException.class);
    assertThatThrownBy(() -> result.getFilteredFacetResult(RANGE_FACET_EXPR.resultPath()))
        .isInstanceOf(IllegalArgumentException.class);
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void rangeFacetsSupportsAlias() throws Exception {
  final String alias = "my-facet";
  final RangeFacetExpression<ProductProjection> facetExpr = PRODUCT_MODEL.allVariants().attribute().ofNumber(ATTR_NAME_SIZE).withAlias(alias).onlyGreaterThanOrEqualTo(ZERO);
  final ProductProjectionSearch search = ProductProjectionSearch.ofStaged().plusFacets(facetExpr);
  testResult(search, result -> {
    assertThat(facetExpr.resultPath()).isEqualTo(alias);
    final RangeStats rangeStats = result.getFacetResult(facetExpr).getRanges().get(0);
    assertThat(rangeStats.getLowerEndpoint()).isEqualTo("0.0");
    assertThat(rangeStats.getUpperEndpoint()).isNull();
    assertThat(rangeStats.getCount()).isEqualTo(6L);
    assertThat(rangeStats.getMin()).isEqualTo("36.0");
    assertThat(rangeStats.getMax()).isEqualTo("46.0");
    assertThat(rangeStats.getSum()).isEqualTo("246.0");
    assertThat(rangeStats.getMean()).isEqualTo(41.0);
  });
}
io.sphere.sdk.searchRangeFacetExpression

Javadoc

Range facets calculate statistical data (i.e. minimum, maximum, mean, count...) for all values of an attribute within a range. Example: variants.price:range(0 to *)

Most used methods

  • resultPath
  • expression
  • value
  • <init>
  • alias
  • attributePath
  • buildResultPath
  • of
  • toSphereFacet

Popular in Java

  • Finding current android device location
  • setScale (BigDecimal)
  • requestLocationUpdates (LocationManager)
  • notifyDataSetChanged (ArrayAdapter)
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Permission (java.security)
    Abstract class for representing access to a system resource. All permissions have a name (whose inte
  • Iterator (java.util)
    An iterator over a collection. Iterator takes the place of Enumeration in the Java Collections Frame
  • DataSource (javax.sql)
    A factory for connections to the physical data source that this DataSource object represents. An alt
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now