Skip to content

Commit 1a31f77

Browse files
committed
add prefix search setting and facet search setting methods
1 parent e3244ab commit 1a31f77

6 files changed

Lines changed: 250 additions & 0 deletions

File tree

.code-samples.meilisearch.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,3 +751,16 @@ update_webhook_1: |-
751751
Webhook updated_webhook = this.client.updateWebhook(webhook.getUuid(), webhookReq2);
752752
delete_webhook_1: |-
753753
this.client.deleteWebhook("WEBHOOK_UUID");
754+
get_facet_search_setting_1: |-
755+
Boolean value = index.getFacetSearchSettings();
756+
update_facet_search_setting_1: |-
757+
index.updateFacetSearchSettings(false);
758+
reset_facet_search_setting_1: |-
759+
index.resetFacetSearchSettings();
760+
get_prefix_search_settings_1: |-
761+
PrefixSearchSetting prefixSearchSettings = index.getPrefixSearchSettings();
762+
update_prefix_search_setting_1: |-
763+
PrefixSearchSetting newSetting = PrefixSearchSetting.DISABLED;
764+
index.updatePrefixSearchSettings(newSetting);
765+
reset_prefix_search_setting_1: |-
766+
index.resetPrefixSearchSettings();

src/main/java/com/meilisearch/sdk/Index.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.meilisearch.sdk;
22

3+
import com.meilisearch.sdk.enums.PrefixSearchSetting;
34
import com.meilisearch.sdk.exceptions.MeilisearchException;
45
import com.meilisearch.sdk.http.URLBuilder;
56
import com.meilisearch.sdk.model.*;
@@ -1448,4 +1449,70 @@ public TaskInfo compact() throws MeilisearchException {
14481449
null,
14491450
TaskInfo.class);
14501451
}
1452+
1453+
/**
1454+
* Returns the current value of the facetSearch setting for the index.
1455+
*
1456+
* @return Returns the current value of the facetSearch setting.
1457+
* @throws MeilisearchException If the Authorization header is missing or index not found
1458+
*/
1459+
public Boolean getFacetSearchSettings() throws MeilisearchException {
1460+
return this.settingsHandler.getFacetSearch(this.uid);
1461+
}
1462+
1463+
/**
1464+
* Updates the facetSearch setting for the index. Send the new value in the request body; send
1465+
* null to reset to default.
1466+
*
1467+
* @param isEnabled New value for the setting
1468+
* @return A summarized view of a task, returned when a task is enqueued
1469+
* @throws MeilisearchException If the Authorization header is missing or index not found.
1470+
*/
1471+
public TaskInfo updateFacetSearchSettings(Boolean isEnabled) throws MeilisearchException {
1472+
return this.settingsHandler.updateFacetSearch(this.uid, isEnabled);
1473+
}
1474+
1475+
/**
1476+
* Resets the facetSearch setting to its default value.
1477+
*
1478+
* @return A summarized view of a task, returned when a task is enqueued
1479+
* @throws MeilisearchException If the Authorization header is missing or index not found.
1480+
*/
1481+
public TaskInfo resetFacetSearchSettings() throws MeilisearchException {
1482+
return this.settingsHandler.resetFacetSearch(this.uid);
1483+
}
1484+
1485+
/**
1486+
* Returns the current value of the prefixSearch setting for the index.
1487+
*
1488+
* @return The current value of the prefixSearch setting.
1489+
* @throws MeilisearchException If the Authorization header is missing or index not found.
1490+
*/
1491+
public PrefixSearchSetting getPrefixSearchSettings() throws MeilisearchException {
1492+
return this.settingsHandler.getPrefixSearch(this.uid);
1493+
}
1494+
1495+
/**
1496+
* Updates the prefixSearch setting for the index. Send the new value in the request body; send
1497+
* null to reset to default.
1498+
*
1499+
* @param updatedPrefixSetting The body is of type enum. Available options: indexingTime,
1500+
* disabled
1501+
* @return A summarized view of a task, returned when a task is enqueued
1502+
* @throws MeilisearchException If the Authorization header is missing or index not found.
1503+
*/
1504+
public TaskInfo updatePrefixSearchSettings(PrefixSearchSetting updatedPrefixSetting)
1505+
throws MeilisearchException {
1506+
return this.settingsHandler.updatePrefixSearch(this.uid, updatedPrefixSetting);
1507+
}
1508+
1509+
/**
1510+
* Resets the prefixSearch setting to its default value.
1511+
*
1512+
* @return A summarized view of a task, returned when a task is enqueued
1513+
* @throws MeilisearchException If the Authorization header is missing or index not found.
1514+
*/
1515+
public TaskInfo resetPrefixSearchSettings() throws MeilisearchException {
1516+
return this.settingsHandler.resetPrefixSearch(this.uid);
1517+
}
14511518
}

