Skip to content

Commit c69a351

Browse files
algolia-botben-kalmusFluf22
committed
feat(specs): add sortBy query param and sortingStrategy (generated)
algolia/api-clients-automation#5686 Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com> Co-authored-by: Ben Kalmus <ben.kalmus@algolia.com> Co-authored-by: Thomas Raffray <Fluf22@users.noreply.github.com>
1 parent 217593e commit c69a351

File tree

3 files changed

+176
-24
lines changed

3 files changed

+176
-24
lines changed

algoliasearch/src/main/java/com/algolia/api/CompositionClient.java

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,4 +1513,97 @@ public CompletableFuture<SearchForFacetValuesResponse> searchForFacetValuesAsync
15131513
throws AlgoliaRuntimeException {
15141514
return this.searchForFacetValuesAsync(compositionID, facetName, null, null);
15151515
}
1516+
1517+
/**
1518+
* Updates the \"sortingStrategy\" field of an existing composition. This endpoint allows you to
1519+
* create a new sorting strategy mapping or replace the currently configured one. The provided
1520+
* sorting indices MUST be associated indices or replicas of the main targeted index. WARNING:
1521+
* This endpoint cannot validate if the sort index is related to the composition's main index.
1522+
* Validation will fail at runtime if the index you updated is not related! The update is applied
1523+
* to the specified composition within the current Algolia application and returns a taskID that
1524+
* can be used to track the operation’s completion.
1525+
*
1526+
* @param compositionID Unique Composition ObjectID. (required)
1527+
* @param requestBody (required)
1528+
* @param requestOptions The requestOptions to send along with the query, they will be merged with
1529+
* the transporter requestOptions.
1530+
* @throws AlgoliaRuntimeException If it fails to process the API call
1531+
*/
1532+
public TaskIDResponse updateSortingStrategyComposition(
1533+
@Nonnull String compositionID,
1534+
@Nonnull Map<String, String> requestBody,
1535+
@Nullable RequestOptions requestOptions
1536+
) throws AlgoliaRuntimeException {
1537+
return LaunderThrowable.await(updateSortingStrategyCompositionAsync(compositionID, requestBody, requestOptions));
1538+
}
1539+
1540+
/**
1541+
* Updates the \"sortingStrategy\" field of an existing composition. This endpoint allows you to
1542+
* create a new sorting strategy mapping or replace the currently configured one. The provided
1543+
* sorting indices MUST be associated indices or replicas of the main targeted index. WARNING:
1544+
* This endpoint cannot validate if the sort index is related to the composition's main index.
1545+
* Validation will fail at runtime if the index you updated is not related! The update is applied
1546+
* to the specified composition within the current Algolia application and returns a taskID that
1547+
* can be used to track the operation’s completion.
1548+
*
1549+
* @param compositionID Unique Composition ObjectID. (required)
1550+
* @param requestBody (required)
1551+
* @throws AlgoliaRuntimeException If it fails to process the API call
1552+
*/
1553+
public TaskIDResponse updateSortingStrategyComposition(@Nonnull String compositionID, @Nonnull Map<String, String> requestBody)
1554+
throws AlgoliaRuntimeException {
1555+
return this.updateSortingStrategyComposition(compositionID, requestBody, null);
1556+
}
1557+
1558+
/**
1559+
* (asynchronously) Updates the \"sortingStrategy\" field of an existing composition. This
1560+
* endpoint allows you to create a new sorting strategy mapping or replace the currently
1561+
* configured one. The provided sorting indices MUST be associated indices or replicas of the main
1562+
* targeted index. WARNING: This endpoint cannot validate if the sort index is related to the
1563+
* composition's main index. Validation will fail at runtime if the index you updated is not
1564+
* related! The update is applied to the specified composition within the current Algolia
1565+
* application and returns a taskID that can be used to track the operation’s completion.
1566+
*
1567+
* @param compositionID Unique Composition ObjectID. (required)
1568+
* @param requestBody (required)
1569+
* @param requestOptions The requestOptions to send along with the query, they will be merged with
1570+
* the transporter requestOptions.
1571+
* @throws AlgoliaRuntimeException If it fails to process the API call
1572+
*/
1573+
public CompletableFuture<TaskIDResponse> updateSortingStrategyCompositionAsync(
1574+
@Nonnull String compositionID,
1575+
@Nonnull Map<String, String> requestBody,
1576+
@Nullable RequestOptions requestOptions
1577+
) throws AlgoliaRuntimeException {
1578+
Parameters.requireNonNull(compositionID, "Parameter `compositionID` is required when calling `updateSortingStrategyComposition`.");
1579+
1580+
Parameters.requireNonNull(requestBody, "Parameter `requestBody` is required when calling `updateSortingStrategyComposition`.");
1581+
1582+
HttpRequest request = HttpRequest.builder()
1583+
.setPath("/1/compositions/{compositionID}/sortingStrategy", compositionID)
1584+
.setMethod("POST")
1585+
.setBody(requestBody)
1586+
.build();
1587+
return executeAsync(request, requestOptions, new TypeReference<TaskIDResponse>() {});
1588+
}
1589+
1590+
/**
1591+
* (asynchronously) Updates the \"sortingStrategy\" field of an existing composition. This
1592+
* endpoint allows you to create a new sorting strategy mapping or replace the currently
1593+
* configured one. The provided sorting indices MUST be associated indices or replicas of the main
1594+
* targeted index. WARNING: This endpoint cannot validate if the sort index is related to the
1595+
* composition's main index. Validation will fail at runtime if the index you updated is not
1596+
* related! The update is applied to the specified composition within the current Algolia
1597+
* application and returns a taskID that can be used to track the operation’s completion.
1598+
*
1599+
* @param compositionID Unique Composition ObjectID. (required)
1600+
* @param requestBody (required)
1601+
* @throws AlgoliaRuntimeException If it fails to process the API call
1602+
*/
1603+
public CompletableFuture<TaskIDResponse> updateSortingStrategyCompositionAsync(
1604+
@Nonnull String compositionID,
1605+
@Nonnull Map<String, String> requestBody
1606+
) throws AlgoliaRuntimeException {
1607+
return this.updateSortingStrategyCompositionAsync(compositionID, requestBody, null);
1608+
}
15161609
}

