Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Std. atrribute filtering and faceting support in client #20

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Add the following dependency to your pom file
<dependency>
<groupId>com.indix.api</groupId>
<artifactId>indix-api-java</artifactId>
<version>3.1.0</version>
<version>3.2.0</version>
</dependency>
```

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>com.indix.api</groupId>
<artifactId>indix-api-java</artifactId>
<version>3.1.0</version>
<version>3.2.0</version>
<packaging>jar</packaging>
<name>Indix API-V2 Java Client</name>
<description>Java client which is used to access API V2 endpoints</description>
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/indix/models/searchResult/AttrFacet.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
5 changes: 5 additions & 0 deletions src/main/java/com/indix/models/searchResult/SearchResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public class SearchResult {
private int count;
private Map<String, List<Facet>> facets;
private Map<String, List<AttrFacet>> attrFacets;

public int getCount() {
return count;
Expand All @@ -14,4 +15,8 @@ public int getCount() {
public Map<String, List<Facet>> getFacets() {
return facets;
}

public Map<String, List<AttrFacet>> getAttrFacets() {
return attrFacets;
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/indix/query/SearchQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ public SearchQuery withCategoryId(List<Integer> categoryId) {
return this;
}

/**
* Combined with any of query/brand/category/store, limits results to products with specific attribute values
* NOTE:
* 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<String> attrFilterValues) {
for (String attrValue: attrFilterValues) {
parameters.add(new BasicNameValuePair("attr."+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
*/
Expand Down Expand Up @@ -214,6 +231,16 @@ public SearchQuery withFacetBy(List<String> facetBy) {
return this;
}

/**
* Facet by product attribute values
*/
public SearchQuery withAttrFacetBy(List<String> attrFacetBy) {
for (String attrFacet : attrFacetBy) {
parameters.add(new BasicNameValuePair("attrFacetBy", "attr."+attrFacet));
}
return this;
}

/**
* Specifies the page number of the result set to return. 10 results per page.
*/
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/com/indix/query/SearchQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ 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"));
expectedValue.add(new BasicNameValuePair("pageNumber", "5"));
expectedValue.add(new BasicNameValuePair("pageSize", "55"));

Expand All @@ -52,6 +57,9 @@ public void testBasicQuery() {
.withSku("sku1")
.withSortBy(SearchQuery.SortBy.PRICE_HIGH_TO_LOW)
.withFacetBy(Arrays.asList("storeId", "brandId"))
.withAttrFacetBy(Arrays.asList("color", "size"))
.withAttrFilter("color", Arrays.asList("black", "red"))
.withAttrFilter("size", Arrays.asList("xs"))
.withPageNumber(5)
.withPageSize(55)
.withCountryCode("US")
Expand Down