Skip to content
This repository was archived by the owner on Jan 31, 2022. It is now read-only.

Commit 9b14509

Browse files
authored
[feat] maxFacetHits (#311)
1 parent 13ab4a6 commit 9b14509

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

algoliasearch/src/main/java/com/algolia/search/saas/Query.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,19 @@ public Polygon(Polygon other) {
813813
}
814814
}
815815

816+
private static final String KEY_MAX_FACET_HITS = "maxFacetHits";
817+
818+
/**
819+
* Limit the number of facet values returned for each facet.
820+
*/
821+
public @NonNull Query setMaxFacetHits(Integer n) {
822+
return set(KEY_MAX_FACET_HITS, n);
823+
}
824+
825+
public Integer getMaxFacetHits() {
826+
return parseInt(get(KEY_MAX_FACET_HITS));
827+
}
828+
816829
private static final String KEY_MAX_VALUES_PER_FACET = "maxValuesPerFacet";
817830

818831
/**

algoliasearch/src/test/java/com/algolia/search/saas/QueryTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,16 @@ public void removeStopWordsInvalidClass() throws Exception {
644644
fail("setRemoveStopWords should throw when its parameter is neither Boolean nor String.");
645645
}
646646

647+
@Test
648+
public void maxFacetHits() {
649+
Query query = new Query();
650+
assertNull(query.getMaxFacetHits());
651+
query.setMaxFacetHits(456);
652+
assertEquals(Integer.valueOf(456), query.getMaxFacetHits());
653+
assertEquals("456", query.get("maxFacetHits"));
654+
assertEquals(query.getMaxFacetHits(), Query.parse(query.build()).getMaxFacetHits());
655+
}
656+
647657
@Test
648658
public void maxValuesPerFacet() {
649659
Query query = new Query();

0 commit comments

Comments
 (0)