Skip to content

Commit 4c9c7bc

Browse files
Merge main into feat/federated-distinct
MultiSearchFederation gained showPerformanceDetails on main while this branch added distinct. The setter conflict cut through a method whose closing 'return this;' both sides shared, so it is resolved as two complete setters rather than one with two signatures.
2 parents 99af7a2 + 740d3f6 commit 4c9c7bc

24 files changed

Lines changed: 758 additions & 18 deletions

.code-samples.meilisearch.yaml

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,14 @@ getting_started_add_documents: |-
391391
// <dependency>
392392
// <groupId>com.meilisearch.sdk</groupId>
393393
// <artifactId>meilisearch-java</artifactId>
394-
// <version>0.20.1</version>
394+
// <version>0.21.0</version>
395395
// <type>pom</type>
396396
// </dependency>
397397
398398
// For Gradle
399399
// Add the following line to the `dependencies` section of your `build.gradle`:
400400
//
401-
// implementation 'com.meilisearch.sdk:meilisearch-java:0.20.1'
401+
// implementation 'com.meilisearch.sdk:meilisearch-java:0.21.0'
402402
403403
// In your .java file:
404404
import com.meilisearch.sdk;
@@ -640,3 +640,50 @@ webhooks_patch_1: |-
640640
Webhook updated_webhook = this.client.updateWebhook(webhook.getUuid(), webhookReq2);
641641
webhooks_delete_1: |-
642642
this.client.deleteWebhook("WEBHOOK_UUID");
643+
644+
post_render_template_1: |-
645+
Map<String, Boolean> features = new HashMap<>();
646+
features.put("renderRoute", true);
647+
client.experimentalFeatures(features);
648+
649+
Map<String, Object> template = new HashMap<>();
650+
template.put("kind", "inlineDocumentTemplate");
651+
template.put("inline", "Product {{doc.name}} is a {{doc.color}} {{doc.category}}.");
652+
653+
Map<String, Object> product = new HashMap<>();
654+
product.put("name", "Nike Air Max");
655+
product.put("color", "Black");
656+
product.put("category", "Shoes");
657+
658+
Map<String, Object> input = new HashMap<>();
659+
input.put("kind", "inlineDocument");
660+
input.put("inline", product);
661+
662+
RenderTemplateRequest request = new RenderTemplateRequest()
663+
.setTemplate(template)
664+
.setInput(input);
665+
666+
client.renderTemplate(request);
667+
668+
669+
list_dynamic_search_rules_1: |-
670+
DynamicSearchRulesQuery query = new DynamicSearchRulesQuery();
671+
Results<DynamicSearchRule> rules = client.listDynamicSearchRules(query);
672+
get_dynamic_search_rule_1: |-
673+
DynamicSearchRule rule = client.getDynamicSearchRule("black-friday");
674+
patch_dynamic_search_rule_1: |-
675+
Map<String, Object> conditions = Map.of(
676+
"query", Map.of("isEmpty", true),
677+
"time", Map.of("start", "2025-11-28T00:00:00Z", "end", "2025-11-28T23:59:59Z"));
678+
679+
List<Map<String, Object>> actions = List.of(
680+
Map.of(
681+
"selector", Map.of("indexUid", "products", "id", "123"),
682+
"action", Map.of("type", "pin", "position", 1)));
683+
684+
DynamicSearchRule rule = new DynamicSearchRule(
685+
"black-friday", "Black Friday 2025 rules", 10, true, conditions, actions);
686+
687+
TaskInfo task = client.updateDynamicSearchRule("black-friday", rule);
688+
delete_dynamic_search_rule_1: |-
689+
TaskInfo task = client.deleteDynamicSearchRule("black-friday");