src/main/java/com/meilisearch/sdk/SettingsHandler.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.meilisearch.sdk;
22

3+
import com.meilisearch.sdk.enums.PrefixSearchSetting;
34
import com.meilisearch.sdk.exceptions.MeilisearchException;
45
import com.meilisearch.sdk.http.URLBuilder;
56
import com.meilisearch.sdk.model.Embedder;
@@ -853,4 +854,76 @@ TaskInfo resetEmbedders(String uid) throws MeilisearchException {
853854
return httpClient.delete(
854855
settingsPath(uid).addSubroute("embedders").getURL(), TaskInfo.class);
855856
}
857+
858+
/**
859+
* Returns the current value of the facetSearch setting for the index.
860+
*
861+
* @return Returns the current value of the facetSearch setting.
862+
* @throws MeilisearchException If the Authorization header is missing or index not found
863+
*/
864+
Boolean getFacetSearch(String uid) throws MeilisearchException {
865+
return httpClient.get(
866+
settingsPath(uid).addSubroute("facet-search").getURL(), Boolean.class);
867+
}
868+
869+
/**
870+
* Updates the facetSearch setting for the index. Send the new value in the request body; send
871+
* null to reset to default.
872+
*
873+
* @param isEnabled New value for the setting
874+
* @return A summarized view of a task, returned when a task is enqueued
875+
* @throws MeilisearchException If the Authorization header is missing or index not found.
876+
*/
877+
TaskInfo updateFacetSearch(String uid, Boolean isEnabled) throws MeilisearchException {
878+
return httpClient.put(
879+
settingsPath(uid).addSubroute("facet-search").getURL(), isEnabled, TaskInfo.class);
880+
}
881+
882+
/**
883+
* Resets the facetSearch setting to its default value.
884+
*
885+
* @return A summarized view of a task, returned when a task is enqueued
886+
* @throws MeilisearchException If the Authorization header is missing or index not found.
887+
*/
888+
TaskInfo resetFacetSearch(String uid) throws MeilisearchException {
889+
return httpClient.delete(
890+
settingsPath(uid).addSubroute("facet-search").getURL(), TaskInfo.class);
891+
}
892+
893+
/**
894+
* Returns the current value of the prefixSearch setting for the index.
895+
*
896+
* @return The current value of the prefixSearch setting.
897+
* @throws MeilisearchException If the Authorization header is missing or index not found.
898+
*/
899+
PrefixSearchSetting getPrefixSearch(String uid) throws MeilisearchException {
900+
return httpClient.get(
901+
settingsPath(uid).addSubroute("prefix-search").getURL(), PrefixSearchSetting.class);
902+
}
903+
904+
/**
905+
* Updates the prefixSearch setting for the index. Send the new value in the request body; send
906+
* null to reset to default.
907+
*
908+
* @return A summarized view of a task, returned when a task is enqueued
909+
* @throws MeilisearchException If the Authorization header is missing or index not found.
910+
*/
911+
TaskInfo updatePrefixSearch(String uid, PrefixSearchSetting prefixSearchSetting)
912+
throws MeilisearchException {
913+
return httpClient.put(
914+
settingsPath(uid).addSubroute("prefix-search").getURL(),
915+
prefixSearchSetting,
916+
TaskInfo.class);
917+
}
918+
919+
/**
920+
* Resets the prefixSearch setting to its default value.
921+
*
922+
* @return A summarized view of a task, returned when a task is enqueued
923+
* @throws MeilisearchException If the Authorization header is missing or index not found.
924+
*/
925+
TaskInfo resetPrefixSearch(String uid) throws MeilisearchException {
926+
return httpClient.delete(
927+
settingsPath(uid).addSubroute("prefix-search").getURL(), TaskInfo.class);
928+
}
856929
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.meilisearch.sdk.enums;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
public enum PrefixSearchSetting {
6+
@SerializedName("indexingTime")
7+
INDEXING_TIME,
8+
@SerializedName("disabled")
9+
DISABLED
10+
}

src/main/java/com/meilisearch/sdk/model/Settings.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.meilisearch.sdk.model;
22

