Skip to content
Merged
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ var variationsMap: VariationsMap = VariationsMap(
"max_price" to mapOf("aggregation" to "max", "field" to "data.price"),
),
dtype = "array",
filterBy = """{"and":[{"field":"data.brand","value":"Best Brand"}]}""",
)

// Using RxJava
Expand Down Expand Up @@ -154,6 +155,7 @@ var variationsMap: VariationsMap = VariationsMap(
"max_price" to mapOf("aggregation" to "max", "field" to "data.price"),
),
dtype = "array",
"""{"and":[{"field":"data.brand","value":"Best Brand"}]}""",
)
var preFilterExpression = """{ "and": [ { "name": "Color", "value": "green" } ] }"""

Expand Down Expand Up @@ -223,6 +225,7 @@ var variationsMap: VariationsMap = VariationsMap(
"max_price" to mapOf("aggregation" to "max", "field" to "data.price"),
),
dtype = "array",
"""{"and":[{"field":"data.brand","value":"Best Brand"}]}"""
)
var preFilterExpression = """{ "and": [ { "name": "Color", "value": "green" } ] }"""

Expand Down Expand Up @@ -325,6 +328,7 @@ var variationsMap: VariationsMap = VariationsMap(
"max_price" to mapOf("aggregation" to "max", "field" to "data.price"),
),
dtype = "array",
"""{"and":[{"field":"data.brand","value":"Best Brand"}]}""",
)

// Using RxJava
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ object ConstructorIo {
}

encodedParams.add(Constants.QueryConstants.VARIATIONS_MAP.urlEncode() to variationsMapJSONString.urlEncode())
variationsMap.filterBy = filterBy
}
numResultsPerSection?.forEach { section ->
encodedParams.add(Pair(Constants.QueryConstants.NUM_RESULTS+section.key, section.value.toString()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,20 +317,23 @@ class ConstructorIoBrowseTest {
val mockResponse = MockResponse().setResponseCode(200)
.setBody(TestDataLoader.loadAsString("browse_response.json"))
mockServer.enqueue(mockResponse)
val filterBy = """{"and":[{"field":"data.brand","value":"Best Brand"}]}"""
val variationsMap = VariationsMap(
dtype = "array",
values = mapOf(
"Price" to mapOf("aggregation" to "min", "field" to "data.facets.price"),
"Country" to mapOf("aggregation" to "all", "field" to "data.facets.country")
),
groupBy = listOf(mapOf("name" to "Country", "field" to "data.facets.Country")),
filterBy = """{"and":[{"field":"data.brand","value":"Best Brand"}]}"""
filterBy = filterBy
)
val browseRequest = BrowseRequest.Builder("group_id", "Beverages")
.setVariationsMap(variationsMap)
.build()
val observer = constructorIo.getBrowseResults(browseRequest).test()
val request = mockServer.takeRequest()

assertThat(variationsMap.filterBy).isEqualTo(filterBy)
assertThat(request.requestUrl!!.encodedPath).isEqualTo("/browse/group_id/Beverages")
with(request.requestUrl!!) {
val queryParams = mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,21 +319,23 @@ class ConstructorIoSearchTest {
val mockResponse = MockResponse().setResponseCode(200)
.setBody(TestDataLoader.loadAsString("search_response.json"))
mockServer.enqueue(mockResponse)
val filterBy = """{"and":[{"field":"data.brand","value":"Best Brand"}]}"""
val variationsMap = VariationsMap(
dtype = "array",
values = mapOf(
"Price" to mapOf("aggregation" to "min", "field" to "data.facets.price"),
"Country" to mapOf("aggregation" to "all", "field" to "data.facets.country")
),
groupBy = listOf(mapOf("name" to "Country", "field" to "data.facets.Country")),
filterBy = """{"and":[{"field":"data.brand","value":"Best Brand"}]}"""
filterBy = filterBy
)
val searchRequest = SearchRequest.Builder("bbq")
.setVariationsMap(variationsMap)
.build()
val observer = constructorIo.getSearchResults(searchRequest).test()
val request = mockServer.takeRequest()

assertThat(variationsMap.filterBy).isEqualTo(filterBy)
assertThat(request.requestUrl!!.encodedPath).isEqualTo("/search/bbq")
with(request.requestUrl!!) {
val queryParams = mapOf(
Expand Down