Skip to content

Commit 6a2f9f8

Browse files
committed
guides: add onboarding snippets (#3844) (generated) [skip ci]
Co-authored-by: Levi Whalen <[email protected]> Co-authored-by: Pierre Millot <[email protected]> Co-authored-by: Thomas Raffray <[email protected]>
1 parent 151bd36 commit 6a2f9f8

35 files changed

+1779
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"csharpier": {
6+
"version": "0.29.2",
7+
"commands": [
8+
"dotnet-csharpier"
9+
]
10+
}
11+
}
12+
}

guides/csharp/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin
2+
obj

guides/csharp/Algolia.sln

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "src", "src\src.csproj", "{C3F414F4-84DD-4E56-A1E7-34086763F07D}"
4+
EndProject
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Algolia.Search", "..\..\clients\algoliasearch-client-csharp\algoliasearch\Algolia.Search.csproj", "{2485A285-E565-4407-95E1-0F216142AAA8}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{C3F414F4-84DD-4E56-A1E7-34086763F07D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{C3F414F4-84DD-4E56-A1E7-34086763F07D}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{C3F414F4-84DD-4E56-A1E7-34086763F07D}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{C3F414F4-84DD-4E56-A1E7-34086763F07D}.Release|Any CPU.Build.0 = Release|Any CPU
17+
{2485A285-E565-4407-95E1-0F216142AAA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18+
{2485A285-E565-4407-95E1-0F216142AAA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{2485A285-E565-4407-95E1-0F216142AAA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{2485A285-E565-4407-95E1-0F216142AAA8}.Release|Any CPU.Build.0 = Release|Any CPU
21+
{33F416B9-F209-47BF-9504-D596428FA5E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{33F416B9-F209-47BF-9504-D596428FA5E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{33F416B9-F209-47BF-9504-D596428FA5E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{33F416B9-F209-47BF-9504-D596428FA5E1}.Release|Any CPU.Build.0 = Release|Any CPU
25+
EndGlobalSection
26+
EndGlobal
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Text.Json;
3+
using System.Net.Http;
4+
using System.Collections.Generic;
5+
6+
using Algolia.Search.Clients;
7+
using Algolia.Search.Models.Search;
8+
9+
class Program
10+
{
11+
public static async Task Main(string[] args)
12+
{
13+
// read json file from url
14+
var url = "https://dashboard.algolia.com/sample_datasets/movie.json";
15+
var httpClient = new HttpClient();
16+
var response = await httpClient.GetAsync(url);
17+
var content = await response.Content.ReadAsStringAsync();
18+
19+
// parse json
20+
var movies = JsonSerializer.Deserialize<List<dynamic>>(content);
21+
22+
// initiate client and index
23+
var client = new SearchClient(new SearchConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY"));
24+
25+
// push data to algolia
26+
try
27+
{
28+
var result = await client.SaveObjectsAsync("<YOUR_INDEX_NAME>"
29+
, movies
30+
);
31+
}
32+
catch (Exception e)
33+
{
34+
Console.WriteLine(e.Message);
35+
}
36+
}
37+
}

guides/csharp/src/src.csproj

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<RootNamespace>Algolia</RootNamespace>
9+
<LangVersion>12</LangVersion>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\..\..\clients\algoliasearch-client-csharp\algoliasearch\Algolia.Search.csproj" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
18+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<None Update="appsettings.json">
23+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
24+
</None>
25+
</ItemGroup>
26+
27+
</Project>

guides/go/.golangci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
linters:
2+
disable:
3+
- ineffassign
4+
- staticcheck
5+
6+
issues:
7+
exclude-generated: disable
8+
9+
run:
10+
concurrency: 2
11+
timeout: 10m

guides/go/go.mod

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module snippets
2+
3+
go 1.21
4+
5+
replace github.com/algolia/algoliasearch-client-go/v4 v4.0.0 => ../../clients/algoliasearch-client-go
6+
7+
require github.com/algolia/algoliasearch-client-go/v4 v4.0.0
8+
9+
require (
10+
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
11+
github.com/go-playground/locales v0.14.1 // indirect
12+
github.com/go-playground/universal-translator v0.18.1 // indirect
13+
github.com/go-playground/validator/v10 v10.22.1 // indirect
14+
github.com/leodido/go-urn v1.4.0 // indirect
15+
golang.org/x/crypto v0.22.0 // indirect
16+
golang.org/x/net v0.24.0 // indirect
17+
golang.org/x/sys v0.19.0 // indirect
18+
golang.org/x/text v0.14.0 // indirect
19+
)

guides/go/go.sum

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
4+
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
5+
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
6+
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
7+
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
8+
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
9+
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
10+
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
11+
github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA=
12+
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
13+
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
14+
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
15+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
16+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
17+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
18+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
19+
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
20+
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
21+
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
22+
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
23+
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
24+
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
25+
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
26+
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
27+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
28+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

guides/go/src/saveObjectsMovies.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"net/http"
7+
8+
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
9+
)
10+
11+
func main() {
12+
// read json file
13+
url := "https://dashboard.algolia.com/sample_datasets/movie.json"
14+
response, err := http.Get(url)
15+
16+
if err != nil {
17+
fmt.Println("Could not open url")
18+
return
19+
}
20+
21+
defer response.Body.Close()
22+
23+
// parse json file to Movie struct
24+
var movies []map[string]interface{}
25+
err = json.NewDecoder(response.Body).Decode(&movies)
26+
27+
if err != nil {
28+
fmt.Println("Could not decode body")
29+
return
30+
}
31+
32+
// initiate client
33+
client, err := search.NewClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
34+
if err != nil {
35+
// The client can fail to initialize if you pass an invalid parameter.
36+
panic(err)
37+
}
38+
39+
// push data to algolia
40+
result, err := client.SaveObjects(
41+
"<YOUR_INDEX_NAME>", movies,
42+
)
43+
if err != nil {
44+
fmt.Println(err)
45+
return
46+
}
47+
48+
fmt.Printf("Done! Uploaded records in %d batches.", len(result))
49+
}

guides/java/build.gradle

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
plugins {
2+
id 'java-library'
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
testImplementation 'com.algolia:algoliasearch:4.5.0'
11+
}
12+
13+
java {
14+
toolchain {
15+
languageVersion = JavaLanguageVersion.of(17)
16+
vendor = JvmVendorSpec.ADOPTIUM
17+
}
18+
}
19+
20+
tasks.withType(JavaCompile) {
21+
options.encoding = 'UTF-8'
22+
}

guides/java/settings.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
rootProject.name = 'java-tests'
2+
3+
includeBuild('../../clients/algoliasearch-client-java') {
4+
dependencySubstitution {
5+
substitute module('com.algolia:algoliasearch') using project(':algoliasearch')
6+
}
7+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import com.algolia.api.SearchClient;
2+
import com.algolia.model.search.*;
3+
import com.fasterxml.jackson.core.type.TypeReference;
4+
import com.fasterxml.jackson.databind.JsonNode;
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import java.io.InputStream;
7+
import java.net.URI;
8+
import java.net.URL;
9+
import java.util.List;
10+
11+
public class saveObjectsMovies {
12+
13+
public static void main(String[] args) throws Exception {
14+
// Fetch sample dataset
15+
URL url = new URI("https://dashboard.algolia.com/sample_datasets/movie.json").toURL();
16+
InputStream stream = url.openStream();
17+
ObjectMapper mapper = new ObjectMapper();
18+
List<JsonNode> movies = mapper.readValue(stream, new TypeReference<List<JsonNode>>() {});
19+
stream.close();
20+
21+
// Connect and authenticate with your Algolia app
22+
SearchClient client = new SearchClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");
23+
24+
// Save records in Algolia index
25+
client.saveObjects("<YOUR_INDEX_NAME>", movies);
26+
client.close();
27+
}
28+
}

guides/kotlin/build.gradle.kts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import com.diffplug.gradle.spotless.SpotlessExtension
2+
3+
plugins {
4+
kotlin("jvm") version "2.0.20"
5+
kotlin("plugin.serialization") version "2.0.20"
6+
alias(libs.plugins.spotless)
7+
}
8+
9+
repositories {
10+
mavenCentral()
11+
}
12+
13+
dependencies {
14+
implementation("com.algolia:algoliasearch-client-kotlin")
15+
implementation("io.ktor:ktor-client-okhttp:2.3.12")
16+
implementation("ch.qos.logback:logback-classic:1.5.8")
17+
implementation("io.github.cdimascio:dotenv-kotlin:6.4.2")
18+
}
19+
20+
configure<SpotlessExtension> {
21+
kotlin {
22+
target("**/*.kt")
23+
trimTrailingWhitespace()
24+
ktlint()
25+
.editorConfigOverride(
26+
mapOf(
27+
"ktlint_standard_no-wildcard-imports" to "disabled",
28+
"ktlint_standard_trailing-comma-on-declaration-site" to "disabled",
29+
"ktlint_standard_filename" to "disabled",
30+
"ktlint_standard_import-ordering" to "disabled",
31+
),
32+
)
33+
}
34+
}

guides/kotlin/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kotlin.code.style=official
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[versions]
2+
kotlin = "2.0.20"
3+
coroutines = "1.7.3"
4+
serialization = "1.5.0"
5+
ktor = "2.3.12"
6+
7+
[libraries]
8+
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version = "1.7.3" }
9+
ktor-client-okhttp = { group = "io.ktor", name = "ktor-client-okhttp", version.ref = "ktor" }
10+
ktor-client-darwin = { group = "io.ktor", name = "ktor-client-darwin", version.ref = "ktor" }
11+
12+
[plugins]
13+
kotlin-multiplaform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
14+
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
15+
spotless = { id = "com.diffplug.spotless", version = "6.25.0" }

guides/kotlin/settings.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
rootProject.name = "kotlin-snippets"
2+
3+
includeBuild("../../clients/algoliasearch-client-kotlin") {
4+
dependencySubstitution {
5+
substitute(module("com.algolia:algoliasearch-client-kotlin")).using(project(":client"))
6+
}
7+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.example
2+
import com.algolia.client.api.SearchClient
3+
import com.algolia.client.extensions.*
4+
5+
import kotlinx.serialization.builtins.ListSerializer
6+
import kotlinx.serialization.json.Json
7+
import kotlinx.serialization.json.JsonObject
8+
import java.net.URI
9+
10+
suspend fun main() {
11+
val url = URI.create("https://dashboard.algolia.com/sample_datasets/movie.json")
12+
val json = url.toURL().readText()
13+
val movies: List<JsonObject> = Json.decodeFromString(ListSerializer(JsonObject.serializer()), json)
14+
15+
val client = SearchClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")
16+
17+
try {
18+
client.saveObjects(
19+
indexName = "<YOUR_INDEX_NAME>",
20+
objects = movies,
21+
)
22+
} catch (e: Exception) {
23+
println(e.message)
24+
}
25+
}

guides/php/src/saveObjectsMovies.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
require(__DIR__."/vendor/autoload.php");
3+
use Algolia\AlgoliaSearch\Api\SearchClient;
4+
5+
// Fetch sample dataset
6+
$url = "https://dashboard.algolia.com/sample_datasets/movie.json";
7+
$response = file_get_contents($url);
8+
$movies = json_decode($response, true);
9+
10+
// Connect and authenticate with your Algolia app
11+
$client = SearchClient::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');
12+
13+
// Save records in Algolia index
14+
$client->saveObjects(
15+
"<YOUR_INDEX_NAME>",
16+
17+
movies
18+
)
19+
20+
print('Done!');

0 commit comments

Comments
 (0)