Skip to content

Commit e9d53cc

Browse files
committed
Add support for filtering by product attributes
1 parent 24395ee commit e9d53cc

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/main/java/com/indix/query/SearchQuery.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ public SearchQuery withCategoryId(List<Integer> categoryId) {
5454
return this;
5555
}
5656

57+
/**
58+
* Combined with any of query/brand/category/store, limits results to products with specific attribute values
59+
*/
60+
public SearchQuery withAttrFilter(String attrFilterKey, List<String> attrFilterValues) {
61+
for (String attrValue: attrFilterValues) {
62+
parameters.add(new BasicNameValuePair(attrFilterKey, attrValue));
63+
}
64+
return this;
65+
}
66+
5767
/**
5868
* Combined with end_price, limits results to products sold by at least one store at a price between start and end
5969
*/

src/test/java/com/indix/query/SearchQueryTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public void testBasicQuery() {
4141
expectedValue.add(new BasicNameValuePair("sortBy", "PRICE_HIGH_TO_LOW"));
4242
expectedValue.add(new BasicNameValuePair("facetBy", "storeId"));
4343
expectedValue.add(new BasicNameValuePair("facetBy", "brandId"));
44+
expectedValue.add(new BasicNameValuePair("attr.color", "black"));
45+
expectedValue.add(new BasicNameValuePair("attr.color", "red"));
46+
expectedValue.add(new BasicNameValuePair("attr.size", "xs"));
4447
expectedValue.add(new BasicNameValuePair("pageNumber", "5"));
4548
expectedValue.add(new BasicNameValuePair("pageSize", "55"));
4649

@@ -52,6 +55,8 @@ public void testBasicQuery() {
5255
.withSku("sku1")
5356
.withSortBy(SearchQuery.SortBy.PRICE_HIGH_TO_LOW)
5457
.withFacetBy(Arrays.asList("storeId", "brandId"))
58+
.withAttrFilter("attr.color", Arrays.asList("black", "red"))
59+
.withAttrFilter("attr.size", Arrays.asList("xs"))
5560
.withPageNumber(5)
5661
.withPageSize(55)
5762
.withCountryCode("US")

0 commit comments

Comments
 (0)