Skip to content

Commit 9c26e3e

Browse files
author
Clément Le Provost
authored
Support maxFacetHits when searching for facet values (#301)
This parameter is implemented at the `Query` class level, although it only applies to searches for facet values (not to regular searches).
1 parent e889838 commit 9c26e3e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Source/Query.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,20 @@ open class Query : AbstractQuery {
746746
set { self["responseFields"] = Query.buildJSONArray(newValue) }
747747
}
748748

749+
/// Maximum number of facet hits to return during a search for facet values.
750+
///
751+
/// + Note: Does not apply to regular search queries.
752+
///
753+
/// + Note: For performance reasons, the maximum allowed number of returned values is 100.
754+
/// Any value outside the range [1, 100] will be rejected.
755+
///
756+
/// + SeeAlso: `Index.searchForFacetValues(...)`
757+
///
758+
public var maxFacetHits: UInt? {
759+
get { return Query.parseUInt(self["maxFacetHits"]) }
760+
set { self["maxFacetHits"] = Query.buildUInt(newValue) }
761+
}
762+
749763
// MARK: - Initialization
750764

751765
/// Construct a query with the specified full text query.
@@ -1011,4 +1025,10 @@ open class Query : AbstractQuery {
10111025
get { return AbstractQuery.toNumber(self.facetingAfterDistinct) }
10121026
set { self.facetingAfterDistinct = newValue?.boolValue }
10131027
}
1028+
1029+
@objc(maxFacetHits)
1030+
public var z_objc_maxFacetHits: NSNumber? {
1031+
get { return AbstractQuery.toNumber(self.maxFacetHits) }
1032+
set { self.maxFacetHits = newValue?.uintValue }
1033+
}
10141034
}

Tests/QueryTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,4 +696,14 @@ class QueryTests: XCTestCase {
696696
let query2 = Query.parse(query1.build())
697697
XCTAssertEqual(query2.facetingAfterDistinct, true)
698698
}
699+
700+
func test_maxFacetHits() {
701+
let query1 = Query()
702+
XCTAssertNil(query1.maxFacetHits)
703+
query1.maxFacetHits = 66
704+
XCTAssertEqual(query1.maxFacetHits, 66)
705+
XCTAssertEqual(query1["maxFacetHits"], "66")
706+
let query2 = Query.parse(query1.build())
707+
XCTAssertEqual(query2.maxFacetHits, query1.maxFacetHits)
708+
}
699709
}

0 commit comments

Comments
 (0)