3+
import com.meilisearch.sdk.enums.PrefixSearchSetting;
34
import java.util.HashMap;
45
import lombok.AccessLevel;
56
import lombok.Getter;
@@ -38,6 +39,8 @@ public class Settings {
3839
protected String[] nonSeparatorTokens;
3940
protected HashMap<String, Embedder> embedders;
4041
protected LocalizedAttribute[] localizedAttributes;
42+
protected Boolean facetSearch;
43+
protected PrefixSearchSetting prefixSearch;
4144

4245
public Settings() {}
4346

src/test/java/com/meilisearch/integration/SettingsTest.java

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.meilisearch.integration.classes.AbstractIT;
1818
import com.meilisearch.integration.classes.TestData;
1919
import com.meilisearch.sdk.Index;
20+
import com.meilisearch.sdk.enums.PrefixSearchSetting;
2021
import com.meilisearch.sdk.exceptions.GranularFilterableAttributesException;
2122
import com.meilisearch.sdk.model.Embedder;
2223
import com.meilisearch.sdk.model.EmbedderDistribution;
@@ -1639,4 +1640,87 @@ public void testResetEmbeddersSettings() throws Exception {
16391640
Map<String, Embedder> resetEmbedders = index.getEmbeddersSettings();
16401641
assertThat(resetEmbedders.size(), is(equalTo(0)));
16411642
}
1643+
1644+
@Test
1645+
@DisplayName("Test get prefix search settings")
1646+
public void testGetPrefixSearch() throws Exception {
1647+
Index index = createEmptyIndex("testGetPrefixSearchSettings");
1648+
Settings initialSettings = index.getSettings();
1649+
1650+
PrefixSearchSetting searchSetting = index.getPrefixSearchSettings();
1651+
1652+
assertThat(searchSetting, is(instanceOf(PrefixSearchSetting.class)));
1653+
assertThat(searchSetting, is(equalTo(initialSettings.getPrefixSearch())));
1654+
}
1655+
1656+
@Test
1657+
@DisplayName("Test update prefix search settings")
1658+
public void testUpdatePrefixSearch() throws Exception {
1659+
Index index = createEmptyIndex("testUpdatePrefixSearchSettings");
1660+
1661+
PrefixSearchSetting newSetting = PrefixSearchSetting.DISABLED;
1662+
var task = index.updatePrefixSearchSettings(newSetting);
1663+
index.waitForTask(task.getTaskUid());
1664+
Settings initialSettings = index.getSettings();
1665+
1666+
assertThat(newSetting, is(equalTo(initialSettings.getPrefixSearch())));
1667+
1668+
PrefixSearchSetting newSetting1 = PrefixSearchSetting.INDEXING_TIME;
1669+
var task1 = index.updatePrefixSearchSettings(newSetting1);
1670+
index.waitForTask(task1.getTaskUid());
1671+
Settings initialSettings1 = index.getSettings();
1672+
1673+
assertThat(newSetting1, is(equalTo(initialSettings1.getPrefixSearch())));
1674+
}
1675+
1676+
@Test
1677+
@DisplayName("Test delete prefix search settings")
1678+
public void testResetPrefixSearch() throws Exception {
1679+
Index index = createEmptyIndex("testDeletePrefixSearchSettings");
1680+
PrefixSearchSetting newSetting = PrefixSearchSetting.DISABLED;
1681+
1682+
TaskInfo task = index.updatePrefixSearchSettings(newSetting);
1683+
index.waitForTask(task.getTaskUid());
1684+
1685+
TaskInfo task1 = index.resetPrefixSearchSettings();
1686+
index.waitForTask(task1.getTaskUid());
1687+
Settings settings = index.getSettings();
1688+
1689+
assertThat(settings.getPrefixSearch(), is(equalTo(PrefixSearchSetting.INDEXING_TIME)));
1690+
}
1691+
1692+
@Test
1693+
@DisplayName("Test get facet search settings")
1694+
public void testGetFacetSearch() throws Exception {
1695+
Index index = createEmptyIndex("testGetFacetSearchSettings");
1696+
Settings initialSettings = index.getSettings();
1697+
1698+
Boolean facetSetting = index.getFacetSearchSettings();
1699+
1700+
assertThat(facetSetting, is(equalTo(initialSettings.getFacetSearch())));
1701+
}
1702+
1703+
@Test
1704+
@DisplayName("Test update facet search settings")
1705+
public void testUpdateFacetSearch() throws Exception {
1706+
Index index = createEmptyIndex("testUpdateFacetSearchSettings");
1707+
1708+
var task = index.updateFacetSearchSettings(false);
1709+
index.waitForTask(task.getTaskUid());
1710+
Settings newSetting = index.getSettings();
1711+
1712+
assertThat(false, is(equalTo(newSetting.getFacetSearch())));
1713+
}
1714+
1715+
@Test
1716+
@DisplayName("Test reset facet search settings")
1717+
public void testResetFacetSearch() throws Exception {
1718+
Index index = createEmptyIndex("testResetFacetSearchSettings");
1719+
1720+
TaskInfo task = index.resetFacetSearchSettings();
1721+
index.waitForTask(task.getTaskUid());
1722+
Settings settings = index.getSettings();
1723+
1724+
assertThat(true, is(equalTo(settings.getFacetSearch())));
1725+
}
16421726
}

0 commit comments

Comments
 (0)