Skip to content

Commit 44df4ee

Browse files
committed
Delete FacetQuery class
1 parent 10a03de commit 44df4ee

File tree

5 files changed

+14
-42
lines changed

5 files changed

+14
-42
lines changed

src/commonMain/kotlin/com/algolia/search/endpoint/EndpointSearch.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import com.algolia.search.model.filter.Filter
66
import com.algolia.search.model.response.ResponseSearch
77
import com.algolia.search.model.response.ResponseSearchForFacets
88
import com.algolia.search.model.search.Cursor
9-
import com.algolia.search.model.search.FacetQuery
109
import com.algolia.search.model.search.Query
1110
import com.algolia.search.transport.RequestOptions
1211

@@ -95,12 +94,14 @@ public interface EndpointSearch {
9594
* users can more easily drill down into the results. See more here.
9695
*
9796
* @param attribute The [Attribute] to facet on.
98-
* @param query The [FacetQuery] used to search.
97+
* @param facetQuery The facetQuery used to search for facets.
98+
* @param query: The [Query] to filter results.
9999
* @param requestOptions Configure request locally with [RequestOptions].
100100
*/
101101
suspend fun searchForFacets(
102102
attribute: Attribute,
103-
query: FacetQuery = FacetQuery(),
103+
facetQuery: String? = null,
104+
query: Query = Query(),
104105
requestOptions: RequestOptions? = null
105106
): ResponseSearchForFacets
106107

src/commonMain/kotlin/com/algolia/search/endpoint/EndpointSearchImpl.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import com.algolia.search.model.request.RequestParams
1111
import com.algolia.search.model.response.ResponseSearch
1212
import com.algolia.search.model.response.ResponseSearchForFacets
1313
import com.algolia.search.model.search.Cursor
14-
import com.algolia.search.model.search.FacetQuery
1514
import com.algolia.search.model.search.FacetStats
1615
import com.algolia.search.model.search.Query
1716
import com.algolia.search.serialize.*
@@ -49,14 +48,15 @@ internal class EndpointSearchImpl(
4948

5049
override suspend fun searchForFacets(
5150
attribute: Attribute,
52-
query: FacetQuery,
51+
facetQuery: String?,
52+
query: Query,
5353
requestOptions: RequestOptions?
5454
): ResponseSearchForFacets {
5555
val path = indexName.toPath("/facets/$attribute/query")
5656
val extraParams = json {
57-
query.facetQuery?.let { KeyFacetQuery to it }
57+
facetQuery?.let { KeyFacetQuery to it }
5858
}
59-
val body = query.query.toJsonNoDefaults().merge(extraParams).toString()
59+
val body = query.toJsonNoDefaults().merge(extraParams).toString()
6060

6161
return transport.request(HttpMethod.Post, CallType.Read, path, requestOptions, body)
6262
}

src/commonMain/kotlin/com/algolia/search/model/search/FacetQuery.kt

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/commonTest/kotlin/documentation/methods/search/DocSearchForFacets.kt

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package documentation.methods.search
22

33
import com.algolia.search.dsl.requestOptions
44
import com.algolia.search.model.Attribute
5-
import com.algolia.search.model.search.FacetQuery
65
import com.algolia.search.model.search.Query
76
import documentation.index
87
import runBlocking
@@ -15,53 +14,38 @@ internal class DocSearchForFacets {
1514

1615
// suspend fun Index.searchForFacets(
1716
// #{attribute}: __Attribute__,
18-
// #{query}: __FacetQuery__ = FacetQuery(),
17+
// #{facetQuery}: __String?__ = null,
18+
// [query](#searchParameters): __Query?__ = Query(),
1919
// #{requestOptions}: __RequestOptions?__ = null
2020
// ): ResponseSearchForFacetValues
21-
//
22-
// data class FacetQuery(
23-
// var #{facetQuery}: __String__? = null,
24-
// var #{query}: __Query?__ = null,
25-
// )
26-
//
27-
// // any #{searchParameters} can be set on the Query object
2821

2922
@Test
3023
fun snippet1() {
3124
runBlocking {
3225
val attribute = Attribute("category")
33-
val query = FacetQuery(facetQuery = "phone")
3426

35-
index.searchForFacets(attribute, query)
27+
index.searchForFacets(attribute, "phone")
3628
}
3729
}
3830

3931
@Test
4032
fun snippet2() {
4133
runBlocking {
4234
val attribute = Attribute("category")
43-
val query = FacetQuery(
44-
facetQuery = "phone",
45-
query = Query(filters = "brand:Apple")
46-
)
4735

48-
index.searchForFacets(attribute, query)
36+
index.searchForFacets(attribute, "phone", Query(filters = "brand:Apple"))
4937
}
5038
}
5139

5240
@Test
5341
fun snippet3() {
5442
runBlocking {
5543
val attribute = Attribute("category")
56-
val query = FacetQuery(
57-
facetQuery = "phone",
58-
query = Query(filters = "brand:Apple")
59-
)
6044
val requestOptions = requestOptions {
6145
header("X-Algolia-User-ID", "user123")
6246
}
6347

64-
index.searchForFacets(attribute, query, requestOptions)
48+
index.searchForFacets(attribute, "phone", Query(filters = "brand:Apple"), requestOptions)
6549
}
6650
}
6751
}

src/commonTest/kotlin/suite/TestSuiteSearch.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package suite
33
import clientAdmin1
44
import clientSearch
55
import com.algolia.search.helper.toAttribute
6-
import com.algolia.search.model.search.FacetQuery
76
import com.algolia.search.model.search.Query
87
import com.algolia.search.model.settings.AttributeForFaceting
98
import com.algolia.search.model.settings.Settings
@@ -58,8 +57,7 @@ internal class TestSuiteSearch {
5857
search.apply {
5958
search(Query(facets = allFacets, filters = "company:tesla")).nbHits shouldEqual 1
6059
search(Query(facets = allFacets, filters = "(company:tesla OR company:spacex)")).nbHits shouldEqual 2
61-
val query = FacetQuery("a")
62-
val response = searchForFacets(company, query)
60+
val response = searchForFacets(company, "a")
6361
val facetHits = response.facets.map { it.value }
6462

6563
facetHits shouldContain "Algolia"

0 commit comments

Comments
 (0)