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

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

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

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
FileOutputStream f =
  • Codota IconFile file;new FileOutputStream(file)
  • Codota IconString name;new FileOutputStream(name)
  • Codota IconFile file;new FileOutputStream(file, true)
  • Smart code suggestions by Codota
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void buildsTermFacetExpressionWithAlias() throws Exception {
  final TermFacetExpression<Object> facet = TermFacetExpression.of(ATTRIBUTE_PATH + AS_ALIAS);
  assertThat(facet.expression()).isEqualTo(ATTRIBUTE_PATH + AS_ALIAS);
  assertThat(facet.attributePath()).isEqualTo(ATTRIBUTE_PATH);
  assertThat(facet.value()).isNull();
  assertThat(facet.alias()).isEqualTo(ALIAS);
  assertThat(facet.resultPath()).isEqualTo(ALIAS);
}
origin: io.sphere.sdk.jvm/common

public TermFacetExpression<T, V> all() {
  return new TermFacetExpression<>(this, typeSerializer, alias);
}
origin: io.sphere.sdk.jvm/common

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

@SuppressWarnings("unchecked")
public <V> Optional<TermFacetResult<V>> getTermFacetResult(final TermFacetExpression<T, V> facetExpression) {
  return getFacetResult(facetExpression.resultPath()).map(facetResult -> {
    if (facetResult instanceof TermFacetResult) {
      return (TermFacetResult) facetResult;
    } else {
      // TODO Use another type of exception once exception task is finished
      throw new RuntimeException("Facet result is not of type TermFacetResult: " + facetResult);
    }
  });
}
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: commercetools/commercetools-jvm-sdk

@Test
public void simpleFacetsAreParsed() throws Exception {
  final TermFacetExpression<ProductProjection> facetExpr = TermFacetExpression.of("variants.attributes." + ATTR_NAME_COLOR);
  final ProductProjectionSearch search = ProductProjectionSearch.ofStaged().plusFacets(facetExpr);
  testResult(search, result -> {
    final TermFacetResult termFacetResult = result.getFacetResult(facetExpr);
    assertThat(termFacetResult.getMissing()).isGreaterThanOrEqualTo(3);
    assertThat(termFacetResult.getTotal()).isEqualTo(3);
    assertThat(termFacetResult.getOther()).isEqualTo(0);
    assertThat(termFacetResult.getTerms()).isEqualTo(asList(TermStats.of("blue", 2L), TermStats.of("red", 1L)));
  });
}
origin: commercetools/commercetools-jvm-sdk

