From e9d53ccaafbeb4a41f484058448416df2af96324 Mon Sep 17 00:00:00 2001 From: anithakathir Date: Fri, 17 Feb 2017 15:50:13 +0530 Subject: [PATCH 1/6] Add support for filtering by product attributes --- src/main/java/com/indix/query/SearchQuery.java | 10 ++++++++++ src/test/java/com/indix/query/SearchQueryTest.java | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/src/main/java/com/indix/query/SearchQuery.java b/src/main/java/com/indix/query/SearchQuery.java index db69a1f..01a8647 100644 --- a/src/main/java/com/indix/query/SearchQuery.java +++ b/src/main/java/com/indix/query/SearchQuery.java @@ -54,6 +54,16 @@ public SearchQuery withCategoryId(List categoryId) { return this; } + /** + * Combined with any of query/brand/category/store, limits results to products with specific attribute values + */ + public SearchQuery withAttrFilter(String attrFilterKey, List attrFilterValues) { + for (String attrValue: attrFilterValues) { + parameters.add(new BasicNameValuePair(attrFilterKey, attrValue)); + } + return this; + } + /** * Combined with end_price, limits results to products sold by at least one store at a price between start and end */ diff --git a/src/test/java/com/indix/query/SearchQueryTest.java b/src/test/java/com/indix/query/SearchQueryTest.java index 6d58e98..5de254d 100644 --- a/src/test/java/com/indix/query/SearchQueryTest.java +++ b/src/test/java/com/indix/query/SearchQueryTest.java @@ -41,6 +41,9 @@ public void testBasicQuery() { expectedValue.add(new BasicNameValuePair("sortBy", "PRICE_HIGH_TO_LOW")); expectedValue.add(new BasicNameValuePair("facetBy", "storeId")); expectedValue.add(new BasicNameValuePair("facetBy", "brandId")); + expectedValue.add(new BasicNameValuePair("attr.color", "black")); + expectedValue.add(new BasicNameValuePair("attr.color", "red")); + expectedValue.add(new BasicNameValuePair("attr.size", "xs")); expectedValue.add(new BasicNameValuePair("pageNumber", "5")); expectedValue.add(new BasicNameValuePair("pageSize", "55")); @@ -52,6 +55,8 @@ public void testBasicQuery() { .withSku("sku1") .withSortBy(SearchQuery.SortBy.PRICE_HIGH_TO_LOW) .withFacetBy(Arrays.asList("storeId", "brandId")) + .withAttrFilter("attr.color", Arrays.asList("black", "red")) + .withAttrFilter("attr.size", Arrays.asList("xs")) .withPageNumber(5) .withPageSize(55) .withCountryCode("US") From 0eba0623fc039865f848849ddf4155a483c8c6a9 Mon Sep 17 00:00:00 2001 From: anithakathir Date: Fri, 17 Feb 2017 15:53:09 +0530 Subject: [PATCH 2/6] Adds support for faceting by product attributes --- src/main/java/com/indix/query/SearchQuery.java | 10 ++++++++++ src/test/java/com/indix/query/SearchQueryTest.java | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/main/java/com/indix/query/SearchQuery.java b/src/main/java/com/indix/query/SearchQuery.java index 01a8647..5125d65 100644 --- a/src/main/java/com/indix/query/SearchQuery.java +++ b/src/main/java/com/indix/query/SearchQuery.java @@ -224,6 +224,16 @@ public SearchQuery withFacetBy(List facetBy) { return this; } + /** + * Facet by product attribute values + */ + public SearchQuery withAttrFacetBy(List attrFacetBy) { + for (String attrFacet : attrFacetBy) { + parameters.add(new BasicNameValuePair("attrFacetBy", attrFacet)); + } + return this; + } + /** * Specifies the page number of the result set to return. 10 results per page. */ diff --git a/src/test/java/com/indix/query/SearchQueryTest.java b/src/test/java/com/indix/query/SearchQueryTest.java index 5de254d..23ea013 100644 --- a/src/test/java/com/indix/query/SearchQueryTest.java +++ b/src/test/java/com/indix/query/SearchQueryTest.java @@ -41,6 +41,8 @@ public void testBasicQuery() { expectedValue.add(new BasicNameValuePair("sortBy", "PRICE_HIGH_TO_LOW")); expectedValue.add(new BasicNameValuePair("facetBy", "storeId")); expectedValue.add(new BasicNameValuePair("facetBy", "brandId")); + expectedValue.add(new BasicNameValuePair("attrFacetBy", "attr.color")); + expectedValue.add(new BasicNameValuePair("attrFacetBy", "attr.size")); expectedValue.add(new BasicNameValuePair("attr.color", "black")); expectedValue.add(new BasicNameValuePair("attr.color", "red")); expectedValue.add(new BasicNameValuePair("attr.size", "xs")); @@ -55,6 +57,7 @@ public void testBasicQuery() { .withSku("sku1") .withSortBy(SearchQuery.SortBy.PRICE_HIGH_TO_LOW) .withFacetBy(Arrays.asList("storeId", "brandId")) + .withAttrFacetBy(Arrays.asList("attr.color", "attr.size")) .withAttrFilter("attr.color", Arrays.asList("black", "red")) .withAttrFilter("attr.size", Arrays.asList("xs")) .withPageNumber(5) From 8b65d23ec51f1ae577f1f6f69f56f8cb9ce9c967 Mon Sep 17 00:00:00 2001 From: anithakathir Date: Fri, 17 Feb 2017 15:54:09 +0530 Subject: [PATCH 3/6] Update SearchResult to include AttributeFacets --- .../com/indix/models/searchResult/AttrFacet.java | 15 +++++++++++++++ .../indix/models/searchResult/SearchResult.java | 5 +++++ 2 files changed, 20 insertions(+) create mode 100644 src/main/java/com/indix/models/searchResult/AttrFacet.java diff --git a/src/main/java/com/indix/models/searchResult/AttrFacet.java b/src/main/java/com/indix/models/searchResult/AttrFacet.java new file mode 100644 index 0000000..564d4e2 --- /dev/null +++ b/src/main/java/com/indix/models/searchResult/AttrFacet.java @@ -0,0 +1,15 @@ +package com.indix.models.searchResult; + +public class AttrFacet { + private String name; + private int count; + + public String getName() { + return name; + } + + public int getCount() { + return count; + } + +} diff --git a/src/main/java/com/indix/models/searchResult/SearchResult.java b/src/main/java/com/indix/models/searchResult/SearchResult.java index 73c4467..c2350e3 100644 --- a/src/main/java/com/indix/models/searchResult/SearchResult.java +++ b/src/main/java/com/indix/models/searchResult/SearchResult.java @@ -6,6 +6,7 @@ public class SearchResult { private int count; private Map> facets; + private Map> attrFacets; public int getCount() { return count; @@ -14,4 +15,8 @@ public int getCount() { public Map> getFacets() { return facets; } + + public Map> getAttrFacets() { + return attrFacets; + } } From 1b52655aa806d7b4474ddf2981a53f57f6c173da Mon Sep 17 00:00:00 2001 From: anithakathir Date: Mon, 20 Feb 2017 12:15:31 +0530 Subject: [PATCH 4/6] Extracting out the std. attributes impl details --- src/main/java/com/indix/query/SearchQuery.java | 10 +++++++++- src/test/java/com/indix/query/SearchQueryTest.java | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/indix/query/SearchQuery.java b/src/main/java/com/indix/query/SearchQuery.java index 5125d65..5d532cc 100644 --- a/src/main/java/com/indix/query/SearchQuery.java +++ b/src/main/java/com/indix/query/SearchQuery.java @@ -56,10 +56,18 @@ public SearchQuery withCategoryId(List categoryId) { /** * Combined with any of query/brand/category/store, limits results to products with specific attribute values + * NOTE: + * Prepends attribute filter key with "attr.", since product attributes are identified that way. + * Examples of a few product attribute keys and values are: + * 1. color -> red / blue / green / black + * 2. size -> xs / s / m / l / xl + * 3. gender -> mens / womens + * A schema for the filterable keys and values isn't in place yet. + * When the standard schema is published, the filterable keys for a category and the list of values for the same will be available. */ public SearchQuery withAttrFilter(String attrFilterKey, List attrFilterValues) { for (String attrValue: attrFilterValues) { - parameters.add(new BasicNameValuePair(attrFilterKey, attrValue)); + parameters.add(new BasicNameValuePair("attr."+attrFilterKey, attrValue)); } return this; } diff --git a/src/test/java/com/indix/query/SearchQueryTest.java b/src/test/java/com/indix/query/SearchQueryTest.java index 23ea013..0b715a4 100644 --- a/src/test/java/com/indix/query/SearchQueryTest.java +++ b/src/test/java/com/indix/query/SearchQueryTest.java @@ -58,8 +58,8 @@ public void testBasicQuery() { .withSortBy(SearchQuery.SortBy.PRICE_HIGH_TO_LOW) .withFacetBy(Arrays.asList("storeId", "brandId")) .withAttrFacetBy(Arrays.asList("attr.color", "attr.size")) - .withAttrFilter("attr.color", Arrays.asList("black", "red")) - .withAttrFilter("attr.size", Arrays.asList("xs")) + .withAttrFilter("color", Arrays.asList("black", "red")) + .withAttrFilter("size", Arrays.asList("xs")) .withPageNumber(5) .withPageSize(55) .withCountryCode("US") From fb35aca0580a4933ba8df08d155eec5c0ed41e07 Mon Sep 17 00:00:00 2001 From: anithakathir Date: Mon, 27 Feb 2017 14:46:36 +0530 Subject: [PATCH 5/6] Remove std attribute specifics while faceting --- src/main/java/com/indix/query/SearchQuery.java | 3 +-- src/test/java/com/indix/query/SearchQueryTest.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/indix/query/SearchQuery.java b/src/main/java/com/indix/query/SearchQuery.java index 5d532cc..ef450af 100644 --- a/src/main/java/com/indix/query/SearchQuery.java +++ b/src/main/java/com/indix/query/SearchQuery.java @@ -57,7 +57,6 @@ public SearchQuery withCategoryId(List categoryId) { /** * Combined with any of query/brand/category/store, limits results to products with specific attribute values * NOTE: - * Prepends attribute filter key with "attr.", since product attributes are identified that way. * Examples of a few product attribute keys and values are: * 1. color -> red / blue / green / black * 2. size -> xs / s / m / l / xl @@ -237,7 +236,7 @@ public SearchQuery withFacetBy(List facetBy) { */ public SearchQuery withAttrFacetBy(List attrFacetBy) { for (String attrFacet : attrFacetBy) { - parameters.add(new BasicNameValuePair("attrFacetBy", attrFacet)); + parameters.add(new BasicNameValuePair("attrFacetBy", "attr."+attrFacet)); } return this; } diff --git a/src/test/java/com/indix/query/SearchQueryTest.java b/src/test/java/com/indix/query/SearchQueryTest.java index 0b715a4..0b28c9c 100644 --- a/src/test/java/com/indix/query/SearchQueryTest.java +++ b/src/test/java/com/indix/query/SearchQueryTest.java @@ -57,7 +57,7 @@ public void testBasicQuery() { .withSku("sku1") .withSortBy(SearchQuery.SortBy.PRICE_HIGH_TO_LOW) .withFacetBy(Arrays.asList("storeId", "brandId")) - .withAttrFacetBy(Arrays.asList("attr.color", "attr.size")) + .withAttrFacetBy(Arrays.asList("color", "size")) .withAttrFilter("color", Arrays.asList("black", "red")) .withAttrFilter("size", Arrays.asList("xs")) .withPageNumber(5) From 2b7a25e2e2da7459c05c5ee6a4f58c60818b34c0 Mon Sep 17 00:00:00 2001 From: anithakathir Date: Mon, 27 Feb 2017 14:54:08 +0530 Subject: [PATCH 6/6] Bump up client version and add feature usage in README --- README.md | 26 +++++++++++++++++++++++++- pom.xml | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b5ce84d..857706c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Add the following dependency to your pom file com.indix.api indix-api-java - 3.1.0 + 3.2.0 ``` @@ -108,6 +108,30 @@ It returns summary information for a product. indixApiClient.close(); } ``` +### Search Query with attribute facets and filters + +The following example shows how to filter products based on attributes. It retrieves a list of products matching a variety of +query parameters along with attributes facets with their offers and catalog info across stores + +```java + try { + Query searchQuery = QueryFactory.newSearchQuery() + .withQ("nike") + .withCountryCode("US") + .withAttrFacetBy("color"); + .withAttrFilter("color", colorList); + + UniversalSearchResult sr = indixApiClient.getProductsUniversal(searchQuery); + System.out.println(sr.getCount()); + System.out.println(sr.getProducts().size()); + System.out.println(sr.getFacets().size()); + System.out.println(sr.getAttrFacets().size()); + System.out.println(sr.getProducts().get(0).getMpid()); + } finally { + indixApiClient.close(); + } +``` + ### Bulk Products Query The following example shows how to request for a bulk search query which finds products against a list diff --git a/pom.xml b/pom.xml index dde423a..676e5d8 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.indix.api indix-api-java - 3.1.0 + 3.2.0 jar Indix API-V2 Java Client Java client which is used to access API V2 endpoints