Skip to content

Commit 3d62612

Browse files
authored
docs(java): installation guide APIC-419 (#481)
1 parent d320ae7 commit 3d62612

File tree

2 files changed

+110
-6
lines changed

2 files changed

+110
-6
lines changed

.github/actions/setup/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ runs:
8787
id: gen-matrix
8888
shell: bash
8989
run: |
90-
if [[ steps.diff.outputs.JS_ALGOLIASEARCH_CHANGED > 0 ]]; then
90+
if [[ ${{ steps.diff.outputs.JS_ALGOLIASEARCH_CHANGED }} > 0 ]]; then
9191
echo "Running algoliasearch: true"
9292
echo "::set-output name=RUN_JS_ALGOLIASEARCH::true"
9393
fi
9494
95-
if [[ steps.diff.outputs.JS_UTILS_CHANGED > 0 ]]; then
95+
if [[ ${{ steps.diff.outputs.JS_UTILS_CHANGED }} > 0 ]]; then
9696
echo "Running JavaScript utils: true"
9797
echo "::set-output name=RUN_JS_UTILS::true"
9898
fi

website/docs/api-clients/installation.mdx

Lines changed: 108 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import TabItem from '@theme/TabItem';
77

88
<Tabs
99
groupId="language"
10-
defaultValue="js"
10+
defaultValue="javascript"
1111
values={[
12-
{ label: 'JavaScript', value: 'js', },
13-
{ label: 'PHP', value: 'php', }
12+
{ label: 'JavaScript', value: 'javascript', },
13+
{ label: 'PHP', value: 'php', },
14+
{ label: 'Java', value: 'java' }
1415
]
1516
}>
16-
<TabItem value="js">
17+
<TabItem value="javascript">
1718

1819
To get started, you first need to install `algoliasearch` (or any other available API client package). You can find the full list of available packages [here](https://www.npmjs.com/org/experimental-api-clients-automation).
1920

@@ -153,4 +154,107 @@ $res = $client->getUserTokenProfile('<YOUR_TOKEN>');
153154
```
154155

155156
</TabItem>
157+
158+
<TabItem value="java">
159+
160+
To get started, add the [algoliasearch-core](https://oss.sonatype.org/content/repositories/snapshots/com/algolia/algoliasearch-core/0.0.1-SNAPSHOT/) dependency to your project, either with [Maven](https://maven.apache.org/):
161+
```xml
162+
<repositories>
163+
<repository>
164+
<id>oss.sonatype.org-snapshot</id>
165+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
166+
<releases>
167+
<enabled>false</enabled>
168+
</releases>
169+
<snapshots>
170+
<enabled>true</enabled>
171+
</snapshots>
172+
</repository>
173+
</repositories>
174+
175+
<dependency>
176+
<groupId>com.algolia</groupId>
177+
<artifactId>algoliasearch-core</artifactId>
178+
<version>0.0.1-SNAPSHOT</version>
179+
</dependency>
180+
```
181+
182+
or [Gradle](https://gradle.org/):
183+
```groovy
184+
repositories() {
185+
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
186+
}
187+
188+
dependencies {
189+
testImplementation 'com.algolia:algoliasearch-core:0.0.1-SNAPSHOT'
190+
}
191+
```
192+
193+
## Using the client
194+
195+
The package is divided into multiples API Clients, you can find the list [here](https://github.com/algolia/algoliasearch-client-java-2/tree/next/algoliasearch-core/src/main/java/com/algolia/api).
196+
To instanciate a client, prepare your credentials and follow this example:
197+
198+
```java
199+
import com.algolia.api.SearchClient;
200+
201+
public class AlgoliaTest {
202+
public static void main(String[] args) {
203+
SearchClient client = new SearchClient("<YOUR_APP_ID>", "<YOUR_API_KEY>");
204+
}
205+
}
206+
```
207+
208+
You can add segments to the `User Agent`:
209+
```java
210+
import com.algolia.utils.UserAgent;
211+
212+
SearchClient client = new SearchClient(
213+
"<YOUR_APP_ID>",
214+
"<YOUR_API_KEY>",
215+
new UserAgent.Segment[] {
216+
new UserAgent.Segment("tracker", "8.0.0")
217+
}
218+
);
219+
```
220+
221+
And also specify a custom `Requester`:
222+
```java
223+
import com.algolia.utils.echo.EchoRequester;
224+
225+
SearchClient client = new SearchClient(
226+
"<YOUR_APP_ID>",
227+
"<YOUR_API_KEY>",
228+
new EchoRequester()
229+
);
230+
```
231+
232+
Or use a completely different client (some clients might require a `region` parameter):
233+
```java
234+
import com.algolia.api.AbtestingClient;
235+
236+
AbtestingClient client = new AbtestingClient("<YOUR_APP_ID>", "<YOUR_API_KEY>", "us");
237+
```
238+
239+
Once the client is setup, you can play with the Algolia API!
240+
241+
```java
242+
import com.algolia.model.search.*;
243+
244+
SearchParamsObject params = new SearchParamsObject();
245+
params.setQuery("your query");
246+
247+
try {
248+
SearchResponse result = client.search(
249+
"the index name",
250+
SearchParams.ofSearchParamsObject(params)
251+
);
252+
System.out.println(result);
253+
} catch (AlgoliaRuntimeException e) {
254+
e.printStackTrace();
255+
}
256+
```
257+
258+
</TabItem>
259+
156260
</Tabs>

0 commit comments

Comments
 (0)