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

Commit a66514d

Browse files
author
Clément Le Provost
committed
Merge branch 'master' into feat/offline-facet-search
2 parents 797c880 + 9b14509 commit a66514d

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,19 @@ protected Request multipleQueriesAsync(@NonNull List<Query> queries, @NonNull Co
182182
}
183183

184184
/**
185-
* Search for some text in a facet values.
185+
* Search (asynchronously) for some text in a facet values.
186+
*
187+
* @param facetName The name of the facet to search. It must have been declared in the index's `attributesForFaceting` setting with the `searchable()` modifier.
188+
* @param text The text to search for in the facet's values.
189+
* @param handler A Completion handler that will be notified of the request's outcome.
190+
* @return A cancellable request.
191+
*/
192+
public Request searchForFacetValuesAsync(@NonNull String facetName, @NonNull String text, @NonNull final CompletionHandler handler) throws AlgoliaException {
193+
return searchForFacetValues(facetName, text, null, handler);
194+
}
195+
196+
/**
197+
* Search (asynchronously) for some text in a facet values.
186198
*
187199
* @param facetName The name of the facet to search. It must have been declared in the index's `attributesForFaceting` setting with the `searchable()` modifier.
188200
* @param text The text to search for in the facet's values.
@@ -202,6 +214,19 @@ public Request searchForFacetValues(@NonNull String facetName, @NonNull String t
202214
* @param handler A Completion handler that will be notified of the request's outcome.
203215
* @return A cancellable request.
204216
*/
217+
public Request searchForFacetValuesAsync(@NonNull String facetName, @NonNull String facetText, @Nullable Query query, @NonNull final CompletionHandler handler) {
218+
return searchForFacetValues(facetName, facetText, query, handler);
219+
}
220+
221+
/**
222+
* Search (asynchronously) for some text in a facet values, optionally restricting the returned values to those contained in objects matching other (regular) search criteria.
223+
*
224+
* @param facetName The name of the facet to search. It must have been declared in the index's `attributesForFaceting` setting with the `searchable()` modifier.
225+
* @param facetText The text to search for in the facet's values.
226+
* @param query An optional query to take extra search parameters into account. There parameters apply to index objects like in a regular search query. Only facet values contained in the matched objects will be returned
227+
* @param handler A Completion handler that will be notified of the request's outcome.
228+
* @return A cancellable request.
229+
*/
205230
public Request searchForFacetValues(@NonNull String facetName, @NonNull String facetText, @Nullable Query query, @NonNull final CompletionHandler handler) {
206231
try {
207232
final String path = "/1/indexes/" + getEncodedIndexName() + "/facets/" + URLEncoder.encode(facetName, "UTF-8") + "/query";

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)