algoliasearch/src/main/java/com/algolia/model/composition/Composition.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import com.fasterxml.jackson.annotation.*;
77
import com.fasterxml.jackson.databind.annotation.*;
8+
import java.util.HashMap;
9+
import java.util.Map;
810
import java.util.Objects;
911

1012
/** Composition */
@@ -23,6 +25,9 @@ public class Composition implements BatchCompositionAction {
2325
@JsonProperty("behavior")
2426
private CompositionBehavior behavior;
2527

28+
@JsonProperty("sortingStrategy")
29+
private Map<String, String> sortingStrategy;
30+
2631
public Composition setObjectID(String objectID) {
2732
this.objectID = objectID;
2833
return this;
@@ -67,6 +72,33 @@ public CompositionBehavior getBehavior() {
6772
return behavior;
6873
}
6974

75+
public Composition setSortingStrategy(Map<String, String> sortingStrategy) {
76+
this.sortingStrategy = sortingStrategy;
77+
return this;
78+
}
79+
80+
public Composition putSortingStrategy(String key, String sortingStrategyItem) {
81+
if (this.sortingStrategy == null) {
82+
this.sortingStrategy = new HashMap<>();
83+
}
84+
this.sortingStrategy.put(key, sortingStrategyItem);
85+
return this;
86+
}
87+
88+
/**
89+
* A mapping of sorting labels to the indices (or replicas) that implement those sorting rules.
90+
* The sorting indices MUST be related to the associated main targeted index in the composition.
91+
* Each key is the label your frontend sends at runtime (for example, \"Price (asc)\"), and each
92+
* value is the name of the index that should be queried when that label is selected. When a
93+
* request includes a \"sortBy\" parameter, the platform looks up the corresponding index in this
94+
* mapping and uses it to execute the query. The main targeted index is replaced with the sorting
95+
* strategy index it is mapped to. Up to 20 sorting strategies can be defined.
96+
*/
97+
@javax.annotation.Nullable
98+
public Map<String, String> getSortingStrategy() {
99+
return sortingStrategy;
100+
}
101+
70102
@Override
71103
public boolean equals(Object o) {
72104
if (this == o) {
@@ -80,13 +112,14 @@ public boolean equals(Object o) {
80112
Objects.equals(this.objectID, composition.objectID) &&
81113
Objects.equals(this.name, composition.name) &&
82114
Objects.equals(this.description, composition.description) &&
83-
Objects.equals(this.behavior, composition.behavior)
115+
Objects.equals(this.behavior, composition.behavior) &&
116+
Objects.equals(this.sortingStrategy, composition.sortingStrategy)
84117
);
85118
}
86119

87120
@Override
88121
public int hashCode() {
89-
return Objects.hash(objectID, name, description, behavior);
122+
return Objects.hash(objectID, name, description, behavior, sortingStrategy);
90123
}
91124

92125
@Override
@@ -97,6 +130,7 @@ public String toString() {
97130
sb.append(" name: ").append(toIndentedString(name)).append("\n");
98131
sb.append(" description: ").append(toIndentedString(description)).append("\n");
99132
sb.append(" behavior: ").append(toIndentedString(behavior)).append("\n");
133+
sb.append(" sortingStrategy: ").append(toIndentedString(sortingStrategy)).append("\n");
100134
sb.append("}");
101135
return sb.toString();
102136
}

algoliasearch/src/main/java/com/algolia/model/composition/Params.java

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,18 @@ public class Params {
8989
@JsonProperty("query")
9090
private String query;
9191

92-
@JsonProperty("relevancyStrictness")
93-
private Integer relevancyStrictness;
94-
9592
@JsonProperty("queryLanguages")
9693
private List<SupportedLanguage> queryLanguages;
9794

95+
@JsonProperty("relevancyStrictness")
96+
private Integer relevancyStrictness;
97+
9898
@JsonProperty("ruleContexts")
9999
private List<String> ruleContexts;
100100

101+
@JsonProperty("sortBy")
102+
private String sortBy;
103+
101104
@JsonProperty("userToken")
102105
private String userToken;
103106

@@ -474,22 +477,6 @@ public String getQuery() {
474477
return query;
475478
}
476479

477-
public Params setRelevancyStrictness(Integer relevancyStrictness) {
478-
this.relevancyStrictness = relevancyStrictness;
479-
return this;
480-
}
481-
482-
/**
483-
* Relevancy threshold below which less relevant results aren't included in the results You can
484-
* only set `relevancyStrictness` on [virtual replica
485-
* indices](https://www.algolia.com/doc/guides/managing-results/refine-results/sorting/in-depth/replicas/#what-are-virtual-replicas).
486-
* Use this setting to strike a balance between the relevance and number of returned results.
487-
*/
488-
@javax.annotation.Nullable
489-
public Integer getRelevancyStrictness() {
490-
return relevancyStrictness;
491-
}
492-
493480
public Params setQueryLanguages(List<SupportedLanguage> queryLanguages) {
494481
this.queryLanguages = queryLanguages;
495482
return this;
@@ -522,6 +509,22 @@ public List<SupportedLanguage> getQueryLanguages() {
522509
return queryLanguages;
523510
}
524511

512+
public Params setRelevancyStrictness(Integer relevancyStrictness) {
513+
this.relevancyStrictness = relevancyStrictness;
514+
return this;
515+
}
516+
517+
/**
518+
* Relevancy threshold below which less relevant results aren't included in the results You can
519+
* only set `relevancyStrictness` on [virtual replica
520+
* indices](https://www.algolia.com/doc/guides/managing-results/refine-results/sorting/in-depth/replicas/#what-are-virtual-replicas).
521+
* Use this setting to strike a balance between the relevance and number of returned results.
522+
*/
523+
@javax.annotation.Nullable
524+
public Integer getRelevancyStrictness() {
525+
return relevancyStrictness;
526+
}
527+
525528
public Params setRuleContexts(List<String> ruleContexts) {
526529
this.ruleContexts = ruleContexts;
527530
return this;
@@ -545,6 +548,25 @@ public List<String> getRuleContexts() {
545548
return ruleContexts;
546549
}
547550

551+
public Params setSortBy(String sortBy) {
552+
this.sortBy = sortBy;
553+
return this;
554+
}
555+
556+
/**
557+
* Indicates which sorting strategy to apply for the request. The value must match one of the
558+
* labels defined in the \"sortingStrategy\" mapping. For example, \"Price (asc)\", see Upsert
559+
* Composition. At runtime, this label is used to look up the corresponding index or replica
560+
* configured in \"sortingStrategy\", and the query is executed using that index instead of
561+
* main's. In addition to \"sortingStrategy\", this parameter is also used to apply a matching
562+
* Composition Rule that contains a condition defined to trigger on \"sortBy\", see Composition
563+
* Rules. If no value is provided or an invalid value, no sorting strategy is applied.
564+
*/
565+
@javax.annotation.Nullable
566+
public String getSortBy() {
567+
return sortBy;
568+
}
569+
548570
public Params setUserToken(String userToken) {
549571
this.userToken = userToken;
550572
return this;
@@ -595,9 +617,10 @@ public boolean equals(Object o) {
595617
Objects.equals(this.optionalFilters, params.optionalFilters) &&
596618
Objects.equals(this.page, params.page) &&
597619
Objects.equals(this.query, params.query) &&
598-
Objects.equals(this.relevancyStrictness, params.relevancyStrictness) &&
599620
Objects.equals(this.queryLanguages, params.queryLanguages) &&
621+
Objects.equals(this.relevancyStrictness, params.relevancyStrictness) &&
600622
Objects.equals(this.ruleContexts, params.ruleContexts) &&
623+
Objects.equals(this.sortBy, params.sortBy) &&
601624
Objects.equals(this.userToken, params.userToken)
602625
);
603626
}
@@ -630,9 +653,10 @@ public int hashCode() {
630653
optionalFilters,
631654
page,
632655
query,
633-
relevancyStrictness,
634656
queryLanguages,
657+
relevancyStrictness,
635658
ruleContexts,
659+
sortBy,
636660
userToken
637661
);
638662
}
@@ -666,9 +690,10 @@ public String toString() {
666690
sb.append(" optionalFilters: ").append(toIndentedString(optionalFilters)).append("\n");
667691
sb.append(" page: ").append(toIndentedString(page)).append("\n");
668692
sb.append(" query: ").append(toIndentedString(query)).append("\n");
669-
sb.append(" relevancyStrictness: ").append(toIndentedString(relevancyStrictness)).append("\n");
670693
sb.append(" queryLanguages: ").append(toIndentedString(queryLanguages)).append("\n");
694+
sb.append(" relevancyStrictness: ").append(toIndentedString(relevancyStrictness)).append("\n");
671695
sb.append(" ruleContexts: ").append(toIndentedString(ruleContexts)).append("\n");
696+
sb.append(" sortBy: ").append(toIndentedString(sortBy)).append("\n");
672697
sb.append(" userToken: ").append(toIndentedString(userToken)).append("\n");
673698
sb.append("}");
674699
return sb.toString();

0 commit comments

Comments
 (0)