@Test public void testCreateQueryChainNewArrivalShop() throws Exception { final ShopSearchSupportService shopSearchSupportService = context.mock(ShopSearchSupportService.class, "shopSearchSupportService"); final ZonedDateTime now = DateUtils.zdtParseSDT("2014-11-23 01:50:33"); final Instant expected = DateUtils.iParseSDT("2014-11-18 00:00:00"); final NavigationContext<Query> navigationContext = this.context.mock(NavigationContext.class, "navigationContext"); context.checking(new Expectations() {{ oneOf(shopSearchSupportService).getCategoryNewArrivalOffsetDays(0L, 10L); will(returnValue(5)); oneOf(navigationContext).getCategories(); will(returnValue(null)); oneOf(navigationContext).getCustomerShopId(); will(returnValue(10L)); }}); final List<Query> query = new ProductTagSearchQueryBuilder(shopSearchSupportService) { @Override ZonedDateTime now() { return now; } }.createQueryChain(navigationContext, "tag", "newarrival"); assertNotNull(query); assertEquals(1, query.size()); assertEquals("(tag:newarrival)^20.0 createdTimestamp:[" + expected.toEpochMilli() + " TO 9223372036854775807]", query.get(0).toString()); this.context.assertIsSatisfied(); }
@Override public List<Query> createQueryChain(final NavigationContext<Query> navigationContext, final String parameter, final Object value) { if (value instanceof Collection) { final Collection singleValues = (Collection) value; if (singleValues.size() > 1) { final BooleanQuery.Builder aggregatedQuery = new BooleanQuery.Builder(); boolean hasClause = false; for (final Object item : singleValues) { final Query clause = createTagQuery(navigationContext, escapeValue(item)); if (clause != null) { aggregatedQuery.add(clause, BooleanClause.Occur.SHOULD); hasClause = true; } } if (hasClause) { return Collections.singletonList(aggregatedQuery.build()); } } else if (singleValues.size() == 1) { final Query clause = createTagQuery(navigationContext, escapeValue(singleValues.iterator().next())); if (clause != null) { return Collections.singletonList(clause); } } return null; } final Query clause = createTagQuery(navigationContext, escapeValue(value)); if (clause != null) { return Collections.singletonList(clause); } return null; }
ProductTagSearchQueryBuilder extends AbstractSearchQueryBuilderImpl implements ProductSearchQueryBuilder<Query> { @Override public List<Query> createQueryChain(final NavigationContext<Query> navigationContext, final String parameter, final Object value) { if (value instanceof Collection) { final Collection singleValues = (Collection) value; if (singleValues.size() > 1) { final BooleanQuery.Builder aggregatedQuery = new BooleanQuery.Builder(); boolean hasClause = false; for (final Object item : singleValues) { final Query clause = createTagQuery(navigationContext, escapeValue(item)); if (clause != null) { aggregatedQuery.add(clause, BooleanClause.Occur.SHOULD); hasClause = true; } } if (hasClause) { return Collections.singletonList(aggregatedQuery.build()); } } else if (singleValues.size() == 1) { final Query clause = createTagQuery(navigationContext, escapeValue(singleValues.iterator().next())); if (clause != null) { return Collections.singletonList(clause); } } return null; } final Query clause = createTagQuery(navigationContext, escapeValue(value)); if (clause != null) { return Collections.singletonList(clause); } return null; } }
ProductTagSearchQueryBuilder extends AbstractSearchQueryBuilderImpl implements ProductSearchQueryBuilder<Query> { @Override public List<Query> createQueryChain(final NavigationContext<Query> navigationContext, final String parameter, final Object value) { if (value instanceof Collection) { final Collection singleValues = (Collection) value; if (singleValues.size() > 1) { final BooleanQuery.Builder aggregatedQuery = new BooleanQuery.Builder(); boolean hasClause = false; for (final Object item : singleValues) { final Query clause = createTagQuery(navigationContext, escapeValue(item)); if (clause != null) { aggregatedQuery.add(clause, BooleanClause.Occur.SHOULD); hasClause = true; } } if (hasClause) { return Collections.singletonList(aggregatedQuery.build()); } } else if (singleValues.size() == 1) { final Query clause = createTagQuery(navigationContext, escapeValue(singleValues.iterator().next())); if (clause != null) { return Collections.singletonList(clause); } } return null; } final Query clause = createTagQuery(navigationContext, escapeValue(value)); if (clause != null) { return Collections.singletonList(clause); } return null; } ProductTagSearchQueryBuilder(final ShopSearchSupportService shopSearchSupportService); }
ProductTagSearchQueryBuilder extends AbstractSearchQueryBuilderImpl implements ProductSearchQueryBuilder<Query> { @Override public List<Query> createQueryChain(final NavigationContext<Query> navigationContext, final String parameter, final Object value) { if (value instanceof Collection) { final Collection singleValues = (Collection) value; if (singleValues.size() > 1) { final BooleanQuery.Builder aggregatedQuery = new BooleanQuery.Builder(); boolean hasClause = false; for (final Object item : singleValues) { final Query clause = createTagQuery(navigationContext, escapeValue(item)); if (clause != null) { aggregatedQuery.add(clause, BooleanClause.Occur.SHOULD); hasClause = true; } } if (hasClause) { return Collections.singletonList(aggregatedQuery.build()); } } else if (singleValues.size() == 1) { final Query clause = createTagQuery(navigationContext, escapeValue(singleValues.iterator().next())); if (clause != null) { return Collections.singletonList(clause); } } return null; } final Query clause = createTagQuery(navigationContext, escapeValue(value)); if (clause != null) { return Collections.singletonList(clause); } return null; } ProductTagSearchQueryBuilder(final ShopSearchSupportService shopSearchSupportService); @Override List<Query> createQueryChain(final NavigationContext<Query> navigationContext, final String parameter, final Object value); }
ProductTagSearchQueryBuilder extends AbstractSearchQueryBuilderImpl implements ProductSearchQueryBuilder<Query> { @Override public List<Query> createQueryChain(final NavigationContext<Query> navigationContext, final String parameter, final Object value) { if (value instanceof Collection) { final Collection singleValues = (Collection) value; if (singleValues.size() > 1) { final BooleanQuery.Builder aggregatedQuery = new BooleanQuery.Builder(); boolean hasClause = false; for (final Object item : singleValues) { final Query clause = createTagQuery(navigationContext, escapeValue(item)); if (clause != null) { aggregatedQuery.add(clause, BooleanClause.Occur.SHOULD); hasClause = true; } } if (hasClause) { return Collections.singletonList(aggregatedQuery.build()); } } else if (singleValues.size() == 1) { final Query clause = createTagQuery(navigationContext, escapeValue(singleValues.iterator().next())); if (clause != null) { return Collections.singletonList(clause); } } return null; } final Query clause = createTagQuery(navigationContext, escapeValue(value)); if (clause != null) { return Collections.singletonList(clause); } return null; } ProductTagSearchQueryBuilder(final ShopSearchSupportService shopSearchSupportService); @Override List<Query> createQueryChain(final NavigationContext<Query> navigationContext, final String parameter, final Object value);  }