Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,22 @@ update_localized_attribute_settings_1: |-
);
reset_localized_attribute_settings_1: |-
client.index("INDEX_NAME").resetLocalizedAttributesSettings();
get_foreign_keys_setting_1: |-
client.index("INDEX_NAME").getForeignKeysSettings();
update_foreign_keys_setting_1: |-
ForeignKey firstForeignKey = new ForeignKey();
firstForeignKey.setForeignIndexUid("authors");
firstForeignKey.setFieldName("author");

ForeignKey secondForeignKey = new ForeignKey();
secondForeignKey.setForeignIndexUid("authors");
secondForeignKey.setFieldName("related_authors");

client.index("books").updateForeignKeysSettings(
new ForeignKey[]{firstForeignKey, secondForeignKey}
);
reset_foreign_keys_setting_1: |-
client.index("INDEX_NAME").resetForeignKeysSettings();
export_post_1: |-
Map<String, ExportIndexFilter> indexes = new HashMap<>();
indexes.put("*", ExportIndexFilter.builder().overrideSettings(true).build());
Expand All @@ -639,4 +655,4 @@ webhooks_patch_1: |-

Webhook updated_webhook = this.client.updateWebhook(webhook.getUuid(), webhookReq2);
webhooks_delete_1: |-
this.client.deleteWebhook("WEBHOOK_UUID");
this.client.deleteWebhook("WEBHOOK_UUID");
16 changes: 9 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ jacocoTestReport {
}

tasks.register('integrationTest', Test) {
useJUnitPlatform {
includeTags 'integration'
}
testLogging {
events 'passed', 'skipped', 'failed'
showStandardStreams = System.getenv('DEBUG') != null
}
testClassesDirs = sourceSets.test.output.classesDirs // tells Gradle WHERE test classes are
classpath = sourceSets.test.runtimeClasspath // gives JUnit all dependencies it needs
useJUnitPlatform {
includeTags 'integration'
}
testLogging {
events 'passed', 'skipped', 'failed'
showStandardStreams = System.getenv('DEBUG') != null
}
}

java {
Expand Down
186 changes: 93 additions & 93 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions src/main/java/com/meilisearch/sdk/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,49 @@ public TaskInfo resetEmbeddersSettings() throws MeilisearchException {
return this.settingsHandler.resetEmbedders(this.uid);
}

/**
* Gets the foreign keys settings of the index.
*
* <p>Foreign keys are an experimental feature (Meilisearch v1.39+) that allow cross-index
* document hydration. The user must enable this experimental feature on their Meilisearch
* instance before using these settings.
*
* @return an array of ForeignKey that describes cross-index relationships
* @throws MeilisearchException if an error occurs
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings/get-foreignkeys">API
* specification</a>
*/
public ForeignKey[] getForeignKeysSettings() throws MeilisearchException {
// Delegates to SettingsHandler, passing the index uid.
return this.settingsHandler.getForeignKeysSettings(this.uid);
}

/**
* Updates the foreign keys settings of the index.
*
* @param foreignKeys an array of ForeignKey objects describing cross-index relationships
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings/update-foreignkeys">API
* specification</a>
*/
public TaskInfo updateForeignKeysSettings(ForeignKey[] foreignKeys)
throws MeilisearchException {
return this.settingsHandler.updateForeignKeysSettings(this.uid, foreignKeys);
}

/**
* Resets the foreign keys settings of the index to the default (empty) value.
*
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings/reset-foreignkeys">API
* specification</a>
*/
public TaskInfo resetForeignKeysSettings() throws MeilisearchException {
return this.settingsHandler.resetForeignKeysSettings(this.uid);
}

/**
* Compacts the database for this index to reclaim unused space
*
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/com/meilisearch/sdk/SettingsHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.meilisearch.sdk.model.Faceting;
import com.meilisearch.sdk.model.FilterableAttributesConfig;
import com.meilisearch.sdk.model.FilterableAttributesLegacyAdapter;
import com.meilisearch.sdk.model.ForeignKey;
import com.meilisearch.sdk.model.LocalizedAttribute;
import com.meilisearch.sdk.model.Pagination;
import com.meilisearch.sdk.model.Settings;
Expand Down Expand Up @@ -853,4 +854,61 @@ TaskInfo resetEmbedders(String uid) throws MeilisearchException {
return httpClient.delete(
settingsPath(uid).addSubroute("embedders").getURL(), TaskInfo.class);
}

/**
* Gets the foreign keys settings of the index.
*
* <p>Foreign keys are an experimental feature (Meilisearch v1.39+) that allow cross-index
* document hydration. The user must enable this experimental feature on their Meilisearch
* instance before using these settings.
*
* @param uid Index identifier
* @return an array of ForeignKey that contains the foreign keys settings
* @throws MeilisearchException if an error occurs
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings/get-foreignkeys">API
* specification</a>
*/
ForeignKey[] getForeignKeysSettings(String uid) throws MeilisearchException {
// GET /indexes/{uid}/settings/foreign-keys
// Returns an array of ForeignKey objects, each with a foreignIndexUid and fieldName.
return httpClient.get(
settingsPath(uid).addSubroute("foreign-keys").getURL(), ForeignKey[].class);
}

/**
* Updates the foreign keys settings of the index.
*
* @param uid Index identifier
* @param foreignKeys an array of ForeignKey objects describing cross-index relationships
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings/update-foreignkeys">API
* specification</a>
*/
TaskInfo updateForeignKeysSettings(String uid, ForeignKey[] foreignKeys)
throws MeilisearchException {
// PUT /indexes/{uid}/settings/foreign-keys
// If foreignKeys is null, we encode it as a JSON null to reset the setting.
// Otherwise we send the array directly and let the HTTP client serialize it to JSON.
return httpClient.put(
settingsPath(uid).addSubroute("foreign-keys").getURL(),
foreignKeys == null ? httpClient.jsonHandler.encode(foreignKeys) : foreignKeys,
TaskInfo.class);
}

/**
* Resets the foreign keys settings of the index to the default (empty) value.
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings/reset-foreignkeys">API
* specification</a>
*/
TaskInfo resetForeignKeysSettings(String uid) throws MeilisearchException {
// DELETE /indexes/{uid}/settings/foreign-keys resets the setting to its default empty
// value.
return httpClient.delete(
settingsPath(uid).addSubroute("foreign-keys").getURL(), TaskInfo.class);
}
}
28 changes: 28 additions & 0 deletions src/main/java/com/meilisearch/sdk/model/ForeignKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.meilisearch.sdk.model;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
* ForeignKey setting data structure for cross-index document hydration.
*
* <p>Each ForeignKey entry links a field in the current index to a field in another index, allowing
* search results to be automatically enriched with related data.
*
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings/get-foreignkeys">API
* specification</a>
*/
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class ForeignKey {

// The uid of the foreign (related) index this entry points to.
protected String foreignIndexUid;

// The name of the field in the current index that holds the foreign key value.
protected String fieldName;
}
4 changes: 4 additions & 0 deletions src/main/java/com/meilisearch/sdk/model/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public class Settings {
protected HashMap<String, Embedder> embedders;
protected LocalizedAttribute[] localizedAttributes;

// Holds the list of foreign key relationships for cross-index document hydration.
// This is an experimental Meilisearch feature (v1.39+).
protected ForeignKey[] foreignKeys;

public Settings() {}

/** Granular filterable attributes accessor. */
Expand Down
Loading