Skip to content

Commit

Permalink
feat(kotlin): add disjunctive faceting (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#3789

Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com>
Co-authored-by: Thomas Raffray <Fluf22@users.noreply.github.com>
  • Loading branch information
algolia-bot and Fluf22 committed Sep 24, 2024
1 parent 5da9052 commit 1e507c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions Sources/Search/Extra/DisjunctiveFaceting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct DisjunctiveFacetingHelper {

/// Build search queries to fetch the necessary facets information for disjunctive faceting
/// If the disjunctive facets set is empty, makes a single request with applied conjunctive filters
func makeQueries() -> [SearchQuery] {
func buildQueries() -> [SearchQuery] {
var queries = [SearchQuery]()

var mainQuery = self.query
Expand Down Expand Up @@ -89,8 +89,7 @@ struct DisjunctiveFacetingHelper {

/// Merge received search responses into single one with combined facets information
func mergeResponses<T: Codable>(
_ responses: [SearchResponse<T>],
keepSelectedEmptyFacets _: Bool = true
_ responses: [SearchResponse<T>]
) throws -> SearchDisjunctiveFacetingResponse<T> {
guard var mainResponse = responses.first else {
throw DisjunctiveFacetingError.emptyResponses
Expand Down
8 changes: 4 additions & 4 deletions Sources/Search/Extra/SearchClientExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,8 @@ public extension SearchClient {
/// - Parameter searchParamsObject: The search query params.
/// - Parameter refinements: Refinements to apply to the search in form of dictionary with
/// facet attribute as a key and a list of facet values for the designated attribute.
/// Any facet in this list not present in the `disjunctiveFacets` set will be filtered conjunctively.
/// Any facet in this list not present in the `disjunctiveFacets` set will be filtered conjunctively (with AND
/// operator).
/// - Parameter disjunctiveFacets: Set of facets attributes applied disjunctively (with OR operator)
/// - Parameter keepSelectedEmptyFacets: Whether the selected facet values might be preserved even
/// in case of their absence in the search response
Expand All @@ -657,19 +658,18 @@ public extension SearchClient {
searchParamsObject: SearchSearchParamsObject,
refinements: [String: [String]],
disjunctiveFacets: Set<String>,
keepSelectedEmptyFacets: Bool = true,
requestOptions: RequestOptions? = nil
) async throws -> SearchDisjunctiveFacetingResponse<T> {
let helper = DisjunctiveFacetingHelper(
query: SearchForHits(from: searchParamsObject, indexName: indexName),
refinements: refinements,
disjunctiveFacets: disjunctiveFacets
)
let queries = helper.makeQueries()
let queries = helper.buildQueries()
let responses: [SearchResponse<T>] = try await self.searchForHitsWithResponse(
searchMethodParams: SearchMethodParams(requests: queries),
requestOptions: requestOptions
)
return try helper.mergeResponses(responses, keepSelectedEmptyFacets: keepSelectedEmptyFacets)
return try helper.mergeResponses(responses)
}
}

0 comments on commit 1e507c5

Please sign in to comment.