Skip to content

Commit

Permalink
fix rebase (generated)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Millot <pierre.millot@algolia.com>
  • Loading branch information
algolia-bot and millotp committed Oct 7, 2024
1 parent be3dbf1 commit 91ed2a5
Show file tree
Hide file tree
Showing 35 changed files with 1,678 additions and 0 deletions.
12 changes: 12 additions & 0 deletions guides/csharp/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"csharpier": {
"version": "0.29.2",
"commands": [
"dotnet-csharpier"
]
}
}
}
2 changes: 2 additions & 0 deletions guides/csharp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin
obj
26 changes: 26 additions & 0 deletions guides/csharp/Algolia.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "src", "src\src.csproj", "{C3F414F4-84DD-4E56-A1E7-34086763F07D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Algolia.Search", "..\..\clients\algoliasearch-client-csharp\algoliasearch\Algolia.Search.csproj", "{2485A285-E565-4407-95E1-0F216142AAA8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C3F414F4-84DD-4E56-A1E7-34086763F07D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C3F414F4-84DD-4E56-A1E7-34086763F07D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3F414F4-84DD-4E56-A1E7-34086763F07D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3F414F4-84DD-4E56-A1E7-34086763F07D}.Release|Any CPU.Build.0 = Release|Any CPU
{2485A285-E565-4407-95E1-0F216142AAA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2485A285-E565-4407-95E1-0F216142AAA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2485A285-E565-4407-95E1-0F216142AAA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2485A285-E565-4407-95E1-0F216142AAA8}.Release|Any CPU.Build.0 = Release|Any CPU
{33F416B9-F209-47BF-9504-D596428FA5E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{33F416B9-F209-47BF-9504-D596428FA5E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33F416B9-F209-47BF-9504-D596428FA5E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33F416B9-F209-47BF-9504-D596428FA5E1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
37 changes: 37 additions & 0 deletions guides/csharp/src/saveObjectsMovies.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Text.Json;
using System.Net.Http;
using System.Collections.Generic;

using Algolia.Search.Clients;
using Algolia.Search.Models.Search;

class Program
{
public static async Task Main(string[] args)
{
// read json file from url
var url = "https://dashboard.algolia.com/sample_datasets/movie.json";
var httpClient = new HttpClient();
var response = await httpClient.GetAsync(url);
var content = await response.Content.ReadAsStringAsync();

// parse json
var movies = JsonSerializer.Deserialize<List<dynamic>>(content);

// initiate client and index
var client = new SearchClient(new SearchConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY"));

// push data to algolia
try
{
var result = await client.SaveObjectsAsync("<YOUR_INDEX_NAME>"
, movies
);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
27 changes: 27 additions & 0 deletions guides/csharp/src/src.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Algolia</RootNamespace>
<LangVersion>12</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\clients\algoliasearch-client-csharp\algoliasearch\Algolia.Search.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions guides/go/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
linters:
disable:
- ineffassign
- staticcheck

issues:
exclude-generated: disable

run:
concurrency: 2
timeout: 10m
19 changes: 19 additions & 0 deletions guides/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module snippets

go 1.21

replace github.com/algolia/algoliasearch-client-go/v4 v4.0.0 => ../../clients/algoliasearch-client-go

require github.com/algolia/algoliasearch-client-go/v4 v4.0.0

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

import (
"encoding/json"
"fmt"
"net/http"

"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)

func main() {
// read json file
url := "https://dashboard.algolia.com/sample_datasets/movie.json"
response, err := http.Get(url)

if err != nil {
fmt.Println("Could not open url")
return
}

defer response.Body.Close()

// parse json file to Movie struct
var movies []map[string]interface{}
err = json.NewDecoder(response.Body).Decode(&movies)

if err != nil {
fmt.Println("Could not decode body")
return
}

// initiate client
client, err := search.NewClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
if err != nil {
// The client can fail to initialize if you pass an invalid parameter.
panic(err)
}

// push data to algolia
result, err := client.SaveObjects(
"<YOUR_INDEX_NAME>", movies,
)
if err != nil {
fmt.Println(err)
return
}

fmt.Printf("Done! Uploaded records in %d batches.", len(result))
}
22 changes: 22 additions & 0 deletions guides/java/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
id 'java-library'
}

repositories {
mavenCentral()
}

dependencies {
testImplementation 'com.algolia:algoliasearch:4.4.0'
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
vendor = JvmVendorSpec.ADOPTIUM
}
}

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
7 changes: 7 additions & 0 deletions guides/java/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rootProject.name = 'java-tests'

includeBuild('../../clients/algoliasearch-client-java') {
dependencySubstitution {
substitute module('com.algolia:algoliasearch') using project(':algoliasearch')
}
}
28 changes: 28 additions & 0 deletions guides/java/src/test/java/com/algolia/saveObjectsMovies.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import com.algolia.api.SearchClient;
import com.algolia.model.search.*;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.util.List;

public class saveObjectsMovies {

public static void main(String[] args) throws Exception {
// Fetch sample dataset
URL url = new URI("https://dashboard.algolia.com/sample_datasets/movie.json").toURL();
InputStream stream = url.openStream();
ObjectMapper mapper = new ObjectMapper();
List<JsonNode> movies = mapper.readValue(stream, new TypeReference<List<JsonNode>>() {});
stream.close();

// Connect and authenticate with your Algolia app
SearchClient client = new SearchClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");

// Save records in Algolia index
client.saveObjects("<YOUR_INDEX_NAME>", movies);
client.close();
}
}
34 changes: 34 additions & 0 deletions guides/kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import com.diffplug.gradle.spotless.SpotlessExtension

plugins {
kotlin("jvm") version "2.0.20"
kotlin("plugin.serialization") version "2.0.20"
alias(libs.plugins.spotless)
}

repositories {
mavenCentral()
}

dependencies {
implementation("com.algolia:algoliasearch-client-kotlin")
implementation("io.ktor:ktor-client-okhttp:2.3.12")
implementation("ch.qos.logback:logback-classic:1.5.8")
implementation("io.github.cdimascio:dotenv-kotlin:6.4.2")
}

configure<SpotlessExtension> {
kotlin {
target("**/*.kt")
trimTrailingWhitespace()
ktlint()
.editorConfigOverride(
mapOf(
"ktlint_standard_no-wildcard-imports" to "disabled",
"ktlint_standard_trailing-comma-on-declaration-site" to "disabled",
"ktlint_standard_filename" to "disabled",
"ktlint_standard_import-ordering" to "disabled",
),
)
}
}
1 change: 1 addition & 0 deletions guides/kotlin/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kotlin.code.style=official
15 changes: 15 additions & 0 deletions guides/kotlin/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[versions]
kotlin = "2.0.20"
coroutines = "1.7.3"
serialization = "1.5.0"
ktor = "2.3.12"

[libraries]
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version = "1.7.3" }
ktor-client-okhttp = { group = "io.ktor", name = "ktor-client-okhttp", version.ref = "ktor" }
ktor-client-darwin = { group = "io.ktor", name = "ktor-client-darwin", version.ref = "ktor" }

[plugins]
kotlin-multiplaform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
spotless = { id = "com.diffplug.spotless", version = "6.25.0" }
7 changes: 7 additions & 0 deletions guides/kotlin/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rootProject.name = "kotlin-snippets"

includeBuild("../../clients/algoliasearch-client-kotlin") {
dependencySubstitution {
substitute(module("com.algolia:algoliasearch-client-kotlin")).using(project(":client"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.example
import com.algolia.client.api.SearchClient
import com.algolia.client.extensions.*

import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import java.net.URI

suspend fun main() {
val url = URI.create("https://dashboard.algolia.com/sample_datasets/movie.json")
val json = url.toURL().readText()
val movies: List<JsonObject> = Json.decodeFromString(ListSerializer(JsonObject.serializer()), json)

val client = SearchClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")

try {
client.saveObjects(
indexName = "<YOUR_INDEX_NAME>",
objects = movies,
)
} catch (e: Exception) {
println(e.message)
}
}
20 changes: 20 additions & 0 deletions guides/php/src/saveObjectsMovies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
require(__DIR__."/vendor/autoload.php");
use Algolia\AlgoliaSearch\Api\SearchClient;

// Fetch sample dataset
$url = "https://dashboard.algolia.com/sample_datasets/movie.json";
$response = file_get_contents($url);
$movies = json_decode($response, true);

// Connect and authenticate with your Algolia app
$client = SearchClient::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');

// Save records in Algolia index
$client->saveObjects(
"<YOUR_INDEX_NAME>",

movies
)

print('Done!');
Loading

0 comments on commit 91ed2a5

Please sign in to comment.