@Test public void testCreateQueryChain() throws Exception { final PriceNavigation priceNavigation = context.mock(PriceNavigation.class, "priceNavigation"); final PriceSearchQueryBuilder builder = new PriceSearchQueryBuilder(priceNavigation); final Pair<String, Pair<BigDecimal, BigDecimal>> priceRange = new Pair<>("EUR", new Pair<>( new BigDecimal("10"), new BigDecimal("20"))); final NavigationContext<Query> navigationContext = this.context.mock(NavigationContext.class, "navigationContext"); context.checking(new Expectations() {{ oneOf(priceNavigation).decomposePriceRequestParams("EUR-_-10-_-20"); will(returnValue(priceRange)); oneOf(navigationContext).getCustomerShopId(); will(returnValue(1010L)); }}); final List<Query> query = builder.createQueryChain(navigationContext, "price", "EUR-_-10-_-20"); assertNotNull(query); assertEquals(1, query.size()); assertEquals("facet_price_1010_EUR_range:[1000 TO 1999]", query.get(0).toString()); this.context.assertIsSatisfied(); }
@Override public List<Query> createQueryChain(final NavigationContext<Query> navigationContext, final String parameter, final Object value) { String strValue = null; if (value instanceof Collection) { if (CollectionUtils.isNotEmpty((Collection) value)) { strValue = String.valueOf(((Collection) value).iterator().next()); } } else if (value != null) { strValue = String.valueOf(value); } if (strValue == null || StringUtils.isBlank(strValue)) { return null; } final Pair<String, Pair<BigDecimal, BigDecimal>> priceParams = priceNavigation.decomposePriceRequestParams(strValue); final String facet = SearchUtil.priceFacetName(navigationContext.getCustomerShopId(), priceParams.getFirst()); final Long from = SearchUtil.priceToLong(priceParams.getSecond().getFirst()); final Long to = SearchUtil.priceToLong(priceParams.getSecond().getSecond()); return Collections.singletonList(createRangeQuery(facet + "_range", from, to)); }
PriceSearchQueryBuilder extends AbstractSearchQueryBuilderImpl implements ProductSearchQueryBuilder<Query> { @Override public List<Query> createQueryChain(final NavigationContext<Query> navigationContext, final String parameter, final Object value) { String strValue = null; if (value instanceof Collection) { if (CollectionUtils.isNotEmpty((Collection) value)) { strValue = String.valueOf(((Collection) value).iterator().next()); } } else if (value != null) { strValue = String.valueOf(value); } if (strValue == null || StringUtils.isBlank(strValue)) { return null; } final Pair<String, Pair<BigDecimal, BigDecimal>> priceParams = priceNavigation.decomposePriceRequestParams(strValue); final String facet = SearchUtil.priceFacetName(navigationContext.getCustomerShopId(), priceParams.getFirst()); final Long from = SearchUtil.priceToLong(priceParams.getSecond().getFirst()); final Long to = SearchUtil.priceToLong(priceParams.getSecond().getSecond()); return Collections.singletonList(createRangeQuery(facet + "_range", from, to)); } }
PriceSearchQueryBuilder extends AbstractSearchQueryBuilderImpl implements ProductSearchQueryBuilder<Query> { @Override public List<Query> createQueryChain(final NavigationContext<Query> navigationContext, final String parameter, final Object value) { String strValue = null; if (value instanceof Collection) { if (CollectionUtils.isNotEmpty((Collection) value)) { strValue = String.valueOf(((Collection) value).iterator().next()); } } else if (value != null) { strValue = String.valueOf(value); } if (strValue == null || StringUtils.isBlank(strValue)) { return null; } final Pair<String, Pair<BigDecimal, BigDecimal>> priceParams = priceNavigation.decomposePriceRequestParams(strValue); final String facet = SearchUtil.priceFacetName(navigationContext.getCustomerShopId(), priceParams.getFirst()); final Long from = SearchUtil.priceToLong(priceParams.getSecond().getFirst()); final Long to = SearchUtil.priceToLong(priceParams.getSecond().getSecond()); return Collections.singletonList(createRangeQuery(facet + "_range", from, to)); } PriceSearchQueryBuilder(final PriceNavigation priceNavigation); }
PriceSearchQueryBuilder extends AbstractSearchQueryBuilderImpl implements ProductSearchQueryBuilder<Query> { @Override public List<Query> createQueryChain(final NavigationContext<Query> navigationContext, final String parameter, final Object value) { String strValue = null; if (value instanceof Collection) { if (CollectionUtils.isNotEmpty((Collection) value)) { strValue = String.valueOf(((Collection) value).iterator().next()); } } else if (value != null) { strValue = String.valueOf(value); } if (strValue == null || StringUtils.isBlank(strValue)) { return null; } final Pair<String, Pair<BigDecimal, BigDecimal>> priceParams = priceNavigation.decomposePriceRequestParams(strValue); final String facet = SearchUtil.priceFacetName(navigationContext.getCustomerShopId(), priceParams.getFirst()); final Long from = SearchUtil.priceToLong(priceParams.getSecond().getFirst()); final Long to = SearchUtil.priceToLong(priceParams.getSecond().getSecond()); return Collections.singletonList(createRangeQuery(facet + "_range", from, to)); } PriceSearchQueryBuilder(final PriceNavigation priceNavigation); @Override List<Query> createQueryChain(final NavigationContext<Query> navigationContext, final String parameter, final Object value); }
PriceSearchQueryBuilder extends AbstractSearchQueryBuilderImpl implements ProductSearchQueryBuilder<Query> { @Override public List<Query> createQueryChain(final NavigationContext<Query> navigationContext, final String parameter, final Object value) { String strValue = null; if (value instanceof Collection) { if (CollectionUtils.isNotEmpty((Collection) value)) { strValue = String.valueOf(((Collection) value).iterator().next()); } } else if (value != null) { strValue = String.valueOf(value); } if (strValue == null || StringUtils.isBlank(strValue)) { return null; } final Pair<String, Pair<BigDecimal, BigDecimal>> priceParams = priceNavigation.decomposePriceRequestParams(strValue); final String facet = SearchUtil.priceFacetName(navigationContext.getCustomerShopId(), priceParams.getFirst()); final Long from = SearchUtil.priceToLong(priceParams.getSecond().getFirst()); final Long to = SearchUtil.priceToLong(priceParams.getSecond().getSecond()); return Collections.singletonList(createRangeQuery(facet + "_range", from, to)); } PriceSearchQueryBuilder(final PriceNavigation priceNavigation); @Override List<Query> createQueryChain(final NavigationContext<Query> navigationContext, final String parameter, final Object value);  }