Skip to content

Commit f1522a3

Browse files
authored
docs(java): small migration guide (#934)
1 parent 7744aa7 commit f1522a3

File tree

9 files changed

+68
-24
lines changed

9 files changed

+68
-24
lines changed

website/docs/clients/guides/customized-client-usage.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ client.search(
108108
.setHitsPerPage(50)
109109
)
110110
),
111+
MyObject.class,
111112
new RequestOptions()
112113
// This header is added to the request
113114
.addExtraHeader("additional-header", "hello")

website/docs/clients/guides/filtering-your-search.mdx

+10-5
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ client.search(
154154
.setQuery("<YOUR_QUERY>")
155155
.setFilters("actor:Scarlett Johansson")
156156
)
157-
)
157+
),
158+
Actor.class
158159
);
159160

160161
// Only "Tom Cruise" or "Scarlett Johansson" actor
@@ -166,7 +167,8 @@ client.search(
166167
.setQuery("<YOUR_QUERY>")
167168
.setFilters("actor:Tom Cruise OR actor:Scarlett Johansson")
168169
)
169-
)
170+
),
171+
Actor.class
170172
);
171173

172174
// Everything but "Nicolas Cage" actor
@@ -178,7 +180,8 @@ client.search(
178180
.setQuery("<YOUR_QUERY>")
179181
.setFilters("NOT actor:Nicolas Cage")
180182
)
181-
)
183+
),
184+
Actor.class
182185
);
183186
```
184187

@@ -256,7 +259,8 @@ client.search(
256259
.setQuery("<YOUR_QUERY>")
257260
.addFacetFilters("actor:Scarlett Johansson")
258261
)
259-
)
262+
),
263+
Actor.class
260264
);
261265

262266
// Only "Tom Cruise" or "Scarlett Johansson" actor
@@ -269,7 +273,8 @@ client.search(
269273
.addFacetFilters("actor:Tom Cruise")
270274
.addFacetFilters("actor:Scarlett Johansson")
271275
)
272-
)
276+
),
277+
Actor.class
273278
);
274279
```
275280

website/docs/clients/guides/retrieving-facets.mdx

+4-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ client.search(
8484
.addFacets("author")
8585
.addFacets("genre")
8686
)
87-
)
87+
),
88+
MyObject.class
8889
);
8990
```
9091

@@ -101,7 +102,8 @@ client.search(
101102
.setQuery("<YOUR_QUERY>")
102103
.addFacets("*")
103104
)
104-
)
105+
),
106+
MyObject.class
105107
);
106108
```
107109

website/docs/clients/guides/send-data-to-algolia.mdx

+5-3
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,12 @@ $client->waitForTask(<YOUR_INDEX_NAME>, $response['taskID']);
122122
<TabItem value="java">
123123

124124
```java
125-
class Actor {
126-
String name;
125+
import com.algolia.model.search.*;
127126

128-
Actor(String name) {
127+
class Actor extends Hit {
128+
public String name;
129+
130+
public Actor(String name) {
129131
this.name = name;
130132
}
131133
}

website/docs/clients/installation.mdx

+4-2
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,14 @@ client.saveObject("<YOUR_INDEX_NAME>", body);
178178
SearchMethodParams searchMethodParams = new SearchMethodParams();
179179
SearchQueries requests = new SearchQueries();
180180
requests.setIndexName("<YOUR_INDEX_NAME>");
181+
// Typo tolerant search
181182
requests.setQuery("my aloglia ojbect");
182183
searchMethodParams.setRequests(requests);
183184

184185
try {
185-
SearchResponse result = client.search(
186-
searchMethodParams
186+
SearchResponse<MyObject> result = client.search(
187+
searchMethodParams,
188+
MyObject.class
187189
);
188190
System.out.println(result);
189191
} catch (AlgoliaRuntimeException e) {

website/docs/clients/migration-guides/index.mdx

+11-5
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ client.search(
9393
.addAttributesToRetrieve("lastname")
9494
.setHitsPerPage(50)
9595
)
96-
)
96+
),
97+
MyObject.class
9798
);
9899
```
99100

