@Test public void onlyResultsAreFiltered() throws Exception { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .plusFacets(SIZE_FACETED_SEARCH.facetExpression()) .plusFacets(COLOR_FACETED_SEARCH.facetExpression()) .plusResultFilters(COLOR_FACETED_SEARCH.filterExpressions()); testResult(search, ids -> assertThat(ids).containsOnly(product2.getId()), colors -> assertThat(colors).containsOnly(TermStats.of("blue", 2L), TermStats.of("red", 1L)), sizes -> assertThat(sizes).containsOnly(TermStats.of("36.0", 1L), TermStats.of("38.0", 1L), TermStats.of("40.0", 1L), TermStats.of("42.0", 1L), TermStats.of("44.0", 1L), TermStats.of("46.0", 1L))); }
@Test public void facetedSearchOnNumberSetAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofNumberSet(ATTR_NAME_NUMBER_SET).is(NUMBER_10.toPlainString()), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsExactly( TermStats.of("5.0", 2L), TermStats.of("10.0", 1L))); }
@Test public void facetedSearchOnTextSetAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofStringSet(ATTR_NAME_TEXT_SET).is(TEXT_BAR), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsExactly( TermStats.of(TEXT_FOO, 2L), TermStats.of(TEXT_BAR, 1L))); }
@Test public void onLocTextSetAttributes() throws Exception { testTermStats(FACET.allVariants().attribute().ofLocalizedStringSet(ATTR_NAME_LOC_TEXT_SET).locale(ENGLISH).allTerms(), termStats -> assertThat(termStats).containsExactly( TermStats.of(LOC_TEXT_FOO.get(ENGLISH), 2L), TermStats.of(LOC_TEXT_BAR.get(ENGLISH), 1L))); }
@Test public void facetedSearchOnBooleanAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofBoolean(ATTR_NAME_BOOLEAN).is(BOOL_TRUE), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsOnly( TermStats.of(BOOL_TRUE, 1L), TermStats.of(BOOL_FALSE, 1L))); }
@Test public void facetedSearchOnMoneyAmountAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofMoney(ATTR_NAME_MONEY).centAmount().is(toCents(MONEY_500_EUR).toString()), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsOnly( TermStats.of("50000", 1L), TermStats.of("100000", 1L))); }
@Test public void facetedSearchOnTimeAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofTime(ATTR_NAME_TIME).is(TIME_22H.toString()), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsOnly( TermStats.of("22:05:09.203", 1L), TermStats.of("23:06:10.204", 1L))); }
@Test public void resultsAndFacetsAreFiltered() throws Exception { final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .plusFacets(SIZE_FACETED_SEARCH.facetExpression()) .plusFacets(COLOR_FACETED_SEARCH.facetExpression()) .plusResultFilters(COLOR_FACETED_SEARCH.filterExpressions()) .plusFacetFilters(COLOR_FACETED_SEARCH.filterExpressions()); testResult(search, ids -> assertThat(ids).containsOnly(product2.getId()), colors -> assertThat(colors).containsOnly(TermStats.of("blue", 2L), TermStats.of("red", 1L)), sizes -> assertThat(sizes).containsOnly(TermStats.of("36.0", 1L))); }
@Test public void facetedSearchOnLocTextSetAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofLocalizedStringSet(ATTR_NAME_LOC_TEXT_SET).locale(ENGLISH).is(LOC_TEXT_BAR.get(ENGLISH)), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsExactly( TermStats.of(LOC_TEXT_FOO.get(ENGLISH), 2L), TermStats.of(LOC_TEXT_BAR.get(ENGLISH), 1L))); }
@Test public void facetedSearchOnLocEnumKeySetAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofLocalizedEnumSet(ATTR_NAME_LOC_ENUM_SET).key().is(LOC_ENUM_THREE.getKey()), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsExactly( TermStats.of(LOC_ENUM_TWO.getKey(), 2L), TermStats.of(LOC_ENUM_THREE.getKey(), 1L))); }
@Test public void facetedSearchOnMoneyCurrencyAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofMoney(ATTR_NAME_MONEY).currency().is(MONEY_500_EUR.getCurrency().getCurrencyCode()), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsOnly( TermStats.of("EUR", 1L), TermStats.of("USD", 1L))); }
@Test public void facetedSearchOnLocTextAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofLocalizedString(ATTR_NAME_LOC_TEXT).locale(ENGLISH).is(LOC_TEXT_FOO.get(ENGLISH)), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsOnly( TermStats.of(LOC_TEXT_FOO.get(ENGLISH), 1L), TermStats.of(LOC_TEXT_BAR.get(ENGLISH), 1L))); }
@Test public void facetedSearchOnLocEnumKeyAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofLocalizedEnum(ATTR_NAME_LOC_ENUM).key().is(LOC_ENUM_TWO.getKey()), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsOnly( TermStats.of(LOC_ENUM_TWO.getKey(), 1L), TermStats.of(LOC_ENUM_THREE.getKey(), 1L))); }
@Test public void facetedSearchOnLocEnumLabelSetAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofLocalizedEnumSet(ATTR_NAME_LOC_ENUM_SET).label().locale(GERMAN).is(LOC_ENUM_THREE.getLabel().get(GERMAN)), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsExactly( TermStats.of(LOC_ENUM_TWO.getLabel().get(GERMAN), 2L), TermStats.of(LOC_ENUM_THREE.getLabel().get(GERMAN), 1L))); }
@Test public void onLocEnumLabelAttributes() throws Exception { testTermStats(FACET.allVariants().attribute().ofLocalizedEnum(ATTR_NAME_LOC_ENUM).label().locale(GERMAN).allTerms(), termStats -> assertThat(termStats).containsOnly( TermStats.of(LOC_ENUM_TWO.getLabel().get(GERMAN), 1L), TermStats.of(LOC_ENUM_THREE.getLabel().get(GERMAN), 1L))); }
@Test public void facetedSearchOnLocEnumLabelAttributes() throws Exception { testResultWithTerms(PRODUCT_MODEL.allVariants().attribute().ofLocalizedEnum(ATTR_NAME_LOC_ENUM).label().locale(GERMAN).is(LOC_ENUM_TWO.getLabel().get(GERMAN)), ids -> assertThat(ids).containsOnly(product1.getId()), termStats -> assertThat(termStats).containsOnly( TermStats.of(LOC_ENUM_TWO.getLabel().get(GERMAN), 1L), TermStats.of(LOC_ENUM_THREE.getLabel().get(GERMAN), 1L))); }