From a53d0096f792636e38cbe5d3c08fac4a492a85df Mon Sep 17 00:00:00 2001 From: Christopher Gee Date: Thu, 19 Oct 2023 14:09:05 -0700 Subject: [PATCH 1/3] Re-add filterBy --- library/src/main/java/io/constructor/core/ConstructorIo.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/library/src/main/java/io/constructor/core/ConstructorIo.kt b/library/src/main/java/io/constructor/core/ConstructorIo.kt index 593a40d3..f92a93d2 100755 --- a/library/src/main/java/io/constructor/core/ConstructorIo.kt +++ b/library/src/main/java/io/constructor/core/ConstructorIo.kt @@ -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())) From 619e02f173d4946dc395cb71f38cff20a5ac2638 Mon Sep 17 00:00:00 2001 From: Christopher Gee Date: Thu, 19 Oct 2023 14:33:20 -0700 Subject: [PATCH 2/3] Add test --- .../test/java/io/constructor/core/ConstructorioBrowseTest.kt | 5 ++++- .../test/java/io/constructor/core/ConstructorioSearchTest.kt | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/library/src/test/java/io/constructor/core/ConstructorioBrowseTest.kt b/library/src/test/java/io/constructor/core/ConstructorioBrowseTest.kt index f86beaa6..0e499d28 100644 --- a/library/src/test/java/io/constructor/core/ConstructorioBrowseTest.kt +++ b/library/src/test/java/io/constructor/core/ConstructorioBrowseTest.kt @@ -317,6 +317,7 @@ 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( @@ -324,13 +325,15 @@ class ConstructorIoBrowseTest { "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( diff --git a/library/src/test/java/io/constructor/core/ConstructorioSearchTest.kt b/library/src/test/java/io/constructor/core/ConstructorioSearchTest.kt index 00d10b46..3acfd767 100644 --- a/library/src/test/java/io/constructor/core/ConstructorioSearchTest.kt +++ b/library/src/test/java/io/constructor/core/ConstructorioSearchTest.kt @@ -319,6 +319,7 @@ 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( @@ -326,7 +327,7 @@ class ConstructorIoSearchTest { "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) @@ -334,6 +335,7 @@ class ConstructorIoSearchTest { 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( From 2ca4d40a5fff0a1a6acbfded08a2c47328ae5d2b Mon Sep 17 00:00:00 2001 From: Christopher Gee Date: Fri, 20 Oct 2023 08:22:51 -0700 Subject: [PATCH 3/3] Update readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 4fd1a809..d9a6269d 100755 --- a/README.md +++ b/README.md @@ -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 @@ -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" } ] }""" @@ -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" } ] }""" @@ -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