@@ -153,8 +154,11 @@ const abTest = await abtestingClient.getABTest({
153154
<TabItem value="java">
154155

155156
```java
156-
// TODO
157+
import com.algolia.api.AbtestingClient;
158+
import com.algolia.model.abtesting.*;
157159

160+
AbtestingClient client = new AbtestingClient("<YOUR_APP_ID>", "<YOUR_API_KEY>");
161+
ABTest abTest = client.getABTest(42);
158162
```
159163

160164
</TabItem>
@@ -381,10 +385,12 @@ $client->batch(
381385
<TabItem value="java">
382386

383387
```java
384-
class Actor {
385-
String name;
388+
import com.algolia.model.search.*;
389+
390+
class Actor extends Hit {
391+
public String name;
386392

387-
Actor(String name) {
393+
public Actor(String name) {
388394
this.name = name;
389395
}
390396
}

website/docs/clients/migration-guides/java.md

+27-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,30 @@
22
title: Java
33
---
44

5-
WIP
5+
### Methods targeting an `indexName`
6+
7+
Prior to the `initIndex` removal stated in the [common breaking changes](/docs/clients/migration-guides/#common-breaking-changes), all methods previously available at the `initIndex` level requires the `indexName` to be sent with the query.
8+
9+
That also mean you need to explicit the type you want to be returned from your queries, when it applies.
10+
11+
```java
12+
import com.algolia.api.SearchClient;
13+
import com.algolia.model.search.*;
14+
15+
SearchClient client = new SearchClient("<YOUR_APP_ID>", "<YOUR_API_KEY>");
16+
17+
client.search(
18+
new SearchMethodParams()
19+
.addRequests(SearchQuery.of(
20+
new SearchForHits()
21+
.setIndexName("<YOUR_INDEX_NAME>")
22+
.setQuery("<YOUR_QUERY>")
23+
)
24+
),
25+
MyObject.class
26+
);
27+
```
28+
29+
30+
31+

website/docs/clients/migration-guides/javascript.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: JavaScript
33
---
44

55
| Previous | Latest | Description |
6-
| --------- | :------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
6+
|-----------|:---------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
77
| `search` | `searchClient` | Exported clients are suffixed by `Client`. |
88
| `destroy` | **removed** | This method has not been implemented in the new clients, if you feel the need for it, [please open an issue](https://github.com/algolia/api-clients-automation/issues/new?assignees=&labels=&template=Feature_request.md) |
99

website/docs/clients/migration-guides/php.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
title: PHP
33
---
44

5-
| Previous | Latest | Description |
6-
| -------------------- | :------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
7-
| `"algolia/algoliasearch-client-php": "^3.2"` | `"algolia/algoliasearch-client-php": "^4.0@alpha"` | **During the beta phase**, the clients are available under the package 4.x.x-alpha , you can find a full list [here](https://packagist.org/packages/algolia/algoliasearch-client-php). |
8-
| `Algolia\AlgoliaSearch` | `Algolia\AlgoliaSearch\Api` | Exported clients have now the namespace suffixed by `Api`. |
9-
| `Algolia\AlgoliaSearch\Cache\FileCacheDriver` | **removed** | This implementation of the `CacheInterface` is not available anymore in the Client. If you feel the need for it, [please open an issue](https://github.com/algolia/api-clients-automation/issues/new?assignees=&labels=&template=Feature_request.md) |
5+
| Previous | Latest | Description |
6+
|-----------------------------------------------|:---------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
7+
| `"algolia/algoliasearch-client-php": "^3.2"` | `"algolia/algoliasearch-client-php": "^4.0@alpha"` | **During the beta phase**, the clients are available under the package 4.x.x-alpha , you can find a full list [here](https://packagist.org/packages/algolia/algoliasearch-client-php). |
8+
| `Algolia\AlgoliaSearch` | `Algolia\AlgoliaSearch\Api` | Exported clients have now the namespace suffixed by `Api`. |
9+
| `Algolia\AlgoliaSearch\Cache\FileCacheDriver` | **removed** | This implementation of the `CacheInterface` is not available anymore in the Client. If you feel the need for it, [please open an issue](https://github.com/algolia/api-clients-automation/issues/new?assignees=&labels=&template=Feature_request.md) |
1010

1111

1212
### Usage

0 commit comments

Comments
 (0)