.github/release-draft-template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ categories:
1717
- title: '🔒 Security'
1818
label: 'security'
1919
- title: '⚙️ Maintenance/misc'
20-
label:
20+
labels:
2121
- 'dependencies'
2222
- 'maintenance'
2323
- 'documentation'

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Add the following code to the `<dependencies>` section of your project:
5757
<dependency>
5858
<groupId>com.meilisearch.sdk</groupId>
5959
<artifactId>meilisearch-java</artifactId>
60-
<version>0.20.1</version>
60+
<version>0.21.0</version>
6161
<type>pom</type>
6262
</dependency>
6363
```
@@ -67,7 +67,7 @@ Add the following code to the `<dependencies>` section of your project:
6767
Add the following line to the `dependencies` section of your `build.gradle`:
6868

6969
```groovy
70-
implementation 'com.meilisearch.sdk:meilisearch-java:0.20.1'
70+
implementation 'com.meilisearch.sdk:meilisearch-java:0.21.0'
7171
```
7272

7373
:warning: `meilisearch-java` also requires `okhttp` as a peer dependency.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ plugins {
1616
}
1717

1818
group = 'com.meilisearch.sdk'
19-
version = '0.20.1'
19+
version = '0.21.0'
2020

2121
base {
2222
archivesName.set('meilisearch-java')

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class Client {
2121
private KeysHandler keysHandler;
2222
private JsonHandler jsonHandler;
2323
private WebHooksHandler webHooksHandler;
24+
private DynamicSearchRulesHandler dynamicSearchRulesHandler;
2425

2526
/**
2627
* Calls instance for Meilisearch client
@@ -35,6 +36,7 @@ public Client(Config config) {
3536
this.keysHandler = new KeysHandler(config);
3637
this.jsonHandler = config.jsonHandler;
3738
this.webHooksHandler = new WebHooksHandler(config);
39+
this.dynamicSearchRulesHandler = new DynamicSearchRulesHandler(config);
3840
}
3941

4042
/**
@@ -482,6 +484,18 @@ public void experimentalFeatures(Map<String, Boolean> features) {
482484
this.config.httpClient.patch("/experimental-features", features, Void.class);
483485
}
484486

487+
/**
488+
* Renders a template using the experimental render-template route.
489+
*
490+
* @param request Render template request body
491+
* @return Rendered template result
492+
* @throws MeilisearchException if an error occurs
493+
*/
494+
public RenderTemplateResult renderTemplate(RenderTemplateRequest request)
495+
throws MeilisearchException {
496+
return this.config.httpClient.post("/render-template", request, RenderTemplateResult.class);
497+
}
498+
485499
public String generateTenantToken(String apiKeyUid, Map<String, Object> searchRules)
486500
throws MeilisearchException {
487501
return this.generateTenantToken(apiKeyUid, searchRules, new TenantTokenOptions());
@@ -612,4 +626,50 @@ private Boolean isValidUUID(String apiKeyUid) {
612626
}
613627
return true;
614628
}
629+
/**
630+
* Get a list of all dynamic search rules.
631+
*
632+
* @param query Query parameters for pagination and filtering (offset, limit, filter).
633+
* @return Results containing a list of DynamicSearchRule instances.
634+
* @throws MeilisearchException If an error occurs.
635+
*/
636+
public Results<DynamicSearchRule> listDynamicSearchRules(DynamicSearchRulesQuery query)
637+
throws MeilisearchException {
638+
return this.dynamicSearchRulesHandler.listDynamicSearchRules(query);
639+
}
640+
641+
/**
642+
* Get a single dynamic search rule by its uid.
643+
*
644+
* @param uid Unique identifier of the dynamic search rule.
645+
* @return A single DynamicSearchRule instance.
646+
* @throws MeilisearchException If an error occurs.
647+
*/
648+
public DynamicSearchRule getDynamicSearchRule(String uid) throws MeilisearchException {
649+
return this.dynamicSearchRulesHandler.getDynamicSearchRule(uid);
650+
}
651+
652+
/**
653+
* Create a new dynamic search rule, or update it if a rule with the given uid already exists.
654+
*
655+
* @param uid Unique identifier of the dynamic search rule.
656+
* @param dynamicSearchRule Request body containing the rule configuration.
657+
* @return TaskInfo instance for the enqueued upsert operation.
658+
* @throws MeilisearchException If an error occurs.
659+
*/
660+
public TaskInfo updateDynamicSearchRule(String uid, DynamicSearchRule dynamicSearchRule)
661+
throws MeilisearchException {
662+
return this.dynamicSearchRulesHandler.updateDynamicSearchRule(uid, dynamicSearchRule);
663+
}
664+
665+
/**
666+
* Delete a dynamic search rule.
667+
*
668+
* @param uid Unique identifier of the dynamic search rule.
669+
* @return TaskInfo instance for the enqueued delete operation.
670+
* @throws MeilisearchException If an error occurs.
671+
*/
672+
public TaskInfo deleteDynamicSearchRule(String uid) throws MeilisearchException {
673+
return this.dynamicSearchRulesHandler.deleteDynamicSearchRule(uid);
674+
}
615675
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.meilisearch.sdk;
2+
3+
import com.meilisearch.sdk.exceptions.MeilisearchException;
4+
import com.meilisearch.sdk.http.URLBuilder;
5+
import com.meilisearch.sdk.model.DynamicSearchRule;
6+
import com.meilisearch.sdk.model.DynamicSearchRulesQuery;
7+
import com.meilisearch.sdk.model.Results;
8+
import com.meilisearch.sdk.model.TaskInfo;
9+
10+
class DynamicSearchRulesHandler {
11+
private final HttpClient httpClient;
12+
13+
protected DynamicSearchRulesHandler(Config config) {
14+
httpClient = config.httpClient;
15+
}
16+
17+
Results<DynamicSearchRule> listDynamicSearchRules(DynamicSearchRulesQuery query)
18+
throws MeilisearchException {
19+
return httpClient.post(
20+
dynamicSearchRulesPath().getURL(), query, Results.class, DynamicSearchRule.class);
21+
}
22+
23+
DynamicSearchRule getDynamicSearchRule(String uid) throws MeilisearchException {
24+
return httpClient.get(
25+
dynamicSearchRulesPath().addSubroute(uid).getURL(), DynamicSearchRule.class);
26+
}
27+
28+
TaskInfo updateDynamicSearchRule(String uid, DynamicSearchRule dynamicSearchRule)
29+
throws MeilisearchException {
30+
return httpClient.patch(
31+
dynamicSearchRulesPath().addSubroute(uid).getURL(),
32+
dynamicSearchRule,
33+
TaskInfo.class);
34+
}
35+
36+
TaskInfo deleteDynamicSearchRule(String uid) throws MeilisearchException {
37+
return httpClient.delete(
38+
dynamicSearchRulesPath().addSubroute(uid).getURL(), TaskInfo.class);
39+
}
40+
41+
private URLBuilder dynamicSearchRulesPath() {
42+
return new URLBuilder("/dynamic-search-rules");
43+
}
44+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class MultiSearchFederation {
1212
private MergeFacets mergeFacets;
1313
private Map<String, String[]> facetsByIndex;
1414
private String distinct;
15+
private Boolean showPerformanceDetails;
1516

1617
public MultiSearchFederation setLimit(Integer limit) {
1718
this.limit = limit;
@@ -38,6 +39,11 @@ public MultiSearchFederation setDistinct(String distinct) {
3839
return this;
3940
}
4041

42+
public MultiSearchFederation setShowPerformanceDetails(Boolean showPerformanceDetails) {
43+
this.showPerformanceDetails = showPerformanceDetails;
44+
return this;
45+
}
46+
4147
/**
4248
* Method that returns the JSON String of the MultiSearchFederation
4349
*
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.meilisearch.sdk;
2+
3+
import java.util.Map;
4+
import lombok.AccessLevel;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Builder;
7+
import lombok.Getter;
8+
import lombok.Setter;
9+
import lombok.experimental.Accessors;
10+
import org.json.JSONObject;
11+
12+
@Builder
13+
@AllArgsConstructor(access = AccessLevel.PACKAGE)
14+
@Getter
15+
@Setter
16+
@Accessors(chain = true)
17+
public class RenderTemplateRequest {
18+
private Map<String, Object> template;
19+
private Map<String, Object> input;
20+
21+
public RenderTemplateRequest() {}
22+
23+
@Override
24+
public String toString() {
25+
JSONObject jsonObject = new JSONObject();
26+
jsonObject.put("template", this.template);
27+
jsonObject.putOpt("input", this.input);
28+
return jsonObject.toString();
29+
}
30+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class SearchRequest {
4646
protected Hybrid hybrid;
4747
protected Double[] vector;
4848
protected Boolean retrieveVectors;
49+
protected Boolean showPerformanceDetails;
4950
/**
5051
* Constructor for SearchRequest for building search queries with the default values: offset: 0,
5152
* limit: 20, attributesToRetrieve: ["*"], attributesToCrop: null, cropLength: 200,
@@ -110,7 +111,8 @@ public String toString() {
110111
.putOpt("locales", this.locales)
111112
.putOpt("distinct", this.distinct)
112113
.putOpt("vector", this.vector)
113-
.putOpt("retrieveVectors", this.retrieveVectors);
114+
.putOpt("retrieveVectors", this.retrieveVectors)
115+
.putOpt("showPerformanceDetails", this.showPerformanceDetails);
114116

115117
if (this.hybrid != null) {
116118
jsonObject.put("hybrid", this.hybrid.toJSONObject());

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class SimilarDocumentRequest {
2020
private Boolean showRankingScoreDetails;
2121
private Double rankingScoreThreshold;
2222
private Boolean retrieveVectors;
23+
private Boolean showPerformanceDetails;
2324

2425
/** Constructor for SimilarDocumentsRequest for building search request for similar documents */
2526
public SimilarDocumentRequest() {}
@@ -37,6 +38,7 @@ public String toString() {
3738
jsonObject.putOpt("showRankingScoreDetails", this.showRankingScoreDetails);
3839
jsonObject.putOpt("rankingScoreThreshold", this.rankingScoreThreshold);
3940
jsonObject.putOpt("retrieveVectors", this.retrieveVectors);
41+
jsonObject.putOpt("showPerformanceDetails", this.showPerformanceDetails);
4042

4143
return jsonObject.toString();
4244
}

0 commit comments

Comments
 (0)