Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
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;
}
}
28 changes: 28 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,24 @@ 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:
* 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<String> attrFilterValues) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should attrFilterKey contain the prefix 'attr.' or not on input?

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 +232,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", 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("attr.color", "attr.size"))
.withAttrFilter("color", Arrays.asList("black", "red"))
.withAttrFilter("size", Arrays.asList("xs"))
.withPageNumber(5)
.withPageSize(55)
.withCountryCode("US")
Expand Down