public TermFacetResult getFacetResult(final TermFacetExpression<T> facetExpression) {
  return getTermFacetResult(facetExpression.resultPath());
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void canAccessNumberCustomAttributes() throws Exception {
  final String attrName = "length";
  assertThat(FACET_ATTR.ofNumber(attrName).allTerms().expression()).isEqualTo("variants.attributes.length");
  assertThat(FILTER_ATTR.ofNumber(attrName).is(valueOf(4))).extracting(expression()).containsExactly("variants.attributes.length:4");
  assertThat(SORT_ATTR.ofNumber(attrName).descWithMinValue().expression()).isEqualTo("variants.attributes.length desc.min");
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void buildsTermFacetExpression() throws Exception {
  final TermFacetExpression<Object> facet = TermFacetExpression.of(ATTRIBUTE_PATH);
  assertThat(facet.expression()).isEqualTo(ATTRIBUTE_PATH);
  assertThat(facet.attributePath()).isEqualTo(ATTRIBUTE_PATH);
  assertThat(facet.value()).isNull();
  assertThat(facet.alias()).isNull();
  assertThat(facet.resultPath()).isEqualTo(ATTRIBUTE_PATH);
}
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 canAccessTextCustomAttributes() throws Exception {
  final String attrName = "brand";
  assertThat(FACET_ATTR.ofString(attrName).allTerms().expression()).isEqualTo("variants.attributes.brand");
  assertThat(FILTER_ATTR.ofString(attrName).is("Apple")).extracting(expression()).containsExactly("variants.attributes.brand:\"Apple\"");
  assertThat(SORT_ATTR.ofString(attrName).ascWithMaxValue().expression()).isEqualTo("variants.attributes.brand asc.max");
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void buildsTermFacetExpression() throws Exception {
  final TermFacetExpression<Object> facet = TermFacetSearchModel.of(ATTRIBUTE_PATH, ofString()).allTerms();
  assertThat(facet.expression()).isEqualTo(ATTRIBUTE_PATH);
  assertThat(facet.attributePath()).isEqualTo(ATTRIBUTE_PATH);
  assertThat(facet.value()).isNull();
  assertThat(facet.alias()).isNull();
  assertThat(facet.resultPath()).isEqualTo(ATTRIBUTE_PATH);
}
origin: commercetools/commercetools-jvm-sdk

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

@Test
public void canAccessBooleanCustomAttributes() throws Exception {
  final String attrName = "isHandmade";
  assertThat(FACET_ATTR.ofBoolean(attrName).allTerms().expression()).isEqualTo("variants.attributes.isHandmade");
  assertThat(FILTER_ATTR.ofBoolean(attrName).is(true)).extracting(expression()).containsExactly("variants.attributes.isHandmade:true");
  assertThat(SORT_ATTR.ofBoolean(attrName).ascWithMaxValue().expression()).isEqualTo("variants.attributes.isHandmade asc.max");
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void buildsTermFacetExpressionWithAlias() throws Exception {
  final TermFacetExpression<Object> facet = TermFacetSearchModel.of(ATTRIBUTE_PATH, ofString()).withAlias(ALIAS).allTerms();
  assertThat(facet.expression()).isEqualTo(ATTRIBUTE_PATH + AS_ALIAS);
  assertThat(facet.attributePath()).isEqualTo(ATTRIBUTE_PATH);
  assertThat(facet.value()).isNull();
  assertThat(facet.alias()).isEqualTo(ALIAS);
  assertThat(facet.resultPath()).isEqualTo(ALIAS);
}
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 canCreateDateTimeAttributeExpressions() throws Exception {
  final String attrName = "createdDate";
  assertThat(FACET_ATTR.ofDateTime(attrName).allTerms().expression()).isEqualTo("variants.attributes.createdDate");
  assertThat(FILTER_ATTR.ofDateTime(attrName).is(dateTime("2001-09-11T22:05:09.203+00:00"))).extracting(expression()).containsExactly("variants.attributes.createdDate:\"2001-09-11T22:05:09.203Z\"");
  assertThat(SORT_ATTR.ofDateTime(attrName).ascWithMaxValue().expression()).isEqualTo("variants.attributes.createdDate asc.max");
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void termFacetsSupportsAlias() throws Exception {
  final String allFacetAlias = "my-facet";
  final String blueFacetAlias = "my-blue-facet";
  final TermFacetExpression<ProductProjection> allFacetExpr = PRODUCT_MODEL.allVariants().attribute().ofString(ATTR_NAME_COLOR).withAlias(allFacetAlias).allTerms();
  final FilteredFacetExpression<ProductProjection> blueFacetExpr = PRODUCT_MODEL.allVariants().attribute().ofString(ATTR_NAME_COLOR).withAlias(blueFacetAlias).onlyTerm("blue");
  final ProductProjectionSearch search = ProductProjectionSearch.ofStaged()
      .plusFacets(allFacetExpr)
      .plusFacets(blueFacetExpr);
  testResult(search, result -> {
    final TermFacetResult allFacetResult = result.getFacetResult(allFacetExpr);
    final FilteredFacetResult blueFacetResult = result.getFilteredFacetResult(blueFacetAlias);
    assertThat(allFacetExpr.resultPath()).isEqualTo(allFacetAlias);
    assertThat(blueFacetExpr.resultPath()).isEqualTo(blueFacetAlias);
    assertThat(allFacetResult.getTerms()).isEqualTo(asList(TermStats.of("blue", 2L), TermStats.of("red", 1L)));
    assertThat(blueFacetResult.getCount()).isEqualTo(2);
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void canAccessLastModifiedAt() throws Exception {
  assertThat(FACET_MODEL.lastModifiedAt().allTerms().expression()).isEqualTo("lastModifiedAt");
  assertThat(FILTER_MODEL.lastModifiedAt().is(dateTime("2001-09-11T22:05:09.203+00:00"))).extracting(expression()).containsExactly("lastModifiedAt:\"2001-09-11T22:05:09.203Z\"");
  assertThat(SORT_MODEL.lastModifiedAt().asc().expression()).isEqualTo("lastModifiedAt asc");
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void canCreateDateAttributeExpressions() throws Exception {
  final String attrName = "expirationDate";
  assertThat(FACET_ATTR.ofDate(attrName).allTerms().expression()).isEqualTo("variants.attributes.expirationDate");
  assertThat(FILTER_ATTR.ofDate(attrName).is(date("2001-09-11"))).extracting(expression()).containsExactly("variants.attributes.expirationDate:\"2001-09-11\"");
  assertThat(SORT_ATTR.ofDateTime(attrName).ascWithMaxValue().expression()).isEqualTo("variants.attributes.expirationDate asc.max");
}
io.sphere.sdk.searchTermFacetExpression

Javadoc

Term facets calculate statistical counts for all values of an attribute. Example: variants.attributes.color

Most used methods

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

Popular in Java

  • Reactive rest calls using spring rest template
  • setScale (BigDecimal)
  • getResourceAsStream (ClassLoader)
    Returns a stream for the resource with the specified name. See #getResource(String) for a descriptio
  • notifyDataSetChanged (ArrayAdapter)
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • String (java.lang)
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • Path (java.nio.file)
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
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