getPersonalizationProfileAsync(
+ @Nonnull String userToken, RequestOptions requestOptions) {
+ Objects.requireNonNull(userToken, "userToken is required.");
+ return transport.executeRequestAsync(
+ HttpMethod.GET,
+ "1/profiles/personalization/" + userToken,
+ CallType.READ,
+ PersonalizationProfileResponse.class,
+ requestOptions);
+ }
+
+ /**
+ * Delete the user profile and all its associated data.
+ *
+ * Returns, as part of the response, a date until which the data can safely be considered as
+ * deleted for the given user. This means that if you send events for the given user before this
+ * date, they will be ignored. Any data received after the deletedUntil date will start building a
+ * new user profile.
+ *
+ *
It might take a couple hours before for the deletion request to be fully processed.
+ *
+ * @param userToken userToken representing the user for which to delete the Personalization
+ * profile and associated data.
+ * @throws AlgoliaRetryException When the retry has failed on all hosts
+ * @throws AlgoliaApiException When the API sends an http error code
+ * @throws AlgoliaRuntimeException When an error occurred during the serialization
+ */
+ public DeletePersonalizationProfileResponse deletePersonalizationProfile(
+ @Nonnull String userToken) {
+ return LaunderThrowable.await(deletePersonalizationProfileAsync(userToken));
+ }
+
+ /**
+ * Delete the user profile and all its associated data.
+ *
+ *
Returns, as part of the response, a date until which the data can safely be considered as
+ * deleted for the given user. This means that if you send events for the given user before this
+ * date, they will be ignored. Any data received after the deletedUntil date will start building a
+ * new user profile.
+ *
+ *
It might take a couple hours before for the deletion request to be fully processed.
+ *
+ * @param userToken userToken representing the user for which to delete the Personalization
+ * profile and associated data.
+ * @param requestOptions Options to pass to this request
+ * @throws AlgoliaRetryException When the retry has failed on all hosts
+ * @throws AlgoliaApiException When the API sends an http error code
+ * @throws AlgoliaRuntimeException When an error occurred during the serialization
+ */
+ public DeletePersonalizationProfileResponse deletePersonalizationProfile(
+ @Nonnull String userToken, RequestOptions requestOptions) {
+ return LaunderThrowable.await(deletePersonalizationProfileAsync(userToken, requestOptions));
+ }
+
+ /**
+ * Delete the user profile and all its associated data.
+ *
+ *
Returns, as part of the response, a date until which the data can safely be considered as
+ * deleted for the given user. This means that if you send events for the given user before this
+ * date, they will be ignored. Any data received after the deletedUntil date will start building a
+ * new user profile.
+ *
+ *
It might take a couple hours before for the deletion request to be fully processed.
+ *
+ * @param userToken userToken representing the user for which to delete the Personalization
+ * profile and associated data.
+ * @throws AlgoliaRetryException When the retry has failed on all hosts
+ * @throws AlgoliaApiException When the API sends an http error code
+ * @throws AlgoliaRuntimeException When an error occurred during the serialization
+ */
+ public CompletableFuture deletePersonalizationProfileAsync(
+ @Nonnull String userToken) {
+ return deletePersonalizationProfileAsync(userToken, null);
+ }
+
+ /**
+ * Delete the user profile and all its associated data.
+ *
+ * Returns, as part of the response, a date until which the data can safely be considered as
+ * deleted for the given user. This means that if you send events for the given user before this
+ * date, they will be ignored. Any data received after the deletedUntil date will start building a
+ * new user profile.
+ *
+ *
It might take a couple hours before for the deletion request to be fully processed.
+ *
+ * @param userToken userToken representing the user for which to delete the Personalization
+ * profile and associated data.
+ * @param requestOptions Options to pass to this request
+ * @throws AlgoliaRetryException When the retry has failed on all hosts
+ * @throws AlgoliaApiException When the API sends an http error code
+ * @throws AlgoliaRuntimeException When an error occurred during the serialization
+ */
+ public CompletableFuture deletePersonalizationProfileAsync(
+ @Nonnull String userToken, RequestOptions requestOptions) {
+ Objects.requireNonNull(userToken, "userToken is required.");
+ return transport.executeRequestAsync(
+ HttpMethod.DELETE,
+ "1/profiles/" + userToken,
+ CallType.WRITE,
+ DeletePersonalizationProfileResponse.class,
+ requestOptions);
+ }
+
+ /** Get Client's configuration */
+ public ConfigBase getConfig() {
+ return config;
+ }
+}
diff --git a/algoliasearch-core/src/main/java/com/algolia/search/PersonalizationConfig.java b/algoliasearch-core/src/main/java/com/algolia/search/PersonalizationConfig.java
new file mode 100644
index 000000000..455be30c4
--- /dev/null
+++ b/algoliasearch-core/src/main/java/com/algolia/search/PersonalizationConfig.java
@@ -0,0 +1,54 @@
+package com.algolia.search;
+
+import com.algolia.search.models.common.CallType;
+import com.algolia.search.models.common.CompressionType;
+import com.algolia.search.util.AlgoliaUtils;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Objects;
+import javax.annotation.Nonnull;
+
+public class PersonalizationConfig extends ConfigBase {
+
+ public static class Builder extends ConfigBase.Builder {
+ /**
+ * Creates an {@link PersonalizationConfig} with the default hosts
+ *
+ * @param applicationID The Application ID
+ * @param apiKey The API Key
+ * @param region Region where your personalization data is stored and processed.
+ */
+ public Builder(@Nonnull String applicationID, @Nonnull String apiKey, @Nonnull String region) {
+ super(applicationID, apiKey, createPersonalizationHosts(region), CompressionType.NONE);
+ }
+
+ @Override
+ public PersonalizationConfig.Builder getThis() {
+ return this;
+ }
+
+ public PersonalizationConfig build() {
+ return new PersonalizationConfig(this);
+ }
+
+ /** Create hosts for the recommendation configuration */
+ private static List createPersonalizationHosts(@Nonnull String region) {
+
+ Objects.requireNonNull(region, "The region can't be null");
+
+ if (AlgoliaUtils.isEmptyWhiteSpace(region)) {
+ throw new IllegalArgumentException("The region is required. It can't be empty.");
+ }
+
+ return Collections.singletonList(
+ new StatefulHost(
+ String.format("personalization.%s.algolia.com", region),
+ EnumSet.of(CallType.READ, CallType.WRITE)));
+ }
+ }
+
+ private PersonalizationConfig(Builder builder) {
+ super(builder);
+ }
+}
diff --git a/algoliasearch-core/src/main/java/com/algolia/search/RecommendationClient.java b/algoliasearch-core/src/main/java/com/algolia/search/RecommendationClient.java
index 109688ec2..f915aac34 100644
--- a/algoliasearch-core/src/main/java/com/algolia/search/RecommendationClient.java
+++ b/algoliasearch-core/src/main/java/com/algolia/search/RecommendationClient.java
@@ -1,6 +1,8 @@
package com.algolia.search;
-import com.algolia.search.exceptions.*;
+import com.algolia.search.exceptions.AlgoliaApiException;
+import com.algolia.search.exceptions.AlgoliaRetryException;
+import com.algolia.search.exceptions.AlgoliaRuntimeException;
import com.algolia.search.exceptions.LaunderThrowable;
import com.algolia.search.models.HttpMethod;
import com.algolia.search.models.RequestOptions;
@@ -21,8 +23,10 @@
* be reused and it's thread-safe.
*
* @see Algolia.com
+ * @deprecated use {@link PersonalizationClient} instead
*/
@SuppressWarnings({"WeakerAccess", "Unused"})
+@Deprecated
public class RecommendationClient implements Closeable {
/** The transport layer. Must be reused. */
diff --git a/algoliasearch-core/src/main/java/com/algolia/search/RecommendationConfig.java b/algoliasearch-core/src/main/java/com/algolia/search/RecommendationConfig.java
index 7ed4ddfd9..8493db9f2 100644
--- a/algoliasearch-core/src/main/java/com/algolia/search/RecommendationConfig.java
+++ b/algoliasearch-core/src/main/java/com/algolia/search/RecommendationConfig.java
@@ -9,6 +9,8 @@
import java.util.Objects;
import javax.annotation.Nonnull;
+/** @deprecated use {@link PersonalizationConfig} instead */
+@Deprecated
public class RecommendationConfig extends ConfigBase {
public static class Builder extends ConfigBase.Builder {
diff --git a/algoliasearch-core/src/main/java/com/algolia/search/SearchClientPersonalization.java b/algoliasearch-core/src/main/java/com/algolia/search/SearchClientPersonalization.java
index b6d8e8998..90cad4b0e 100644
--- a/algoliasearch-core/src/main/java/com/algolia/search/SearchClientPersonalization.java
+++ b/algoliasearch-core/src/main/java/com/algolia/search/SearchClientPersonalization.java
@@ -22,7 +22,7 @@ public interface SearchClientPersonalization extends SearchClientBase {
* @throws AlgoliaRetryException When the retry has failed on all hosts
* @throws AlgoliaApiException When the API sends an http error code
* @throws AlgoliaRuntimeException When an error occurred during the serialization
- * @deprecated Endpoint will be deprecated. Please use {@link RecommendationConfig} instead.
+ * @deprecated Endpoint will be deprecated. Please use {@link PersonalizationConfig} instead.
*/
@Deprecated
default GetStrategyResponse getPersonalizationStrategy() {
@@ -36,7 +36,7 @@ default GetStrategyResponse getPersonalizationStrategy() {
* @throws AlgoliaRetryException When the retry has failed on all hosts
* @throws AlgoliaApiException When the API sends an http error code
* @throws AlgoliaRuntimeException When an error occurred during the serialization
- * @deprecated Endpoint will be deprecated. Please use {@link RecommendationConfig} instead.
+ * @deprecated Endpoint will be deprecated. Please use {@link PersonalizationConfig} instead.
*/
@Deprecated
default GetStrategyResponse getPersonalizationStrategy(RequestOptions requestOptions) {
@@ -49,7 +49,7 @@ default GetStrategyResponse getPersonalizationStrategy(RequestOptions requestOpt
* @throws AlgoliaRetryException When the retry has failed on all hosts
* @throws AlgoliaApiException When the API sends an http error code
* @throws AlgoliaRuntimeException When an error occurred during the serialization
- * @deprecated Endpoint will be deprecated. Please use {@link RecommendationConfig} instead.
+ * @deprecated Endpoint will be deprecated. Please use {@link PersonalizationConfig} instead.
*/
@Deprecated
default CompletableFuture getPersonalizationStrategyAsync() {
@@ -63,7 +63,7 @@ default CompletableFuture getPersonalizationStrategyAsync()
* @throws AlgoliaRetryException When the retry has failed on all hosts
* @throws AlgoliaApiException When the API sends an http error code
* @throws AlgoliaRuntimeException When an error occurred during the serialization
- * @deprecated Endpoint will be deprecated. Please use {@link RecommendationConfig} instead.
+ * @deprecated Endpoint will be deprecated. Please use {@link PersonalizationConfig} instead.
*/
@Deprecated
default CompletableFuture getPersonalizationStrategyAsync(
@@ -84,7 +84,7 @@ default CompletableFuture getPersonalizationStrategyAsync(
* @throws AlgoliaRetryException When the retry has failed on all hosts
* @throws AlgoliaApiException When the API sends an http error code
* @throws AlgoliaRuntimeException When an error occurred during the serialization
- * @deprecated Endpoint will be deprecated. Please use {@link RecommendationConfig} instead.
+ * @deprecated Endpoint will be deprecated. Please use {@link PersonalizationConfig} instead.
*/
@Deprecated
default SetStrategyResponse setPersonalizationStrategy(@Nonnull SetStrategyRequest request) {
@@ -99,7 +99,7 @@ default SetStrategyResponse setPersonalizationStrategy(@Nonnull SetStrategyReque
* @throws AlgoliaRetryException When the retry has failed on all hosts
* @throws AlgoliaApiException When the API sends an http error code
* @throws AlgoliaRuntimeException When an error occurred during the serialization
- * @deprecated Endpoint will be deprecated. Please use {@link RecommendationConfig} instead.
+ * @deprecated Endpoint will be deprecated. Please use {@link PersonalizationConfig} instead.
*/
@Deprecated
default SetStrategyResponse setPersonalizationStrategy(
@@ -114,7 +114,7 @@ default SetStrategyResponse setPersonalizationStrategy(
* @throws AlgoliaRetryException When the retry has failed on all hosts
* @throws AlgoliaApiException When the API sends an http error code
* @throws AlgoliaRuntimeException When an error occurred during the serialization
- * @deprecated Endpoint will be deprecated. Please use {@link RecommendationConfig} instead.
+ * @deprecated Endpoint will be deprecated. Please use {@link PersonalizationConfig} instead.
*/
@Deprecated
default CompletableFuture setPersonalizationStrategyAsync(
@@ -130,7 +130,7 @@ default CompletableFuture setPersonalizationStrategyAsync(
* @throws AlgoliaRetryException When the retry has failed on all hosts
* @throws AlgoliaApiException When the API sends an http error code
* @throws AlgoliaRuntimeException When an error occurred during the serialization
- * @deprecated Endpoint will be deprecated. Please use {@link RecommendationConfig} instead.
+ * @deprecated Endpoint will be deprecated. Please use {@link PersonalizationConfig} instead.
*/
@Deprecated
default CompletableFuture setPersonalizationStrategyAsync(
diff --git a/algoliasearch-core/src/main/java/com/algolia/search/models/recommendation/DeletePersonalizationProfileResponse.java b/algoliasearch-core/src/main/java/com/algolia/search/models/recommendation/DeletePersonalizationProfileResponse.java
new file mode 100644
index 000000000..2e23364d9
--- /dev/null
+++ b/algoliasearch-core/src/main/java/com/algolia/search/models/recommendation/DeletePersonalizationProfileResponse.java
@@ -0,0 +1,28 @@
+package com.algolia.search.models.recommendation;
+
+/** Delete the user profile response. */
+public class DeletePersonalizationProfileResponse {
+
+ /** The user token representing the user and associated data. */
+ private String userToken;
+ /** Date until which the data can safely be considered as deleted for the given use. */
+ private String deletedUntil;
+
+ public String getUserToken() {
+ return userToken;
+ }
+
+ public DeletePersonalizationProfileResponse setUserToken(String userToken) {
+ this.userToken = userToken;
+ return this;
+ }
+
+ public String getDeletedUntil() {
+ return deletedUntil;
+ }
+
+ public DeletePersonalizationProfileResponse setDeletedUntil(String deletedUntil) {
+ this.deletedUntil = deletedUntil;
+ return this;
+ }
+}
diff --git a/algoliasearch-core/src/main/java/com/algolia/search/models/recommendation/PersonalizationProfileResponse.java b/algoliasearch-core/src/main/java/com/algolia/search/models/recommendation/PersonalizationProfileResponse.java
new file mode 100644
index 000000000..39bb6c4bc
--- /dev/null
+++ b/algoliasearch-core/src/main/java/com/algolia/search/models/recommendation/PersonalizationProfileResponse.java
@@ -0,0 +1,45 @@
+package com.algolia.search.models.recommendation;
+
+import java.util.Map;
+
+/** User profile built from Personalization strategy. */
+public class PersonalizationProfileResponse {
+
+ /** The user token representing the user and associated data. */
+ private String userToken;
+ /** The last processed event timestamp using the ISO 8601 format. */
+ private String lastEventAt;
+ /**
+ * The profile is structured by facet name used in the strategy. Each facet value is mapped to its
+ * score. Each score represents the user affinity for a specific facet value given the {@link
+ * #userToken} past events and the Personalization strategy defined. Scores are bounded to 20.
+ */
+ private Map scores;
+
+ public String getUserToken() {
+ return userToken;
+ }
+
+ public PersonalizationProfileResponse setUserToken(String userToken) {
+ this.userToken = userToken;
+ return this;
+ }
+
+ public String getLastEventAt() {
+ return lastEventAt;
+ }
+
+ public PersonalizationProfileResponse setLastEventAt(String lastEventAt) {
+ this.lastEventAt = lastEventAt;
+ return this;
+ }
+
+ public Map getScores() {
+ return scores;
+ }
+
+ public PersonalizationProfileResponse setScores(Map scores) {
+ this.scores = scores;
+ return this;
+ }
+}
diff --git a/algoliasearch-core/src/test/java/com/algolia/search/integration/recommendation/RecommendationTest.java b/algoliasearch-core/src/test/java/com/algolia/search/integration/personalization/PersonalizationTest.java
similarity index 81%
rename from algoliasearch-core/src/test/java/com/algolia/search/integration/recommendation/RecommendationTest.java
rename to algoliasearch-core/src/test/java/com/algolia/search/integration/personalization/PersonalizationTest.java
index 89a5be689..dd2ffb733 100644
--- a/algoliasearch-core/src/test/java/com/algolia/search/integration/recommendation/RecommendationTest.java
+++ b/algoliasearch-core/src/test/java/com/algolia/search/integration/personalization/PersonalizationTest.java
@@ -1,9 +1,9 @@
-package com.algolia.search.integration.recommendation;
+package com.algolia.search.integration.personalization;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import com.algolia.search.Defaults;
-import com.algolia.search.RecommendationClient;
+import com.algolia.search.PersonalizationClient;
import com.algolia.search.models.recommendation.EventsScoring;
import com.algolia.search.models.recommendation.FacetsScoring;
import com.algolia.search.models.recommendation.GetStrategyResponse;
@@ -14,16 +14,16 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-public abstract class RecommendationTest {
+public abstract class PersonalizationTest {
- private final RecommendationClient recommendationClient;
+ private final PersonalizationClient personalizationClient;
- protected RecommendationTest(RecommendationClient recommendationClient) {
- this.recommendationClient = recommendationClient;
+ protected PersonalizationTest(PersonalizationClient personalizationClient) {
+ this.personalizationClient = personalizationClient;
}
@Test
- void testRecommendationClient() {
+ void testPersonalizationClient() {
SetStrategyRequest request =
new SetStrategyRequest()
.setEventsScoring(
@@ -33,9 +33,9 @@ void testRecommendationClient() {
.setFacetsScoring(
Arrays.asList(new FacetsScoring("brand", 100), new FacetsScoring("categories", 10)))
.setPersonalizationImpact(0);
- Assertions.assertDoesNotThrow(() -> recommendationClient.setPersonalizationStrategy(request));
+ Assertions.assertDoesNotThrow(() -> personalizationClient.setPersonalizationStrategy(request));
- GetStrategyResponse response = recommendationClient.getPersonalizationStrategy();
+ GetStrategyResponse response = personalizationClient.getPersonalizationStrategy();
assertThat(response.getEventsScoring())
.usingRecursiveComparison()