├── .gitignore ├── dotnet ├── .gitignore ├── README.md └── src │ ├── AlgoliaConsole.sln │ └── AlgoliaConsole │ ├── Actor.cs │ ├── AlgoliaConsole.csproj │ ├── Datas │ └── Actors.json │ └── Program.cs ├── go ├── .gitignore ├── README.md └── main.go ├── java-v1 ├── .gitignore ├── pom.xml └── src │ └── main │ └── java │ └── Main.java ├── java ├── .gitignore ├── README.md ├── pom.xml └── src │ └── main │ └── java │ ├── AsyncHttpClientRequester.java │ ├── CustomHttpClientExample.java │ ├── DefaultClientExample.java │ ├── Employee.java │ └── Main.java ├── javascript ├── .gitignore ├── README.md ├── index.js ├── package.json └── yarn.lock ├── kotlin ├── .gitignore ├── README.md ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ └── main │ └── kotlin │ └── App.kt ├── laravel-scout-extended ├── .editorconfig ├── .env.example ├── .gitattributes ├── .gitignore ├── .styleci.yml ├── README.md ├── app │ ├── Article.php │ ├── Console │ │ └── Kernel.php │ ├── Exceptions │ │ └── Handler.php │ ├── Http │ │ ├── Controllers │ │ │ └── Controller.php │ │ ├── Kernel.php │ │ └── Middleware │ │ │ ├── Authenticate.php │ │ │ ├── CheckForMaintenanceMode.php │ │ │ ├── EncryptCookies.php │ │ │ ├── RedirectIfAuthenticated.php │ │ │ ├── TrimStrings.php │ │ │ ├── TrustHosts.php │ │ │ ├── TrustProxies.php │ │ │ └── VerifyCsrfToken.php │ ├── Providers │ │ ├── AppServiceProvider.php │ │ ├── AuthServiceProvider.php │ │ ├── BroadcastServiceProvider.php │ │ ├── EventServiceProvider.php │ │ └── RouteServiceProvider.php │ └── User.php ├── artisan ├── bootstrap │ ├── app.php │ └── cache │ │ └── .gitignore ├── composer.json ├── composer.lock ├── config │ ├── app.php │ ├── auth.php │ ├── broadcasting.php │ ├── cache.php │ ├── cors.php │ ├── database.php │ ├── filesystems.php │ ├── hashing.php │ ├── logging.php │ ├── mail.php │ ├── queue.php │ ├── scout.php │ ├── services.php │ ├── session.php │ └── view.php ├── database │ ├── .gitignore │ ├── factories │ │ ├── ArticleFactory.php │ │ └── UserFactory.php │ ├── migrations │ │ ├── 2014_10_12_000000_create_users_table.php │ │ ├── 2019_03_18_102855_create_articles_table.php │ │ └── 2019_08_19_000000_create_failed_jobs_table.php │ └── seeds │ │ ├── ArticleTableSeeder.php │ │ └── DatabaseSeeder.php ├── package.json ├── phpunit.xml ├── public │ ├── .htaccess │ ├── favicon.ico │ ├── index.php │ ├── robots.txt │ └── web.config ├── resources │ ├── js │ │ ├── app.js │ │ └── bootstrap.js │ ├── lang │ │ └── en │ │ │ ├── auth.php │ │ │ ├── pagination.php │ │ │ ├── passwords.php │ │ │ └── validation.php │ ├── sass │ │ └── app.scss │ └── views │ │ └── welcome.blade.php ├── routes │ ├── api.php │ ├── channels.php │ ├── console.php │ └── web.php ├── server.php ├── storage │ ├── app │ │ ├── .gitignore │ │ └── public │ │ │ └── .gitignore │ ├── framework │ │ ├── .gitignore │ │ ├── cache │ │ │ ├── .gitignore │ │ │ └── data │ │ │ │ └── .gitignore │ │ ├── sessions │ │ │ └── .gitignore │ │ ├── testing │ │ │ └── .gitignore │ │ └── views │ │ │ └── .gitignore │ └── logs │ │ └── .gitignore ├── tests │ ├── CreatesApplication.php │ ├── Feature │ │ └── ExampleTest.php │ ├── TestCase.php │ └── Unit │ │ └── ExampleTest.php └── webpack.mix.js ├── php ├── .gitignore ├── LICENSE.md ├── README.md ├── bin │ └── index.php └── composer.json ├── python ├── README.md └── examples │ ├── async.py │ └── sync.py ├── rails ├── .gitignore ├── Gemfile ├── README.md ├── Rakefile ├── app │ ├── assets │ │ ├── config │ │ │ └── manifest.js │ │ ├── images │ │ │ └── .keep │ │ ├── javascripts │ │ │ ├── application.js │ │ │ ├── cable.js │ │ │ ├── channels │ │ │ │ └── .keep │ │ │ └── search.coffee │ │ └── stylesheets │ │ │ ├── application.css │ │ │ └── search.scss │ ├── channels │ │ └── application_cable │ │ │ ├── channel.rb │ │ │ └── connection.rb │ ├── controllers │ │ ├── application_controller.rb │ │ ├── concerns │ │ │ └── .keep │ │ └── search_controller.rb │ ├── helpers │ │ ├── application_helper.rb │ │ └── search_helper.rb │ ├── jobs │ │ └── application_job.rb │ ├── mailers │ │ └── application_mailer.rb │ ├── models │ │ ├── application_record.rb │ │ ├── concerns │ │ │ └── .keep │ │ └── contact.rb │ └── views │ │ ├── layouts │ │ ├── application.html.erb │ │ ├── mailer.html.erb │ │ └── mailer.text.erb │ │ └── search │ │ └── index.html.erb ├── bin │ ├── bundle │ ├── rails │ ├── rake │ ├── setup │ ├── spring │ └── update ├── config.ru ├── config │ ├── application.rb │ ├── boot.rb │ ├── cable.yml │ ├── database.yml │ ├── environment.rb │ ├── environments │ │ ├── development.rb │ │ ├── production.rb │ │ └── test.rb │ ├── initializers │ │ ├── algoliasearch.rb │ │ ├── application_controller_renderer.rb │ │ ├── assets.rb │ │ ├── backtrace_silencers.rb │ │ ├── cookies_serializer.rb │ │ ├── filter_parameter_logging.rb │ │ ├── inflections.rb │ │ ├── mime_types.rb │ │ ├── new_framework_defaults.rb │ │ ├── session_store.rb │ │ └── wrap_parameters.rb │ ├── locales │ │ └── en.yml │ ├── puma.rb │ ├── routes.rb │ ├── secrets.yml │ └── spring.rb ├── db │ ├── contacts.json │ ├── migrate │ │ └── 20190906152917_create_contacts.rb │ ├── schema.rb │ └── seeds.rb ├── lib │ ├── assets │ │ └── .keep │ └── tasks │ │ └── .keep ├── log │ └── .keep ├── public │ ├── 404.html │ ├── 422.html │ ├── 500.html │ ├── apple-touch-icon-precomposed.png │ ├── apple-touch-icon.png │ ├── favicon.ico │ └── robots.txt ├── test │ ├── controllers │ │ ├── .keep │ │ └── search_controller_test.rb │ ├── fixtures │ │ ├── .keep │ │ ├── contacts.yml │ │ └── files │ │ │ └── .keep │ ├── helpers │ │ └── .keep │ ├── integration │ │ └── .keep │ ├── mailers │ │ └── .keep │ ├── models │ │ ├── .keep │ │ └── contact_test.rb │ └── test_helper.rb ├── tmp │ └── .keep └── vendor │ └── assets │ ├── javascripts │ └── .keep │ └── stylesheets │ └── .keep ├── ruby-v1 ├── .gitignore ├── Gemfile ├── README.md ├── debug.log └── index.rb ├── ruby ├── .gitignore ├── Gemfile ├── README.md └── index.rb ├── scala ├── .gitignore ├── .scalafmt.conf ├── README.md ├── build.sbt ├── project │ ├── build.properties │ └── plugins.sbt └── src │ └── main │ └── scala │ ├── Contact.scala │ └── Main.scala ├── swift ├── .gitignore ├── Package.resolved ├── Package.swift ├── README.md ├── Sources │ └── Playground │ │ └── main.swift ├── Tests │ ├── LinuxMain.swift │ └── PlaygroundTests │ │ ├── PlaygroundTests.swift │ │ └── XCTestManifests.swift └── Vapor │ ├── README.md │ └── SearchClient+NIO.swift └── symfony ├── .env.test ├── .gitignore ├── README.md ├── bin ├── console └── phpunit ├── composer.json ├── composer.lock ├── config ├── bootstrap.php ├── bundles.php ├── packages │ ├── algolia_search.yaml │ ├── cache.yaml │ ├── dev │ │ └── routing.yaml │ ├── doctrine.yaml │ ├── doctrine_migrations.yaml │ ├── framework.yaml │ ├── prod │ │ ├── doctrine.yaml │ │ └── routing.yaml │ ├── routing.yaml │ └── test │ │ ├── doctrine.yaml │ │ ├── framework.yaml │ │ └── routing.yaml ├── preload.php ├── routes.yaml ├── routes │ ├── annotations.yaml │ ├── dev │ │ └── framework.yaml │ └── framework.yaml └── services.yaml ├── docker-compose.override.yml ├── docker-compose.yml ├── migrations └── .gitignore ├── phpunit.xml.dist ├── public └── index.php ├── src ├── Controller │ ├── .gitignore │ └── ArticleController.php ├── DataFixtures │ └── AppFixtures.php ├── Entity │ ├── .gitignore │ ├── Article.php │ └── News.php ├── Kernel.php ├── Migrations │ └── .gitignore └── Repository │ ├── .gitignore │ └── ArticleRepository.php ├── symfony.lock └── tests └── bootstrap.php /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .vscode/ 3 | .mypy_cache 4 | -------------------------------------------------------------------------------- /dotnet/.gitignore: -------------------------------------------------------------------------------- 1 | [Bb]in/ 2 | [Oo]bj/ 3 | [Ww]orking*/ 4 | Build/Temp/ 5 | Doc/doc.shfbproj_* 6 | TestResults/ 7 | AppPackages/ 8 | BenchmarkDotNet.Artifacts/ 9 | *.suo 10 | *.user 11 | *.userprefs 12 | .vs/ 13 | .vscode/ 14 | *.lock.json 15 | *.nuget.props 16 | *.nuget.targets 17 | *.orig 18 | .DS_Store -------------------------------------------------------------------------------- /dotnet/README.md: -------------------------------------------------------------------------------- 1 | # Algolia's .NET console 2 | 3 | ## .NET environment setup 4 | 5 | You can skip this part if you already have the .NET 7.x installed. 6 | 7 | ### .NET 7.x 8 | 9 | Download and install .NET from [.NET Downloads](https://dotnet.microsoft.com/en-us/download). 10 | 11 | If you have problems with the installation on MacOS, consult the [Known issues](https://github.com/dotnet/core/blob/main/release-notes/7.0/known-issues.md) topic for the version you have installed. 12 | 13 | To check if dotnet is correctly installed : 14 | 15 | ```shell 16 | dotnet --version 17 | ``` 18 | 19 | You should have something like this depending on the version you have installed : 20 | 21 | ```shell 22 | 7.XX.XX 23 | ``` 24 | 25 | If you have the following message `dotnet command not found`. Please run the following command : 26 | 27 | ```shell 28 | export PATH=/usr/local/share/dotnet:$PATH 29 | ``` 30 | 31 | ### Visual studio Code 32 | 33 | If you don't have it, you should download [Visual Studio Code](https://code.visualstudio.com/) which is in my opinion, the best .NET IDE for MacOS at the moment. 34 | 35 | Once you have downloaded Visual Studio Code, I recommend you to install some usefull VSCode's plugins. 36 | 37 | * [C# for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp) 38 | * [.Net Core Test Explorer](https://marketplace.visualstudio.com/items?itemName=formulahendry.dotnet-test-explorer) 39 | 40 | ## How to use the project 41 | 42 | This project aims to show how to use the .NET Algolia API Client from C# code. 43 | 44 | Open your terminal in the `src/AlgoliaConsole` folder. 45 | 46 | First, build the project 47 | 48 | ```shell 49 | dotnet build 50 | ``` 51 | 52 | Then, run the project 53 | 54 | ```shell 55 | ALGOLIA_APPLICATION_ID= ALGOLIA_ADMIN_API_KEY= dotnet run --project AlgoliaConsole 56 | ``` 57 | -------------------------------------------------------------------------------- /dotnet/src/AlgoliaConsole.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26124.0 5 | MinimumVisualStudioVersion = 15.0.26124.0 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlgoliaConsole", "AlgoliaConsole\AlgoliaConsole.csproj", "{7E85B2A9-26B6-40FF-8BEE-02D7592B6E3C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|x64 = Debug|x64 12 | Debug|x86 = Debug|x86 13 | Release|Any CPU = Release|Any CPU 14 | Release|x64 = Release|x64 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {7E85B2A9-26B6-40FF-8BEE-02D7592B6E3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {7E85B2A9-26B6-40FF-8BEE-02D7592B6E3C}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {7E85B2A9-26B6-40FF-8BEE-02D7592B6E3C}.Debug|x64.ActiveCfg = Debug|Any CPU 24 | {7E85B2A9-26B6-40FF-8BEE-02D7592B6E3C}.Debug|x64.Build.0 = Debug|Any CPU 25 | {7E85B2A9-26B6-40FF-8BEE-02D7592B6E3C}.Debug|x86.ActiveCfg = Debug|Any CPU 26 | {7E85B2A9-26B6-40FF-8BEE-02D7592B6E3C}.Debug|x86.Build.0 = Debug|Any CPU 27 | {7E85B2A9-26B6-40FF-8BEE-02D7592B6E3C}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {7E85B2A9-26B6-40FF-8BEE-02D7592B6E3C}.Release|Any CPU.Build.0 = Release|Any CPU 29 | {7E85B2A9-26B6-40FF-8BEE-02D7592B6E3C}.Release|x64.ActiveCfg = Release|Any CPU 30 | {7E85B2A9-26B6-40FF-8BEE-02D7592B6E3C}.Release|x64.Build.0 = Release|Any CPU 31 | {7E85B2A9-26B6-40FF-8BEE-02D7592B6E3C}.Release|x86.ActiveCfg = Release|Any CPU 32 | {7E85B2A9-26B6-40FF-8BEE-02D7592B6E3C}.Release|x86.Build.0 = Release|Any CPU 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /dotnet/src/AlgoliaConsole/Actor.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace AlgoliaConsole 4 | { 5 | public class Actor 6 | { 7 | public string Name { get; set; } 8 | 9 | public string ObjectID { get; set; } 10 | 11 | public int Rating { get; set; } 12 | 13 | [JsonProperty(PropertyName = "image_path")] 14 | public string ImagePath { get; set; } 15 | 16 | [JsonProperty(PropertyName = "alternative_name")] 17 | public string AlternativePath { get; set; } 18 | 19 | public override string ToString() 20 | { 21 | return $"Name: {Name}\r\nObjectId: {ObjectID}\r\nRating: {Rating}"; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /dotnet/src/AlgoliaConsole/AlgoliaConsole.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net7.0 6 | latest 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /dotnet/src/AlgoliaConsole/Program.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Algolia 3 | * http://www.algolia.com/ 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | 24 | using Algolia.Search.Clients; 25 | using Algolia.Search.Models.Search; 26 | using Newtonsoft.Json; 27 | using Newtonsoft.Json.Linq; 28 | using System; 29 | using System.IO; 30 | using System.Linq; 31 | using System.Threading.Tasks; 32 | 33 | namespace AlgoliaConsole 34 | { 35 | class Program 36 | { 37 | private static string _apiKey; 38 | private static string _appKey; 39 | 40 | static async Task Main(string[] args) 41 | { 42 | InitKeys(); 43 | 44 | // Init the client 45 | SearchClient client = new SearchClient(_appKey, _apiKey); 46 | 47 | // Init index 48 | SearchIndex index = client.InitIndex("AlgoliaDotnetConsole"); 49 | 50 | // Push data from Json 51 | using (StreamReader re = File.OpenText("AlgoliaConsole/Datas/Actors.json")) 52 | using (JsonTextReader reader = new JsonTextReader(re)) 53 | { 54 | JArray batch = JArray.Load(reader); 55 | var ret = await index.SaveObjectsAsync(batch); 56 | ret.Wait(); 57 | } 58 | 59 | // Get data 60 | var actor = await index.GetObjectAsync("551486310"); 61 | Console.WriteLine(actor.ToString()); 62 | 63 | // Search 64 | var search = await index.SearchAsync(new Query("monica")); 65 | Console.WriteLine(search.Hits.ElementAt(0).ToString()); 66 | Environment.Exit(0); 67 | } 68 | 69 | static void InitKeys() 70 | { 71 | if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ALGOLIA_APPLICATION_ID"))) 72 | { 73 | Console.WriteLine("Please set the following environment variable : ALGOLIA_APPLICATION_ID"); 74 | Environment.Exit(1); 75 | } 76 | 77 | if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ALGOLIA_ADMIN_API_KEY"))) 78 | { 79 | Console.WriteLine("Please set the following environment variable : ALGOLIA_ADMIN_API_KEY"); 80 | Environment.Exit(1); 81 | } 82 | 83 | _appKey = Environment.GetEnvironmentVariable("ALGOLIA_APPLICATION_ID"); 84 | _apiKey = Environment.GetEnvironmentVariable("ALGOLIA_ADMIN_API_KEY"); 85 | } 86 | 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /go/.gitignore: -------------------------------------------------------------------------------- 1 | go.mod 2 | go.sum 3 | playground 4 | -------------------------------------------------------------------------------- /go/README.md: -------------------------------------------------------------------------------- 1 | ## Go setup 2 | 3 | ``` 4 | # Install go 5 | brew install go 6 | 7 | # Make sure that you are using the latest version of Go (at least 1.14 >=) 8 | go version 9 | ``` 10 | 11 | ## Fetch the client as a dependency 12 | 13 | ``` 14 | # Create a new module for the current project 15 | go mod init playground 16 | 17 | # Fetch the Go client as a dependency 18 | go get github.com/algolia/algoliasearch-client-go/v3@v3.6.0 19 | ``` 20 | 21 | ## Compile and run 22 | 23 | ``` 24 | # Execute the main file by compiling then running the executable 25 | go build 26 | ./playground 27 | 28 | # Or directly compile it and run it at once 29 | go run main.go 30 | ``` 31 | -------------------------------------------------------------------------------- /go/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/algolia/algoliasearch-client-go/v3/algolia/opt" 7 | "github.com/algolia/algoliasearch-client-go/v3/algolia/search" 8 | ) 9 | 10 | func main() { 11 | appID, apiKey, indexName := "", "", "" 12 | 13 | client := search.NewClient(appID, apiKey) 14 | index := client.InitIndex(indexName) 15 | 16 | books := []Book{ 17 | {Author: "J.K. Rowling", Title: "Harry Potter and the Prizoner of Azkaban"}, 18 | {Author: "Stephen King", Title: "It"}, 19 | } 20 | 21 | res, err := index.SaveObjects(books, opt.AutoGenerateObjectIDIfNotExist(true)) 22 | if err != nil { 23 | fmt.Printf("cannot save objects: %v\n", err) 24 | return 25 | } 26 | 27 | if err = res.Wait(); err != nil { 28 | fmt.Printf("error while waiting for save objects to complete: %v\n", err) 29 | return 30 | } 31 | } 32 | 33 | type Book struct { 34 | Author string `json:"author"` 35 | Title string `json:"title"` 36 | } 37 | -------------------------------------------------------------------------------- /java-v1/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | target/ 3 | -------------------------------------------------------------------------------- /java-v1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.algolia 8 | java-v1-playground 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | 14 | org.apache.maven.plugins 15 | maven-compiler-plugin 16 | 17 | 8 18 | 8 19 | 20 | 21 | 22 | com.coveo 23 | fmt-maven-plugin 24 | 2.8 25 | 26 | 27 | 28 | format 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | com.algolia 39 | algoliasearch 40 | 1.12.4 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /java-v1/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | import com.algolia.search.saas.APIClient; 2 | import com.algolia.search.saas.AlgoliaException; 3 | import com.algolia.search.saas.Index; 4 | import org.json.JSONObject; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | 9 | public class Main { 10 | 11 | private static String ALGOLIA_APPLICATION_ID_1 = System.getenv("ALGOLIA_APPLICATION_ID_1"); 12 | private static String ALGOLIA_API_KEY_1 = System.getenv("ALGOLIA_ADMIN_KEY_1"); 13 | 14 | public static void main(String[] args) throws AlgoliaException { 15 | 16 | APIClient client = new APIClient(ALGOLIA_APPLICATION_ID_1, ALGOLIA_API_KEY_1); 17 | Index index = client.initIndex("test"); 18 | 19 | JSONObject settings = new JSONObject() 20 | .put("replicas", Arrays.asList("test_2", "test_3")); 21 | 22 | JSONObject res = index.setSettings(settings); 23 | System.out.println(res); 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /java/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | target/ 3 | .classpath 4 | .project 5 | .settings 6 | 7 | # Mobile Tools for Java (J2ME) 8 | .mtj.tmp/ 9 | 10 | # Package Files # 11 | *.war 12 | *.ear 13 | 14 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 15 | hs_err_pid* 16 | 17 | .idea/ 18 | *.iml 19 | .DS_Store 20 | *.logQueryTest 21 | 22 | .factorypath 23 | -------------------------------------------------------------------------------- /java/README.md: -------------------------------------------------------------------------------- 1 | # ☕ Java Playground 2 | 3 | ## Install OpenJDK 8 or above 4 | 5 | First you need to install **Java** on your machine. Download and install [JDK](https://openjdk.java.net/install/). 6 | 7 | ```sh 8 | java -version 9 | ``` 10 | 11 | Should output something like (if you installed JDK8) : 12 | ``` 13 | java version "1.8.0_181" 14 | ``` 15 | 16 | ## Install an IDE 17 | 18 | You can use multiple IDEs with Java. I would recommend you -in that order- the following: 19 | 20 | - [IntelijIDEA](https://www.jetbrains.com/idea/download/) 21 | - [Eclipse](https://www.eclipse.org/downloads/) 22 | - [Visual Studio Code](https://code.visualstudio.com/) 23 | 24 | ## Check that maven is installed 25 | 26 | ```sh 27 | mvn -version 28 | ``` 29 | 30 | If the command gives no output, go [there](https://maven.apache.org/install.html) to install maven. 31 | 32 | ## Play! 33 | 34 | Run the main method with your favorite IDE. 35 | -------------------------------------------------------------------------------- /java/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.algolia 8 | java-playground 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | org.apache.maven.plugins 14 | maven-compiler-plugin 15 | 16 | 8 17 | 8 18 | 19 | 20 | 21 | com.coveo 22 | fmt-maven-plugin 23 | 2.8 24 | 25 | 26 | 27 | format 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | com.algolia 39 | algoliasearch-core 40 | 3.0.0 41 | 42 | 43 | 44 | com.algolia 45 | algoliasearch-apache 46 | 3.0.0 47 | 48 | 49 | 50 | org.asynchttpclient 51 | async-http-client 52 | 2.8.1 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /java/src/main/java/AsyncHttpClientRequester.java: -------------------------------------------------------------------------------- 1 | import com.algolia.search.ConfigBase; 2 | import com.algolia.search.HttpRequester; 3 | import com.algolia.search.exceptions.AlgoliaRuntimeException; 4 | import com.algolia.search.models.HttpRequest; 5 | import com.algolia.search.models.HttpResponse; 6 | import com.algolia.search.util.HttpStatusCodeUtils; 7 | import java.io.IOException; 8 | import java.util.concurrent.CompletableFuture; 9 | import java.util.concurrent.TimeoutException; 10 | import org.asynchttpclient.*; 11 | 12 | // Example of an HttpClient implementing HttpRequester 13 | public final class AsyncHttpClientRequester implements HttpRequester { 14 | 15 | private final AsyncHttpClient asyncHttpClient; 16 | 17 | public AsyncHttpClientRequester(ConfigBase config) { 18 | 19 | Integer connectTimeOut = config.getConnectTimeOut(); 20 | 21 | DefaultAsyncHttpClientConfig.Builder clientBuilder = 22 | Dsl.config() 23 | .setCompressionEnforced(true) 24 | .setConnectTimeout(connectTimeOut) 25 | .setKeepAlive(true); 26 | 27 | asyncHttpClient = Dsl.asyncHttpClient(clientBuilder); 28 | } 29 | 30 | /** 31 | * Sends the http request asynchronously to the API If the request is time out it creates a new 32 | * response object with timeout set to true Otherwise it throws a run time exception 33 | * 34 | * @param request the request to send 35 | * @throws AlgoliaRuntimeException When an error occurred processing the request on the server 36 | * side 37 | */ 38 | public CompletableFuture performRequestAsync(HttpRequest request) { 39 | BoundRequestBuilder requestToSend = buildRequest(request); 40 | return requestToSend 41 | .execute() 42 | .toCompletableFuture() 43 | .thenApplyAsync(this::buildResponse) 44 | .exceptionally( 45 | t -> { 46 | if (t.getCause() instanceof TimeoutException) { 47 | return new HttpResponse(true); 48 | } 49 | throw new AlgoliaRuntimeException(t); 50 | }); 51 | } 52 | 53 | /** 54 | * Builds an Algolia response from the server response 55 | * 56 | * @param response The server response 57 | */ 58 | private HttpResponse buildResponse(Response response) { 59 | if (HttpStatusCodeUtils.isSuccess(response.getStatusCode())) { 60 | return new HttpResponse(response.getStatusCode(), response.getResponseBodyAsStream()); 61 | } 62 | return new HttpResponse(response.getStatusCode(), response.getResponseBody()); 63 | } 64 | 65 | /** 66 | * Builds an http request from an AlgoliaRequest object 67 | * 68 | * @param algoliaHttpRequest The Algolia request object 69 | */ 70 | private BoundRequestBuilder buildRequest(HttpRequest algoliaHttpRequest) { 71 | Request request = 72 | new RequestBuilder(algoliaHttpRequest.getMethod().toString()) 73 | .setUrl(algoliaHttpRequest.getUri().toString()) 74 | .setMethod(algoliaHttpRequest.getMethod().toString()) 75 | .setSingleHeaders(algoliaHttpRequest.getHeaders()) 76 | .setBody(algoliaHttpRequest.getBody()) 77 | .setRequestTimeout(algoliaHttpRequest.getTimeout()) 78 | .build(); 79 | 80 | return asyncHttpClient.prepareRequest(request); 81 | } 82 | 83 | @Override 84 | public void close() throws IOException { 85 | asyncHttpClient.close(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /java/src/main/java/CustomHttpClientExample.java: -------------------------------------------------------------------------------- 1 | import com.algolia.search.*; 2 | import com.algolia.search.models.indexing.BatchIndexingResponse; 3 | import com.algolia.search.models.indexing.Query; 4 | import com.algolia.search.models.indexing.SearchResult; 5 | import com.algolia.search.models.settings.IndexSettings; 6 | import com.algolia.search.models.settings.SetSettingsResponse; 7 | import java.io.IOException; 8 | import java.util.Collections; 9 | import java.util.List; 10 | import java.util.concurrent.CompletableFuture; 11 | import java.util.concurrent.ExecutionException; 12 | 13 | public class CustomHttpClientExample { 14 | 15 | public static void run() throws ExecutionException, InterruptedException, IOException { 16 | 17 | // Search configuration 18 | SearchConfig config = 19 | new SearchConfig.Builder(Main.ALGOLIA_APPLICATION_ID_1, Main.ALGOLIA_API_KEY_1).build(); 20 | 21 | // Creating a search client with another http client than the default one 22 | try (SearchClient searchClient = 23 | new SearchClient(config, new AsyncHttpClientRequester(config))) { 24 | 25 | // Init an index 26 | SearchIndex index = 27 | searchClient.initIndex("employees_" + System.getProperty("user.name"), Employee.class); 28 | 29 | List employees = Employee.hireEmployees(); 30 | CompletableFuture saveObjectsFuture = 31 | index.saveObjectsAsync(employees, true); 32 | 33 | // Typed index 34 | IndexSettings settings = 35 | new IndexSettings() 36 | .setAttributesForFaceting(Collections.singletonList("searchable(company)")); 37 | 38 | // Typed request/response 39 | CompletableFuture setSettingsFuture = index.setSettingsAsync(settings); 40 | 41 | // Calling get() is blocking on the future to be completed and waitTask is performing Algolia 42 | // wait operations 43 | saveObjectsFuture.get().waitTask(); 44 | setSettingsFuture.get().waitTask(); 45 | 46 | // Performing multiple typed search asynchronously 47 | CompletableFuture> searchAlgoliaFuture = 48 | index.searchAsync(new Query("algolia")); 49 | 50 | SearchResult search = index.search(new Query("algolia")); 51 | 52 | CompletableFuture> searchAppleFuture = 53 | index.searchAsync(new Query("apple")); 54 | 55 | CompletableFuture> searchAmazonFuture = 56 | index.searchAsync(new Query("amazon")); 57 | 58 | CompletableFuture.allOf(searchAlgoliaFuture, searchAppleFuture, searchAmazonFuture).join(); 59 | 60 | System.out.println("Custom client :" + search.getHits().get(0).getName()); 61 | System.out.println("Custom client :" + searchAlgoliaFuture.get().getHits().get(0).getName()); 62 | System.out.println("Custom client :" + searchAppleFuture.get().getHits().get(0).getName()); 63 | System.out.println("Custom client :" + searchAmazonFuture.get().getHits().get(0).getName()); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /java/src/main/java/DefaultClientExample.java: -------------------------------------------------------------------------------- 1 | import com.algolia.search.*; 2 | import com.algolia.search.models.indexing.BatchIndexingResponse; 3 | import com.algolia.search.models.indexing.Query; 4 | import com.algolia.search.models.indexing.SearchResult; 5 | import com.algolia.search.models.settings.IndexSettings; 6 | import com.algolia.search.models.settings.SetSettingsResponse; 7 | import java.io.IOException; 8 | import java.util.Collections; 9 | import java.util.List; 10 | import java.util.concurrent.CompletableFuture; 11 | import java.util.concurrent.ExecutionException; 12 | 13 | public class DefaultClientExample { 14 | 15 | public static void run() throws ExecutionException, InterruptedException, IOException { 16 | // Create a SearchClient (it's a Closeable, so you can leverage the try-with-resources 17 | // construction 18 | // to let the JVM close underlying resources when appropriate) 19 | try (SearchClient searchClient = 20 | DefaultSearchClient.create(Main.ALGOLIA_APPLICATION_ID_1, Main.ALGOLIA_API_KEY_1)) { 21 | 22 | // Init an index 23 | SearchIndex index = 24 | searchClient.initIndex("employees_" + System.getProperty("user.name"), Employee.class); 25 | 26 | List employees = Employee.hireEmployees(); 27 | CompletableFuture saveObjectsFuture = 28 | index.saveObjectsAsync(employees, true); 29 | 30 | // Typed index 31 | IndexSettings settings = 32 | new IndexSettings() 33 | .setAttributesForFaceting(Collections.singletonList("searchable(company)")); 34 | 35 | // Typed request/response 36 | CompletableFuture setSettingsFuture = index.setSettingsAsync(settings); 37 | 38 | // Calling get() is blocking on the future to be completed and waitTask is performing Algolia 39 | // wait operations 40 | saveObjectsFuture.get().waitTask(); 41 | setSettingsFuture.get().waitTask(); 42 | 43 | // Performing multiple typed search asynchronously 44 | CompletableFuture> searchAlgoliaFuture = 45 | index.searchAsync(new Query("algolia")); 46 | 47 | SearchResult search = index.search(new Query("algolia")); 48 | 49 | CompletableFuture> searchAppleFuture = 50 | index.searchAsync(new Query("apple")); 51 | 52 | CompletableFuture> searchAmazonFuture = 53 | index.searchAsync(new Query("amazon")); 54 | 55 | CompletableFuture.allOf(searchAlgoliaFuture, searchAppleFuture, searchAmazonFuture).join(); 56 | 57 | System.out.println("Default client :" + search.getHits().get(0).getName()); 58 | System.out.println("Default client :" + searchAlgoliaFuture.get().getHits().get(0).getName()); 59 | System.out.println("Default client :" + searchAppleFuture.get().getHits().get(0).getName()); 60 | System.out.println("Default client :" + searchAmazonFuture.get().getHits().get(0).getName()); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /java/src/main/java/Employee.java: -------------------------------------------------------------------------------- 1 | import java.io.Serializable; 2 | import java.util.Arrays; 3 | import java.util.List; 4 | 5 | public class Employee implements Serializable { 6 | 7 | public Employee() {} 8 | 9 | public Employee(String company, String name) { 10 | this.company = company; 11 | this.name = name; 12 | } 13 | 14 | public String getCompany() { 15 | return company; 16 | } 17 | 18 | public Employee setCompany(String company) { 19 | this.company = company; 20 | return this; 21 | } 22 | 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | public Employee setName(String name) { 28 | this.name = name; 29 | return this; 30 | } 31 | 32 | public String getQueryID() { 33 | return queryID; 34 | } 35 | 36 | public Employee setQueryID(String queryID) { 37 | this.queryID = queryID; 38 | return this; 39 | } 40 | 41 | private String company; 42 | private String name; 43 | private String queryID; 44 | 45 | public static List hireEmployees() { 46 | return Arrays.asList( 47 | new Employee("Algolia", "Julien Lemoine"), 48 | new Employee("Algolia", "Julien Lemoine"), 49 | new Employee("Amazon", "Jeff Bezos"), 50 | new Employee("Apple", "Steve Jobs"), 51 | new Employee("Apple", "Steve Wozniak"), 52 | new Employee("Arista Networks", "Jayshree Ullal"), 53 | new Employee("Google", "Lary Page"), 54 | new Employee("Google", "Rob Pike"), 55 | new Employee("Google", "Sergueï Brin"), 56 | new Employee("Microsoft", "Bill Gates"), 57 | new Employee("SpaceX", "Elon Musk"), 58 | new Employee("Tesla", "Elon Musk"), 59 | new Employee("Yahoo", "Marissa Mayer")); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /java/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | import java.io.IOException; 2 | import java.util.concurrent.ExecutionException; 3 | 4 | public class Main { 5 | 6 | static String ALGOLIA_APPLICATION_ID_1 = System.getenv("ALGOLIA_APPLICATION_ID_1"); 7 | static String ALGOLIA_API_KEY_1 = System.getenv("ALGOLIA_ADMIN_KEY_1"); 8 | 9 | public static void main(String[] args) 10 | throws ExecutionException, InterruptedException, IOException { 11 | // Run the example with the default http client (apache) 12 | DefaultClientExample.run(); 13 | 14 | // Run the example with a custom implementation of async http client (injected) 15 | CustomHttpClientExample.run(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /javascript/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json 3 | -------------------------------------------------------------------------------- /javascript/README.md: -------------------------------------------------------------------------------- 1 | # About Algolia's API Client Javascript 2 | 3 | Algolia's API Client Javascript was created by, and is maintained by [Algolia](https://github.com/algolia). The Algolia Search API Client for Javascript lets you easily use the Algolia Search REST API from your Javascript code. 4 | 5 | ## Get started locally 6 | 7 | > **Requires:** 8 | - **[Node >11.5](https://nodejs.org)** 9 | - **[NPM >6.9](https://www.npmjs.com)** 10 | 11 | First, use *npm* to playground dependencies: 12 | ```bash 13 | # Go inside the playground javascript folder 14 | cd api-clients-playground/javascript 15 | 16 | # Install dependencies 17 | npm install 18 | ``` 19 | 20 | Finally, edit and run the code on `index.js`: 21 | ``` 22 | node index.js 23 | ``` 24 | -------------------------------------------------------------------------------- /javascript/index.js: -------------------------------------------------------------------------------- 1 | const algoliasearch = require('algoliasearch'); 2 | 3 | var applicationId = ''; 4 | var apiKey = ''; 5 | var indexName = ''; 6 | 7 | const client = algoliasearch(applicationId, apiKey); 8 | const index = client.initIndex(indexName); 9 | 10 | (async function () { 11 | try { 12 | const results = await index.search(); 13 | console.log(results); 14 | } catch (e) { 15 | console.log(e); 16 | throw e; 17 | } 18 | })(); 19 | 20 | -------------------------------------------------------------------------------- /javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "algoliasearch": "^4.1.0" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /kotlin/.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | build 4 | local.properties 5 | reports 6 | .bin 7 | 8 | # IntelliJ IDEA 9 | .idea 10 | *.iml 11 | *.ipl 12 | *.iws 13 | classes/ 14 | idea-classes/ 15 | coverage-error.log 16 | 17 | # Finder 18 | .DS_Store 19 | 20 | # Java 21 | *.hprof 22 | -------------------------------------------------------------------------------- /kotlin/README.md: -------------------------------------------------------------------------------- 1 | # Algolia's Kotlin demo app 2 | 3 | ## Install JDK 8 or above 4 | 5 | First, you need to install **Java** on your machine. 6 | Download and install [JDK](https://openjdk.java.net/install/). 7 | 8 | * Using brew: `brew install openjdk` 9 | * Using [SDKMAN!](https://sdkman.io/install) (recommended but optional). 10 | 11 | ## Setup an IDE 12 | 13 | You can use multiple IDEs with Kotlin, we recommend you -in that order- the following: 14 | 15 | - [Intelij IDEA](https://www.jetbrains.com/idea/download/) Community or Ultimate. 16 | - [Visual Studio Code](https://code.visualstudio.com/) 17 | * Install ["Kotlin" extension](https://marketplace.visualstudio.com/items?itemName=fwcd.kotlin) 18 | 19 | ## How to use the project 20 | 21 | This project aims to show how to use the Kotlin Algolia API client. 22 | 23 | First, build the project 24 | 25 | ```shell 26 | ./gradlew assemble 27 | ``` 28 | 29 | Then, run the project 30 | 31 | ```shell 32 | ./gradlew run 33 | ``` 34 | -------------------------------------------------------------------------------- /kotlin/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.jetbrains.kotlin.jvm' version '1.5.30' 3 | id 'application' 4 | } 5 | 6 | repositories { 7 | mavenCentral() 8 | } 9 | 10 | ext { 11 | kotlin_client_version = "1.10.0" 12 | ktor_version = "1.6.3" 13 | } 14 | 15 | dependencies { 16 | implementation "com.algolia:algoliasearch-client-kotlin:$kotlin_client_version" 17 | implementation "io.ktor:ktor-client-apache:$ktor_version" 18 | } 19 | 20 | application { 21 | // Define the main class for the application. 22 | mainClass = 'AppKt' 23 | } 24 | -------------------------------------------------------------------------------- /kotlin/gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official -------------------------------------------------------------------------------- /kotlin/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/kotlin/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /kotlin/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /kotlin/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /kotlin/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'kotlin' 2 | 3 | -------------------------------------------------------------------------------- /kotlin/src/main/kotlin/App.kt: -------------------------------------------------------------------------------- 1 | import com.algolia.search.client.ClientSearch 2 | import com.algolia.search.model.APIKey 3 | import com.algolia.search.model.ApplicationID 4 | import com.algolia.search.model.IndexName 5 | import kotlinx.coroutines.runBlocking 6 | 7 | fun main() = runBlocking { 8 | val appID = ApplicationID("YourApplicationID") 9 | val apiKey = APIKey("YourAdminAPIKey") 10 | val indexName = IndexName("YourIndexName") 11 | 12 | val client = ClientSearch(appID, apiKey) 13 | val index = client.initIndex(indexName) 14 | 15 | try { 16 | val response = index.search() 17 | println(response) 18 | } catch(exception: Exception) { 19 | println(exception) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /laravel-scout-extended/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | indent_style = space 8 | indent_size = 4 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.{yml,yaml}] 15 | indent_size = 2 16 | -------------------------------------------------------------------------------- /laravel-scout-extended/.env.example: -------------------------------------------------------------------------------- 1 | APP_NAME=Laravel 2 | APP_ENV=local 3 | APP_KEY= 4 | APP_DEBUG=true 5 | APP_URL=http://localhost 6 | 7 | LOG_CHANNEL=stack 8 | 9 | DB_CONNECTION=sqlite 10 | 11 | BROADCAST_DRIVER=log 12 | CACHE_DRIVER=file 13 | QUEUE_CONNECTION=sync 14 | SESSION_DRIVER=file 15 | SESSION_LIFETIME=120 16 | 17 | REDIS_HOST=127.0.0.1 18 | REDIS_PASSWORD=null 19 | REDIS_PORT=6379 20 | 21 | MAIL_MAILER=smtp 22 | MAIL_HOST=smtp.mailtrap.io 23 | MAIL_PORT=2525 24 | MAIL_USERNAME=null 25 | MAIL_PASSWORD=null 26 | MAIL_ENCRYPTION=null 27 | MAIL_FROM_ADDRESS=null 28 | MAIL_FROM_NAME="${APP_NAME}" 29 | 30 | AWS_ACCESS_KEY_ID= 31 | AWS_SECRET_ACCESS_KEY= 32 | AWS_DEFAULT_REGION=us-east-1 33 | AWS_BUCKET= 34 | 35 | PUSHER_APP_ID= 36 | PUSHER_APP_KEY= 37 | PUSHER_APP_SECRET= 38 | PUSHER_APP_CLUSTER=mt1 39 | 40 | MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" 41 | MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" 42 | 43 | ALGOLIA_APP_ID= 44 | ALGOLIA_SECRET= 45 | -------------------------------------------------------------------------------- /laravel-scout-extended/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.css linguist-vendored 3 | *.scss linguist-vendored 4 | *.js linguist-vendored 5 | CHANGELOG.md export-ignore 6 | -------------------------------------------------------------------------------- /laravel-scout-extended/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /public/hot 3 | /public/storage 4 | /storage/*.key 5 | /vendor 6 | .env 7 | .idea 8 | .env.backup 9 | .phpunit.result.cache 10 | Homestead.json 11 | Homestead.yaml 12 | npm-debug.log 13 | yarn-error.log 14 | -------------------------------------------------------------------------------- /laravel-scout-extended/.styleci.yml: -------------------------------------------------------------------------------- 1 | php: 2 | preset: laravel 3 | disabled: 4 | - unused_use 5 | finder: 6 | not-name: 7 | - index.php 8 | - server.php 9 | js: 10 | finder: 11 | not-name: 12 | - webpack.mix.js 13 | css: true 14 | -------------------------------------------------------------------------------- /laravel-scout-extended/README.md: -------------------------------------------------------------------------------- 1 | # About Algolia's Scout-Extended 2 | 3 | Algolia Scout-extended was created by, and is maintained by [Algolia](https://github.com/algolia). 4 | 5 | ## Get started locally 6 | > requires : 7 | * [Composer](https://getcomposer.org/) 8 | * [PHP 7.2+](https://www.php.net/releases/index.php) 9 | 10 | ```bash 11 | # Install from Algolia's Playground from Github 12 | git clone https://github.com/algolia/api-clients-playground 13 | 14 | # Move to Laravel-scout-extended folder. 15 | cd api-clients-playground/laravel-scout-extended 16 | 17 | # Install dependencies 18 | composer install 19 | 20 | # Add your credential in .env 21 | ALGOLIA_APP_ID='YOUR APPLICATION ID' 22 | ALGOLIA_SECRET='YOUR ADMIN API KEY' 23 | 24 | # Your database already exists, so you just need to create data and send it to Algolia 25 | php artisan migrate --seed && php artisan scout:import 26 | 27 | # See the search query 28 | php artisan serve 29 | ``` 30 | 31 | > See the result of the query here : [localhost](http://127.0.0.1:8000) 32 | > Perform search queries with the `query` param : http://127.0.0.1:8000?query=foo 33 | -------------------------------------------------------------------------------- /laravel-scout-extended/app/Article.php: -------------------------------------------------------------------------------- 1 | command('inspire')->hourly(); 28 | } 29 | 30 | /** 31 | * Register the commands for the application. 32 | * 33 | * @return void 34 | */ 35 | protected function commands() 36 | { 37 | $this->load(__DIR__.'/Commands'); 38 | 39 | require base_path('routes/console.php'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /laravel-scout-extended/app/Exceptions/Handler.php: -------------------------------------------------------------------------------- 1 | [ 33 | \App\Http\Middleware\EncryptCookies::class, 34 | \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 35 | \Illuminate\Session\Middleware\StartSession::class, 36 | // \Illuminate\Session\Middleware\AuthenticateSession::class, 37 | \Illuminate\View\Middleware\ShareErrorsFromSession::class, 38 | \App\Http\Middleware\VerifyCsrfToken::class, 39 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 40 | ], 41 | 42 | 'api' => [ 43 | 'throttle:60,1', 44 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 45 | ], 46 | ]; 47 | 48 | /** 49 | * The application's route middleware. 50 | * 51 | * These middleware may be assigned to groups or used individually. 52 | * 53 | * @var array 54 | */ 55 | protected $routeMiddleware = [ 56 | 'auth' => \App\Http\Middleware\Authenticate::class, 57 | 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 58 | 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 59 | 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 60 | 'can' => \Illuminate\Auth\Middleware\Authorize::class, 61 | 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 62 | 'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class, 63 | 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 64 | 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 65 | 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, 66 | ]; 67 | } 68 | -------------------------------------------------------------------------------- /laravel-scout-extended/app/Http/Middleware/Authenticate.php: -------------------------------------------------------------------------------- 1 | expectsJson()) { 18 | return route('login'); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /laravel-scout-extended/app/Http/Middleware/CheckForMaintenanceMode.php: -------------------------------------------------------------------------------- 1 | check()) { 22 | return redirect(RouteServiceProvider::HOME); 23 | } 24 | 25 | return $next($request); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /laravel-scout-extended/app/Http/Middleware/TrimStrings.php: -------------------------------------------------------------------------------- 1 | allSubdomainsOfApplicationUrl(), 18 | ]; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /laravel-scout-extended/app/Http/Middleware/TrustProxies.php: -------------------------------------------------------------------------------- 1 | 'App\Policies\ModelPolicy', 17 | ]; 18 | 19 | /** 20 | * Register any authentication / authorization services. 21 | * 22 | * @return void 23 | */ 24 | public function boot() 25 | { 26 | $this->registerPolicies(); 27 | 28 | // 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /laravel-scout-extended/app/Providers/BroadcastServiceProvider.php: -------------------------------------------------------------------------------- 1 | [ 19 | SendEmailVerificationNotification::class, 20 | ], 21 | ]; 22 | 23 | /** 24 | * Register any events for your application. 25 | * 26 | * @return void 27 | */ 28 | public function boot() 29 | { 30 | parent::boot(); 31 | 32 | // 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /laravel-scout-extended/app/Providers/RouteServiceProvider.php: -------------------------------------------------------------------------------- 1 | mapApiRoutes(); 46 | 47 | $this->mapWebRoutes(); 48 | 49 | // 50 | } 51 | 52 | /** 53 | * Define the "web" routes for the application. 54 | * 55 | * These routes all receive session state, CSRF protection, etc. 56 | * 57 | * @return void 58 | */ 59 | protected function mapWebRoutes() 60 | { 61 | Route::middleware('web') 62 | ->namespace($this->namespace) 63 | ->group(base_path('routes/web.php')); 64 | } 65 | 66 | /** 67 | * Define the "api" routes for the application. 68 | * 69 | * These routes are typically stateless. 70 | * 71 | * @return void 72 | */ 73 | protected function mapApiRoutes() 74 | { 75 | Route::prefix('api') 76 | ->middleware('api') 77 | ->namespace($this->namespace) 78 | ->group(base_path('routes/api.php')); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /laravel-scout-extended/app/User.php: -------------------------------------------------------------------------------- 1 | 'datetime', 38 | ]; 39 | } 40 | -------------------------------------------------------------------------------- /laravel-scout-extended/artisan: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | make(Illuminate\Contracts\Console\Kernel::class); 34 | 35 | $status = $kernel->handle( 36 | $input = new Symfony\Component\Console\Input\ArgvInput, 37 | new Symfony\Component\Console\Output\ConsoleOutput 38 | ); 39 | 40 | /* 41 | |-------------------------------------------------------------------------- 42 | | Shutdown The Application 43 | |-------------------------------------------------------------------------- 44 | | 45 | | Once Artisan has finished running, we will fire off the shutdown events 46 | | so that any final work may be done by the application before we shut 47 | | down the process. This is the last thing to happen to the request. 48 | | 49 | */ 50 | 51 | $kernel->terminate($input, $status); 52 | 53 | exit($status); 54 | -------------------------------------------------------------------------------- /laravel-scout-extended/bootstrap/app.php: -------------------------------------------------------------------------------- 1 | singleton( 30 | Illuminate\Contracts\Http\Kernel::class, 31 | App\Http\Kernel::class 32 | ); 33 | 34 | $app->singleton( 35 | Illuminate\Contracts\Console\Kernel::class, 36 | App\Console\Kernel::class 37 | ); 38 | 39 | $app->singleton( 40 | Illuminate\Contracts\Debug\ExceptionHandler::class, 41 | App\Exceptions\Handler::class 42 | ); 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Return The Application 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This script returns the application instance. The instance is given to 50 | | the calling script so we can separate the building of the instances 51 | | from the actual running of the application and sending responses. 52 | | 53 | */ 54 | 55 | return $app; 56 | -------------------------------------------------------------------------------- /laravel-scout-extended/bootstrap/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /laravel-scout-extended/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel/laravel", 3 | "type": "project", 4 | "description": "The Laravel Framework.", 5 | "keywords": [ 6 | "framework", 7 | "laravel" 8 | ], 9 | "license": "MIT", 10 | "require": { 11 | "php": "^7.2.5", 12 | "algolia/scout-extended": "^1.9", 13 | "fideloper/proxy": "^4.2", 14 | "fruitcake/laravel-cors": "^1.0", 15 | "guzzlehttp/guzzle": "^6.3", 16 | "laravel/framework": "^7.0", 17 | "laravel/tinker": "^2.0" 18 | }, 19 | "require-dev": { 20 | "facade/ignition": "^2.0", 21 | "fzaninotto/faker": "^1.9.1", 22 | "mockery/mockery": "^1.3.1", 23 | "nunomaduro/collision": "^4.1", 24 | "phpunit/phpunit": "^8.5" 25 | }, 26 | "config": { 27 | "optimize-autoloader": true, 28 | "preferred-install": "dist", 29 | "sort-packages": true 30 | }, 31 | "extra": { 32 | "laravel": { 33 | "dont-discover": [] 34 | } 35 | }, 36 | "autoload": { 37 | "psr-4": { 38 | "App\\": "app/" 39 | }, 40 | "classmap": [ 41 | "database/seeds", 42 | "database/factories" 43 | ] 44 | }, 45 | "autoload-dev": { 46 | "psr-4": { 47 | "Tests\\": "tests/" 48 | } 49 | }, 50 | "minimum-stability": "dev", 51 | "prefer-stable": true, 52 | "scripts": { 53 | "post-autoload-dump": [ 54 | "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", 55 | "@php artisan package:discover --ansi" 56 | ], 57 | "post-root-package-install": [ 58 | "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" 59 | ], 60 | "post-create-project-cmd": [ 61 | "@php artisan key:generate --ansi" 62 | ] 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /laravel-scout-extended/config/broadcasting.php: -------------------------------------------------------------------------------- 1 | env('BROADCAST_DRIVER', 'null'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Broadcast Connections 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the broadcast connections that will be used 26 | | to broadcast events to other systems or over websockets. Samples of 27 | | each available type of connection are provided inside this array. 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'pusher' => [ 34 | 'driver' => 'pusher', 35 | 'key' => env('PUSHER_APP_KEY'), 36 | 'secret' => env('PUSHER_APP_SECRET'), 37 | 'app_id' => env('PUSHER_APP_ID'), 38 | 'options' => [ 39 | 'cluster' => env('PUSHER_APP_CLUSTER'), 40 | 'useTLS' => true, 41 | ], 42 | ], 43 | 44 | 'redis' => [ 45 | 'driver' => 'redis', 46 | 'connection' => 'default', 47 | ], 48 | 49 | 'log' => [ 50 | 'driver' => 'log', 51 | ], 52 | 53 | 'null' => [ 54 | 'driver' => 'null', 55 | ], 56 | 57 | ], 58 | 59 | ]; 60 | -------------------------------------------------------------------------------- /laravel-scout-extended/config/cache.php: -------------------------------------------------------------------------------- 1 | env('CACHE_DRIVER', 'file'), 22 | 23 | /* 24 | |-------------------------------------------------------------------------- 25 | | Cache Stores 26 | |-------------------------------------------------------------------------- 27 | | 28 | | Here you may define all of the cache "stores" for your application as 29 | | well as their drivers. You may even define multiple stores for the 30 | | same cache driver to group types of items stored in your caches. 31 | | 32 | */ 33 | 34 | 'stores' => [ 35 | 36 | 'apc' => [ 37 | 'driver' => 'apc', 38 | ], 39 | 40 | 'array' => [ 41 | 'driver' => 'array', 42 | 'serialize' => false, 43 | ], 44 | 45 | 'database' => [ 46 | 'driver' => 'database', 47 | 'table' => 'cache', 48 | 'connection' => null, 49 | ], 50 | 51 | 'file' => [ 52 | 'driver' => 'file', 53 | 'path' => storage_path('framework/cache/data'), 54 | ], 55 | 56 | 'memcached' => [ 57 | 'driver' => 'memcached', 58 | 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), 59 | 'sasl' => [ 60 | env('MEMCACHED_USERNAME'), 61 | env('MEMCACHED_PASSWORD'), 62 | ], 63 | 'options' => [ 64 | // Memcached::OPT_CONNECT_TIMEOUT => 2000, 65 | ], 66 | 'servers' => [ 67 | [ 68 | 'host' => env('MEMCACHED_HOST', '127.0.0.1'), 69 | 'port' => env('MEMCACHED_PORT', 11211), 70 | 'weight' => 100, 71 | ], 72 | ], 73 | ], 74 | 75 | 'redis' => [ 76 | 'driver' => 'redis', 77 | 'connection' => 'cache', 78 | ], 79 | 80 | 'dynamodb' => [ 81 | 'driver' => 'dynamodb', 82 | 'key' => env('AWS_ACCESS_KEY_ID'), 83 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 84 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 85 | 'table' => env('DYNAMODB_CACHE_TABLE', 'cache'), 86 | 'endpoint' => env('DYNAMODB_ENDPOINT'), 87 | ], 88 | 89 | ], 90 | 91 | /* 92 | |-------------------------------------------------------------------------- 93 | | Cache Key Prefix 94 | |-------------------------------------------------------------------------- 95 | | 96 | | When utilizing a RAM based store such as APC or Memcached, there might 97 | | be other applications utilizing the same cache. So, we'll specify a 98 | | value to get prefixed to all our keys so we can avoid collisions. 99 | | 100 | */ 101 | 102 | 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'), 103 | 104 | ]; 105 | -------------------------------------------------------------------------------- /laravel-scout-extended/config/cors.php: -------------------------------------------------------------------------------- 1 | ['api/*'], 19 | 20 | 'allowed_methods' => ['*'], 21 | 22 | 'allowed_origins' => ['*'], 23 | 24 | 'allowed_origins_patterns' => [], 25 | 26 | 'allowed_headers' => ['*'], 27 | 28 | 'exposed_headers' => [], 29 | 30 | 'max_age' => 0, 31 | 32 | 'supports_credentials' => false, 33 | 34 | ]; 35 | -------------------------------------------------------------------------------- /laravel-scout-extended/config/filesystems.php: -------------------------------------------------------------------------------- 1 | env('FILESYSTEM_DRIVER', 'local'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Default Cloud Filesystem Disk 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Many applications store files both locally and in the cloud. For this 24 | | reason, you may specify a default "cloud" driver here. This driver 25 | | will be bound as the Cloud disk implementation in the container. 26 | | 27 | */ 28 | 29 | 'cloud' => env('FILESYSTEM_CLOUD', 's3'), 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Filesystem Disks 34 | |-------------------------------------------------------------------------- 35 | | 36 | | Here you may configure as many filesystem "disks" as you wish, and you 37 | | may even configure multiple disks of the same driver. Defaults have 38 | | been setup for each driver as an example of the required options. 39 | | 40 | | Supported Drivers: "local", "ftp", "sftp", "s3" 41 | | 42 | */ 43 | 44 | 'disks' => [ 45 | 46 | 'local' => [ 47 | 'driver' => 'local', 48 | 'root' => storage_path('app'), 49 | ], 50 | 51 | 'public' => [ 52 | 'driver' => 'local', 53 | 'root' => storage_path('app/public'), 54 | 'url' => env('APP_URL').'/storage', 55 | 'visibility' => 'public', 56 | ], 57 | 58 | 's3' => [ 59 | 'driver' => 's3', 60 | 'key' => env('AWS_ACCESS_KEY_ID'), 61 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 62 | 'region' => env('AWS_DEFAULT_REGION'), 63 | 'bucket' => env('AWS_BUCKET'), 64 | 'url' => env('AWS_URL'), 65 | 'endpoint' => env('AWS_ENDPOINT'), 66 | ], 67 | 68 | ], 69 | 70 | /* 71 | |-------------------------------------------------------------------------- 72 | | Symbolic Links 73 | |-------------------------------------------------------------------------- 74 | | 75 | | Here you may configure the symbolic links that will be created when the 76 | | `storage:link` Artisan command is executed. The array keys should be 77 | | the locations of the links and the values should be their targets. 78 | | 79 | */ 80 | 81 | 'links' => [ 82 | public_path('storage') => storage_path('app/public'), 83 | ], 84 | 85 | ]; 86 | -------------------------------------------------------------------------------- /laravel-scout-extended/config/hashing.php: -------------------------------------------------------------------------------- 1 | 'bcrypt', 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Bcrypt Options 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may specify the configuration options that should be used when 26 | | passwords are hashed using the Bcrypt algorithm. This will allow you 27 | | to control the amount of time it takes to hash the given password. 28 | | 29 | */ 30 | 31 | 'bcrypt' => [ 32 | 'rounds' => env('BCRYPT_ROUNDS', 10), 33 | ], 34 | 35 | /* 36 | |-------------------------------------------------------------------------- 37 | | Argon Options 38 | |-------------------------------------------------------------------------- 39 | | 40 | | Here you may specify the configuration options that should be used when 41 | | passwords are hashed using the Argon algorithm. These will allow you 42 | | to control the amount of time it takes to hash the given password. 43 | | 44 | */ 45 | 46 | 'argon' => [ 47 | 'memory' => 1024, 48 | 'threads' => 2, 49 | 'time' => 2, 50 | ], 51 | 52 | ]; 53 | -------------------------------------------------------------------------------- /laravel-scout-extended/config/logging.php: -------------------------------------------------------------------------------- 1 | env('LOG_CHANNEL', 'stack'), 21 | 22 | /* 23 | |-------------------------------------------------------------------------- 24 | | Log Channels 25 | |-------------------------------------------------------------------------- 26 | | 27 | | Here you may configure the log channels for your application. Out of 28 | | the box, Laravel uses the Monolog PHP logging library. This gives 29 | | you a variety of powerful log handlers / formatters to utilize. 30 | | 31 | | Available Drivers: "single", "daily", "slack", "syslog", 32 | | "errorlog", "monolog", 33 | | "custom", "stack" 34 | | 35 | */ 36 | 37 | 'channels' => [ 38 | 'stack' => [ 39 | 'driver' => 'stack', 40 | 'channels' => ['single'], 41 | 'ignore_exceptions' => false, 42 | ], 43 | 44 | 'single' => [ 45 | 'driver' => 'single', 46 | 'path' => storage_path('logs/laravel.log'), 47 | 'level' => 'debug', 48 | ], 49 | 50 | 'daily' => [ 51 | 'driver' => 'daily', 52 | 'path' => storage_path('logs/laravel.log'), 53 | 'level' => 'debug', 54 | 'days' => 14, 55 | ], 56 | 57 | 'slack' => [ 58 | 'driver' => 'slack', 59 | 'url' => env('LOG_SLACK_WEBHOOK_URL'), 60 | 'username' => 'Laravel Log', 61 | 'emoji' => ':boom:', 62 | 'level' => 'critical', 63 | ], 64 | 65 | 'papertrail' => [ 66 | 'driver' => 'monolog', 67 | 'level' => 'debug', 68 | 'handler' => SyslogUdpHandler::class, 69 | 'handler_with' => [ 70 | 'host' => env('PAPERTRAIL_URL'), 71 | 'port' => env('PAPERTRAIL_PORT'), 72 | ], 73 | ], 74 | 75 | 'stderr' => [ 76 | 'driver' => 'monolog', 77 | 'handler' => StreamHandler::class, 78 | 'formatter' => env('LOG_STDERR_FORMATTER'), 79 | 'with' => [ 80 | 'stream' => 'php://stderr', 81 | ], 82 | ], 83 | 84 | 'syslog' => [ 85 | 'driver' => 'syslog', 86 | 'level' => 'debug', 87 | ], 88 | 89 | 'errorlog' => [ 90 | 'driver' => 'errorlog', 91 | 'level' => 'debug', 92 | ], 93 | 94 | 'null' => [ 95 | 'driver' => 'monolog', 96 | 'handler' => NullHandler::class, 97 | ], 98 | 99 | 'emergency' => [ 100 | 'path' => storage_path('logs/laravel.log'), 101 | ], 102 | ], 103 | 104 | ]; 105 | -------------------------------------------------------------------------------- /laravel-scout-extended/config/queue.php: -------------------------------------------------------------------------------- 1 | env('QUEUE_CONNECTION', 'sync'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Queue Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may configure the connection information for each server that 24 | | is used by your application. A default configuration has been added 25 | | for each back-end shipped with Laravel. You are free to add more. 26 | | 27 | | Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null" 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'sync' => [ 34 | 'driver' => 'sync', 35 | ], 36 | 37 | 'database' => [ 38 | 'driver' => 'database', 39 | 'table' => 'jobs', 40 | 'queue' => 'default', 41 | 'retry_after' => 90, 42 | ], 43 | 44 | 'beanstalkd' => [ 45 | 'driver' => 'beanstalkd', 46 | 'host' => 'localhost', 47 | 'queue' => 'default', 48 | 'retry_after' => 90, 49 | 'block_for' => 0, 50 | ], 51 | 52 | 'sqs' => [ 53 | 'driver' => 'sqs', 54 | 'key' => env('AWS_ACCESS_KEY_ID'), 55 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 56 | 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), 57 | 'queue' => env('SQS_QUEUE', 'your-queue-name'), 58 | 'suffix' => env('SQS_SUFFIX'), 59 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 60 | ], 61 | 62 | 'redis' => [ 63 | 'driver' => 'redis', 64 | 'connection' => 'default', 65 | 'queue' => env('REDIS_QUEUE', 'default'), 66 | 'retry_after' => 90, 67 | 'block_for' => null, 68 | ], 69 | 70 | ], 71 | 72 | /* 73 | |-------------------------------------------------------------------------- 74 | | Failed Queue Jobs 75 | |-------------------------------------------------------------------------- 76 | | 77 | | These options configure the behavior of failed queue job logging so you 78 | | can control which database and table are used to store the jobs that 79 | | have failed. You may change them to any database / table you wish. 80 | | 81 | */ 82 | 83 | 'failed' => [ 84 | 'driver' => env('QUEUE_FAILED_DRIVER', 'database'), 85 | 'database' => env('DB_CONNECTION', 'mysql'), 86 | 'table' => 'failed_jobs', 87 | ], 88 | 89 | ]; 90 | -------------------------------------------------------------------------------- /laravel-scout-extended/config/scout.php: -------------------------------------------------------------------------------- 1 | env('SCOUT_DRIVER', 'algolia'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Index Prefix 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may specify a prefix that will be applied to all search index 26 | | names used by Scout. This prefix may be useful if you have multiple 27 | | "tenants" or applications sharing the same search infrastructure. 28 | | 29 | */ 30 | 31 | 'prefix' => env('SCOUT_PREFIX', ''), 32 | 33 | /* 34 | |-------------------------------------------------------------------------- 35 | | Queue Data Syncing 36 | |-------------------------------------------------------------------------- 37 | | 38 | | This option allows you to control if the operations that sync your data 39 | | with your search engines are queued. When this is set to "true" then 40 | | all automatic data syncing will get queued for better performance. 41 | | 42 | */ 43 | 44 | 'queue' => env('SCOUT_QUEUE', false), 45 | 46 | /* 47 | |-------------------------------------------------------------------------- 48 | | Chunk Sizes 49 | |-------------------------------------------------------------------------- 50 | | 51 | | These options allow you to control the maximum chunk size when you are 52 | | mass importing data into the search engine. This allows you to fine 53 | | tune each of these chunk sizes based on the power of the servers. 54 | | 55 | */ 56 | 57 | 'chunk' => [ 58 | 'searchable' => 500, 59 | 'unsearchable' => 500, 60 | ], 61 | 62 | /* 63 | |-------------------------------------------------------------------------- 64 | | Soft Deletes 65 | |-------------------------------------------------------------------------- 66 | | 67 | | This option allows to control whether to keep soft deleted records in 68 | | the search indexes. Maintaining soft deleted records can be useful 69 | | if your application still needs to search for the records later. 70 | | 71 | */ 72 | 73 | 'soft_delete' => false, 74 | 75 | /* 76 | |-------------------------------------------------------------------------- 77 | | Algolia Configuration 78 | |-------------------------------------------------------------------------- 79 | | 80 | | Here you may configure your Algolia settings. Algolia is a cloud hosted 81 | | search engine which works great with Scout out of the box. Just plug 82 | | in your application ID and admin API key to get started searching. 83 | | 84 | */ 85 | 86 | 'algolia' => [ 87 | 'id' => env('ALGOLIA_APP_ID', ''), 88 | 'secret' => env('ALGOLIA_SECRET', ''), 89 | ], 90 | 91 | ]; 92 | -------------------------------------------------------------------------------- /laravel-scout-extended/config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'domain' => env('MAILGUN_DOMAIN'), 19 | 'secret' => env('MAILGUN_SECRET'), 20 | 'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'), 21 | ], 22 | 23 | 'postmark' => [ 24 | 'token' => env('POSTMARK_TOKEN'), 25 | ], 26 | 27 | 'ses' => [ 28 | 'key' => env('AWS_ACCESS_KEY_ID'), 29 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 30 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 31 | ], 32 | 33 | ]; 34 | -------------------------------------------------------------------------------- /laravel-scout-extended/config/view.php: -------------------------------------------------------------------------------- 1 | [ 17 | resource_path('views'), 18 | ], 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Compiled View Path 23 | |-------------------------------------------------------------------------- 24 | | 25 | | This option determines where all the compiled Blade templates will be 26 | | stored for your application. Typically, this is within the storage 27 | | directory. However, as usual, you are free to change this value. 28 | | 29 | */ 30 | 31 | 'compiled' => env( 32 | 'VIEW_COMPILED_PATH', 33 | realpath(storage_path('framework/views')) 34 | ), 35 | 36 | ]; 37 | -------------------------------------------------------------------------------- /laravel-scout-extended/database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite 2 | *.sqlite-journal 3 | -------------------------------------------------------------------------------- /laravel-scout-extended/database/factories/ArticleFactory.php: -------------------------------------------------------------------------------- 1 | define(Article::class, function (Faker $faker) { 7 | 8 | return [ 9 | 'image_url' => $faker->imageUrl(), 10 | 'title' => $faker->realText($faker->numberBetween(10, 20)), 11 | 'author' => $faker->name, 12 | 'likes_count' => $faker->randomNumber(3), 13 | 'slug' => $faker->slug, 14 | ]; 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /laravel-scout-extended/database/factories/UserFactory.php: -------------------------------------------------------------------------------- 1 | define(User::class, function (Faker $faker) { 21 | return [ 22 | 'name' => $faker->name, 23 | 'email' => $faker->unique()->safeEmail, 24 | 'email_verified_at' => now(), 25 | 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 26 | 'remember_token' => Str::random(10), 27 | ]; 28 | }); 29 | -------------------------------------------------------------------------------- /laravel-scout-extended/database/migrations/2014_10_12_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->string('name'); 19 | $table->string('email')->unique(); 20 | $table->timestamp('email_verified_at')->nullable(); 21 | $table->string('password'); 22 | $table->rememberToken(); 23 | $table->timestamps(); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | * 30 | * @return void 31 | */ 32 | public function down() 33 | { 34 | Schema::dropIfExists('users'); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /laravel-scout-extended/database/migrations/2019_03_18_102855_create_articles_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->string('image_url'); 19 | $table->string('title'); 20 | $table->string('author'); 21 | $table->string('slug'); 22 | $table->integer('likes_count'); 23 | $table->timestamps(); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | * 30 | * @return void 31 | */ 32 | public function down() 33 | { 34 | Schema::dropIfExists('articles'); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /laravel-scout-extended/database/migrations/2019_08_19_000000_create_failed_jobs_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->text('connection'); 19 | $table->text('queue'); 20 | $table->longText('payload'); 21 | $table->longText('exception'); 22 | $table->timestamp('failed_at')->useCurrent(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | * 29 | * @return void 30 | */ 31 | public function down() 32 | { 33 | Schema::dropIfExists('failed_jobs'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /laravel-scout-extended/database/seeds/ArticleTableSeeder.php: -------------------------------------------------------------------------------- 1 | create(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /laravel-scout-extended/database/seeds/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | call(ArticleTableSeeder::class); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /laravel-scout-extended/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "dev": "npm run development", 5 | "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", 6 | "watch": "npm run development -- --watch", 7 | "watch-poll": "npm run watch -- --watch-poll", 8 | "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js", 9 | "prod": "npm run production", 10 | "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" 11 | }, 12 | "devDependencies": { 13 | "axios": "^0.19", 14 | "cross-env": "^7.0", 15 | "laravel-mix": "^5.0.1", 16 | "lodash": "^4.17.13", 17 | "resolve-url-loader": "^3.1.0", 18 | "sass": "^1.15.2", 19 | "sass-loader": "^8.0.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /laravel-scout-extended/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | ./tests/Unit 10 | 11 | 12 | ./tests/Feature 13 | 14 | 15 | 16 | 17 | ./app 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /laravel-scout-extended/public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews -Indexes 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Handle Authorization Header 9 | RewriteCond %{HTTP:Authorization} . 10 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 11 | 12 | # Redirect Trailing Slashes If Not A Folder... 13 | RewriteCond %{REQUEST_FILENAME} !-d 14 | RewriteCond %{REQUEST_URI} (.+)/$ 15 | RewriteRule ^ %1 [L,R=301] 16 | 17 | # Send Requests To Front Controller... 18 | RewriteCond %{REQUEST_FILENAME} !-d 19 | RewriteCond %{REQUEST_FILENAME} !-f 20 | RewriteRule ^ index.php [L] 21 | 22 | -------------------------------------------------------------------------------- /laravel-scout-extended/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/laravel-scout-extended/public/favicon.ico -------------------------------------------------------------------------------- /laravel-scout-extended/public/index.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | define('LARAVEL_START', microtime(true)); 11 | 12 | /* 13 | |-------------------------------------------------------------------------- 14 | | Register The Auto Loader 15 | |-------------------------------------------------------------------------- 16 | | 17 | | Composer provides a convenient, automatically generated class loader for 18 | | our application. We just need to utilize it! We'll simply require it 19 | | into the script here so that we don't have to worry about manual 20 | | loading any of our classes later on. It feels great to relax. 21 | | 22 | */ 23 | 24 | require __DIR__.'/../vendor/autoload.php'; 25 | 26 | /* 27 | |-------------------------------------------------------------------------- 28 | | Turn On The Lights 29 | |-------------------------------------------------------------------------- 30 | | 31 | | We need to illuminate PHP development, so let us turn on the lights. 32 | | This bootstraps the framework and gets it ready for use, then it 33 | | will load up this application so that we can run it and send 34 | | the responses back to the browser and delight our users. 35 | | 36 | */ 37 | 38 | $app = require_once __DIR__.'/../bootstrap/app.php'; 39 | 40 | /* 41 | |-------------------------------------------------------------------------- 42 | | Run The Application 43 | |-------------------------------------------------------------------------- 44 | | 45 | | Once we have the application, we can handle the incoming request 46 | | through the kernel, and send the associated response back to 47 | | the client's browser allowing them to enjoy the creative 48 | | and wonderful application we have prepared for them. 49 | | 50 | */ 51 | 52 | $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); 53 | 54 | $response = $kernel->handle( 55 | $request = Illuminate\Http\Request::capture() 56 | ); 57 | 58 | $response->send(); 59 | 60 | $kernel->terminate($request, $response); 61 | -------------------------------------------------------------------------------- /laravel-scout-extended/public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /laravel-scout-extended/public/web.config: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /laravel-scout-extended/resources/js/app.js: -------------------------------------------------------------------------------- 1 | require('./bootstrap'); 2 | -------------------------------------------------------------------------------- /laravel-scout-extended/resources/js/bootstrap.js: -------------------------------------------------------------------------------- 1 | window._ = require('lodash'); 2 | 3 | /** 4 | * We'll load the axios HTTP library which allows us to easily issue requests 5 | * to our Laravel back-end. This library automatically handles sending the 6 | * CSRF token as a header based on the value of the "XSRF" token cookie. 7 | */ 8 | 9 | window.axios = require('axios'); 10 | 11 | window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; 12 | 13 | /** 14 | * Echo exposes an expressive API for subscribing to channels and listening 15 | * for events that are broadcast by Laravel. Echo and event broadcasting 16 | * allows your team to easily build robust real-time web applications. 17 | */ 18 | 19 | // import Echo from 'laravel-echo'; 20 | 21 | // window.Pusher = require('pusher-js'); 22 | 23 | // window.Echo = new Echo({ 24 | // broadcaster: 'pusher', 25 | // key: process.env.MIX_PUSHER_APP_KEY, 26 | // cluster: process.env.MIX_PUSHER_APP_CLUSTER, 27 | // forceTLS: true 28 | // }); 29 | -------------------------------------------------------------------------------- /laravel-scout-extended/resources/lang/en/auth.php: -------------------------------------------------------------------------------- 1 | 'These credentials do not match our records.', 17 | 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /laravel-scout-extended/resources/lang/en/pagination.php: -------------------------------------------------------------------------------- 1 | '« Previous', 17 | 'next' => 'Next »', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /laravel-scout-extended/resources/lang/en/passwords.php: -------------------------------------------------------------------------------- 1 | 'Your password has been reset!', 17 | 'sent' => 'We have emailed your password reset link!', 18 | 'throttled' => 'Please wait before retrying.', 19 | 'token' => 'This password reset token is invalid.', 20 | 'user' => "We can't find a user with that email address.", 21 | 22 | ]; 23 | -------------------------------------------------------------------------------- /laravel-scout-extended/resources/sass/app.scss: -------------------------------------------------------------------------------- 1 | // 2 | -------------------------------------------------------------------------------- /laravel-scout-extended/resources/views/welcome.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Laravel 8 | 9 | 10 | 11 | 12 | 13 | 65 | 66 | 67 |
68 | @if (Route::has('login')) 69 | 80 | @endif 81 | 82 |
83 |
84 | Laravel 85 |
86 | 87 | 97 |
98 |
99 | 100 | 101 | -------------------------------------------------------------------------------- /laravel-scout-extended/routes/api.php: -------------------------------------------------------------------------------- 1 | get('/user', function (Request $request) { 18 | return $request->user(); 19 | }); 20 | -------------------------------------------------------------------------------- /laravel-scout-extended/routes/channels.php: -------------------------------------------------------------------------------- 1 | id === (int) $id; 18 | }); 19 | -------------------------------------------------------------------------------- /laravel-scout-extended/routes/console.php: -------------------------------------------------------------------------------- 1 | comment(Inspiring::quote()); 19 | })->describe('Display an inspiring quote'); 20 | -------------------------------------------------------------------------------- /laravel-scout-extended/routes/web.php: -------------------------------------------------------------------------------- 1 | get(); 21 | 22 | return $articles; 23 | }); 24 | -------------------------------------------------------------------------------- /laravel-scout-extended/server.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | $uri = urldecode( 11 | parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) 12 | ); 13 | 14 | // This file allows us to emulate Apache's "mod_rewrite" functionality from the 15 | // built-in PHP web server. This provides a convenient way to test a Laravel 16 | // application without having installed a "real" web server software here. 17 | if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) { 18 | return false; 19 | } 20 | 21 | require_once __DIR__.'/public/index.php'; 22 | -------------------------------------------------------------------------------- /laravel-scout-extended/storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !public/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /laravel-scout-extended/storage/app/public/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /laravel-scout-extended/storage/framework/.gitignore: -------------------------------------------------------------------------------- 1 | config.php 2 | routes.php 3 | schedule-* 4 | compiled.php 5 | services.json 6 | events.scanned.php 7 | routes.scanned.php 8 | down 9 | -------------------------------------------------------------------------------- /laravel-scout-extended/storage/framework/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !data/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /laravel-scout-extended/storage/framework/cache/data/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /laravel-scout-extended/storage/framework/sessions/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /laravel-scout-extended/storage/framework/testing/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /laravel-scout-extended/storage/framework/views/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /laravel-scout-extended/storage/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /laravel-scout-extended/tests/CreatesApplication.php: -------------------------------------------------------------------------------- 1 | make(Kernel::class)->bootstrap(); 19 | 20 | return $app; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /laravel-scout-extended/tests/Feature/ExampleTest.php: -------------------------------------------------------------------------------- 1 | get('/'); 18 | 19 | $response->assertStatus(200); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /laravel-scout-extended/tests/TestCase.php: -------------------------------------------------------------------------------- 1 | assertTrue(true); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /laravel-scout-extended/webpack.mix.js: -------------------------------------------------------------------------------- 1 | const mix = require('laravel-mix'); 2 | 3 | /* 4 | |-------------------------------------------------------------------------- 5 | | Mix Asset Management 6 | |-------------------------------------------------------------------------- 7 | | 8 | | Mix provides a clean, fluent API for defining some Webpack build steps 9 | | for your Laravel application. By default, we are compiling the Sass 10 | | file for the application as well as bundling up all the JS files. 11 | | 12 | */ 13 | 14 | mix.js('resources/js/app.js', 'public/js') 15 | .sass('resources/sass/app.scss', 'public/css'); 16 | -------------------------------------------------------------------------------- /php/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | .idea/codeStyleSettings.xml 3 | composer.lock 4 | /vendor/ 5 | coverage.xml 6 | -------------------------------------------------------------------------------- /php/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Algolia Team 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /php/README.md: -------------------------------------------------------------------------------- 1 | # About Algolia's API Client PHP 2 | 3 | Algolia's API Client php was created by, and is maintained by [Algolia](https://github.com/algolia). The Algolia Search API Client for php lets you easily use the Algolia Search REST API from your php code. 4 | 5 | ## Get started locally 6 | 7 | > **Requires:** 8 | - **[PHP 7.2+](https://php.net/releases/)** 9 | - **[Composer](https://getcomposer.org/)** 10 | 11 | First, use *composer* to playground dependencies: 12 | ```bash 13 | # Go inside the playground ruby folder 14 | cd api-clients-playground/php 15 | # Install dependencies 16 | composer install 17 | ``` 18 | 19 | Finally, edit and run the code on `bin/index.php`: 20 | ``` 21 | php bin/index.php 22 | ``` 23 | -------------------------------------------------------------------------------- /php/bin/index.php: -------------------------------------------------------------------------------- 1 | register(); 6 | 7 | // Here goes your code: 8 | $client = \Algolia\AlgoliaSearch\SearchClient::create('..', '..'); 9 | $index = $client->initIndex('contacts'); 10 | -------------------------------------------------------------------------------- /php/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "algolia/api-clients-playground", 3 | "keywords": ["algolia", "php", "playground"], 4 | "license": "MIT", 5 | "authors": [ 6 | { 7 | "name": "Algolia Team", 8 | "email": "support@algolia.com" 9 | } 10 | ], 11 | "require": { 12 | "php": "^7.2", 13 | "algolia/algoliasearch-client-php": "^2.2", 14 | "nunomaduro/collision": "^2.1", 15 | "symfony/var-dumper": "^4.1" 16 | }, 17 | "minimum-stability": "dev", 18 | "prefer-stable": true, 19 | "config": { 20 | "sort-packages": true, 21 | "preferred-install": "dist" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /python/README.md: -------------------------------------------------------------------------------- 1 | # About Algolia's API Client Python 2 | 3 | Algolia's API Client Python was created by, and is maintained by [Algolia](https://github.com/algolia). The Algolia Search API Client for Python lets you easily use the Algolia Search REST API from your Python code. 4 | 5 | ## Get started locally 6 | 7 | > **Requires:** 8 | - **[Homebrew](https://brew.sh)** 9 | 10 | First, use [Homebrew](https://brew.sh) to install Python 3.7: 11 | ```bash 12 | # Clone the repository 13 | git clone https://github.com/algolia/api-clients-playground 14 | cd api-clients-playground/python 15 | 16 | # Install Python 3 17 | brew install python3 18 | 19 | # Create a Python Virtual Environment inside your directory 20 | python3 -m venv venv 21 | 22 | # Activate the Python Virtual Environment 23 | source venv/bin/activate 24 | 25 | # At any time, use the following command to deactivate it 26 | deactivate 27 | ``` 28 | 29 | Finally, install `algoliasearch` - API Client Python v2: 30 | ``` 31 | pip install https://github.com/algolia/algoliasearch-client-python/archive/develop.zip 32 | ``` 33 | 34 | ### Synchronous example: 35 | 36 | ```py 37 | import os 38 | 39 | from algoliasearch.search_client import SearchClient 40 | from algoliasearch.exceptions import AlgoliaException 41 | 42 | client = SearchClient.create( 43 | os.environ.get('ALGOLIA_APPLICATION_ID_1'), 44 | os.environ.get('ALGOLIA_ADMIN_KEY_1') 45 | ) 46 | 47 | index = client.init_index('articles') 48 | 49 | index.save_objects([ 50 | {'objectID': 1, 'firstname': 'Jimmie', 'lastname': 'Barninger'}, 51 | {'objectID': 2, 'firstname': 'Warren', 'lastname': 'Speach'} 52 | ]).wait() 53 | 54 | hits = index.search('Jimmie') 55 | 56 | print(hits) 57 | ``` 58 | 59 | ### Asynchronous example: 60 | 61 | First, require asynchronous libraries: 62 | 63 | ``` 64 | pip install 'asyncio>=3.4,<4.0' 'aiohttp>=2.0,<4.0' 'async_timeout>=2.0,<4.0' 65 | ``` 66 | 67 | 68 | ```py 69 | import asyncio 70 | import os 71 | 72 | from algoliasearch.search_client import SearchClient 73 | from algoliasearch.exceptions import AlgoliaException 74 | from algoliasearch.responses import MultipleResponse 75 | 76 | app_id = os.environ.get('ALGOLIA_APPLICATION_ID_1') 77 | api_key = os.environ.get('ALGOLIA_ADMIN_KEY_1') 78 | 79 | 80 | async def main(): 81 | async with SearchClient.create(app_id, api_key) as client: 82 | index = client.init_index('articles') 83 | 84 | try: 85 | (await index.clear_objects_async()).wait() 86 | except AlgoliaException: # Index not found 87 | pass 88 | 89 | results = await asyncio.gather( 90 | index.save_object_async({'objectID': 1, 'foo': 'bar'}), 91 | index.save_object_async({'objectID': 2, 'foo': 'foo'}) 92 | ) 93 | 94 | MultipleResponse(results).wait() 95 | 96 | print(await index.search_async('')) 97 | 98 | asyncio.run(main()) 99 | ``` 100 | -------------------------------------------------------------------------------- /python/examples/async.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import os 3 | 4 | from algoliasearch.search_client import SearchClient 5 | from algoliasearch.exceptions import AlgoliaException 6 | from algoliasearch.responses import MultipleResponse 7 | 8 | app_id = os.environ.get('ALGOLIA_APPLICATION_ID_1') 9 | api_key = os.environ.get('ALGOLIA_ADMIN_KEY_1') 10 | 11 | 12 | async def main(): 13 | async with SearchClient.create(app_id, api_key) as client: 14 | index = client.init_index('articles') 15 | 16 | try: 17 | (await index.clear_objects_async()).wait() 18 | except AlgoliaException: # Index not found 19 | pass 20 | 21 | results = await asyncio.gather( 22 | index.save_object_async({'objectID': 1, 'foo': 'bar'}), 23 | index.save_object_async({'objectID': 2, 'foo': 'foo'}) 24 | ) 25 | 26 | MultipleResponse(results).wait() 27 | 28 | print(await index.search_async('')) 29 | 30 | asyncio.run(main()) 31 | -------------------------------------------------------------------------------- /python/examples/sync.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from algoliasearch.search_client import SearchClient 4 | from algoliasearch.exceptions import AlgoliaException 5 | 6 | client = SearchClient.create( 7 | os.environ.get('ALGOLIA_APPLICATION_ID_1'), 8 | os.environ.get('ALGOLIA_ADMIN_KEY_1') 9 | ) 10 | 11 | index = client.init_index('articles') 12 | 13 | try: 14 | index.clear_objects().wait() 15 | except AlgoliaException: # Index not found 16 | pass 17 | 18 | index.save_object({'objectID': 1, 'firstname': 'Jimmie', 'lastname': 'Barninger'}).wait() 19 | 20 | print(index.search('')) 21 | -------------------------------------------------------------------------------- /rails/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore the default SQLite database. 11 | /db/*.sqlite3 12 | /db/*.sqlite3-journal 13 | 14 | # Ignore all logfiles and tempfiles. 15 | /log/* 16 | /tmp/* 17 | !/log/.keep 18 | !/tmp/.keep 19 | 20 | # Ignore Byebug command history file. 21 | .byebug_history 22 | 23 | /.idea/* 24 | 25 | Gemfile.lock -------------------------------------------------------------------------------- /rails/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | 4 | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 5 | gem 'rails', '~> 5.0.0' 6 | # Use sqlite3 as the database for Active Record 7 | gem 'sqlite3', '~> 1.3.6' 8 | # Use Puma as the app server 9 | gem 'puma', '~> 3.0' 10 | # Use SCSS for stylesheets 11 | gem 'sass-rails', '~> 5.0' 12 | # Use Uglifier as compressor for JavaScript assets 13 | gem 'uglifier', '>= 1.3.0' 14 | # Use CoffeeScript for .coffee assets and views 15 | gem 'coffee-rails', '~> 4.2' 16 | # See https://github.com/rails/execjs#readme for more supported runtimes 17 | # gem 'therubyracer', platforms: :ruby 18 | 19 | # Use jquery as the JavaScript library 20 | gem 'jquery-rails' 21 | # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 22 | gem 'turbolinks', '~> 5' 23 | # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 24 | gem 'jbuilder', '~> 2.5' 25 | # Use Redis adapter to run Action Cable in production 26 | # gem 'redis', '~> 3.0' 27 | # Use ActiveModel has_secure_password 28 | # gem 'bcrypt', '~> 3.1.7' 29 | 30 | # Use algoliasearch 31 | gem 'algoliasearch-rails' 32 | 33 | # Use Capistrano for deployment 34 | # gem 'capistrano-rails', group: :development 35 | 36 | group :development, :test do 37 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console 38 | gem 'byebug', platform: :mri 39 | end 40 | 41 | group :development do 42 | # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. 43 | gem 'web-console' 44 | gem 'listen', '~> 3.0.5' 45 | # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 46 | gem 'spring' 47 | gem 'spring-watcher-listen', '~> 2.0.0' 48 | end 49 | 50 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 51 | gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 52 | -------------------------------------------------------------------------------- /rails/README.md: -------------------------------------------------------------------------------- 1 | # About Algolia's Rails integration 2 | 3 | Algolia's Rails integration was created by, and is maintained by [Algolia](https://github.com/algolia). 4 | 5 | ## Get started locally 6 | 7 | > **Requires:** 8 | - **[Ruby v2.2.2 or newer](https://www.ruby-lang.org/en/)** 9 | - **[Bundler](https://bundler.io/)** 10 | - **[Rails](https://rubyonrails.org/)** 11 | 12 | First, make sure you're using Rails v5.0.0 13 | ```bash 14 | rvm gemset create rails5 15 | rvm gemset use rails5 16 | gem install rails -v 5.0.0 17 | ``` 18 | 19 | Then setup the project 20 | ```bash 21 | # Go inside the playground Rails folder 22 | cd api-clients-playground/rails 23 | 24 | # Install dependencies 25 | bundle install 26 | 27 | # Change your credentials in config/initializers/algoliasearch.rb 28 | AlgoliaSearch.configuration = { 29 | application_id: ENV['ALGOLIA_APPLICATION_ID'], 30 | api_key: ENV['ALGOLIA_API_KEY'] 31 | } 32 | 33 | # Migrate DB 34 | rake db:migrate 35 | 36 | # See the DB with the `db/contacts.json` 37 | rake db:seed 38 | 39 | # Run the server 40 | bin/rails server 41 | ``` 42 | 43 | You can now edit the `app/controllers/search_controller.rb` and see your changes reflected. 44 | 45 | Happy coding! 46 | -------------------------------------------------------------------------------- /rails/Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative 'config/application' 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /rails/app/assets/config/manifest.js: -------------------------------------------------------------------------------- 1 | //= link_tree ../images 2 | //= link_directory ../javascripts .js 3 | //= link_directory ../stylesheets .css 4 | -------------------------------------------------------------------------------- /rails/app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/app/assets/images/.keep -------------------------------------------------------------------------------- /rails/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. JavaScript code in this file should be added after the last require_* statement. 9 | // 10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require jquery 14 | //= require jquery_ujs 15 | //= require turbolinks 16 | //= require_tree . 17 | -------------------------------------------------------------------------------- /rails/app/assets/javascripts/cable.js: -------------------------------------------------------------------------------- 1 | // Action Cable provides the framework to deal with WebSockets in Rails. 2 | // You can generate new channels where WebSocket features live using the rails generate channel command. 3 | // 4 | //= require action_cable 5 | //= require_self 6 | //= require_tree ./channels 7 | 8 | (function() { 9 | this.App || (this.App = {}); 10 | 11 | App.cable = ActionCable.createConsumer(); 12 | 13 | }).call(this); 14 | -------------------------------------------------------------------------------- /rails/app/assets/javascripts/channels/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/app/assets/javascripts/channels/.keep -------------------------------------------------------------------------------- /rails/app/assets/javascripts/search.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://coffeescript.org/ 4 | -------------------------------------------------------------------------------- /rails/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS 10 | * files in this directory. Styles in this file should be added after the last require_* statement. 11 | * It is generally better to create a new file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /rails/app/assets/stylesheets/search.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the Search controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /rails/app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Channel < ActionCable::Channel::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /rails/app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Connection < ActionCable::Connection::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /rails/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | protect_from_forgery with: :exception 3 | end 4 | -------------------------------------------------------------------------------- /rails/app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /rails/app/controllers/search_controller.rb: -------------------------------------------------------------------------------- 1 | class SearchController < ApplicationController 2 | def index 3 | @contacts = Contact.search("John") 4 | render :json => @contacts 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /rails/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /rails/app/helpers/search_helper.rb: -------------------------------------------------------------------------------- 1 | module SearchHelper 2 | end 3 | -------------------------------------------------------------------------------- /rails/app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | end 3 | -------------------------------------------------------------------------------- /rails/app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: 'from@example.com' 3 | layout 'mailer' 4 | end 5 | -------------------------------------------------------------------------------- /rails/app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | self.abstract_class = true 3 | end 4 | -------------------------------------------------------------------------------- /rails/app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/app/models/concerns/.keep -------------------------------------------------------------------------------- /rails/app/models/contact.rb: -------------------------------------------------------------------------------- 1 | class Contact < ApplicationRecord 2 | include AlgoliaSearch 3 | 4 | algoliasearch do 5 | # Use all default configuration 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /rails/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AlgoliasearchRails 5 | <%= csrf_meta_tags %> 6 | 7 | <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> 8 | <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> 9 | 10 | 11 | 12 | <%= yield %> 13 | 14 | 15 | -------------------------------------------------------------------------------- /rails/app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /rails/app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /rails/app/views/search/index.html.erb: -------------------------------------------------------------------------------- 1 |

Search#index

2 |

Find me in app/views/search/index.html.erb

3 | -------------------------------------------------------------------------------- /rails/bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /rails/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | begin 3 | load File.expand_path('../spring', __FILE__) 4 | rescue LoadError => e 5 | raise unless e.message.include?('spring') 6 | end 7 | APP_PATH = File.expand_path('../config/application', __dir__) 8 | require_relative '../config/boot' 9 | require 'rails/commands' 10 | -------------------------------------------------------------------------------- /rails/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | begin 3 | load File.expand_path('../spring', __FILE__) 4 | rescue LoadError => e 5 | raise unless e.message.include?('spring') 6 | end 7 | require_relative '../config/boot' 8 | require 'rake' 9 | Rake.application.run 10 | -------------------------------------------------------------------------------- /rails/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | require 'fileutils' 4 | include FileUtils 5 | 6 | # path to your application root. 7 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 8 | 9 | def system!(*args) 10 | system(*args) || abort("\n== Command #{args} failed ==") 11 | end 12 | 13 | chdir APP_ROOT do 14 | # This script is a starting point to setup your application. 15 | # Add necessary setup steps to this file. 16 | 17 | puts '== Installing dependencies ==' 18 | system! 'gem install bundler --conservative' 19 | system('bundle check') || system!('bundle install') 20 | 21 | # puts "\n== Copying sample files ==" 22 | # unless File.exist?('config/database.yml') 23 | # cp 'config/database.yml.sample', 'config/database.yml' 24 | # end 25 | 26 | puts "\n== Preparing database ==" 27 | system! 'bin/rails db:setup' 28 | 29 | puts "\n== Removing old logs and tempfiles ==" 30 | system! 'bin/rails log:clear tmp:clear' 31 | 32 | puts "\n== Restarting application server ==" 33 | system! 'bin/rails restart' 34 | end 35 | -------------------------------------------------------------------------------- /rails/bin/spring: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # This file loads Spring without using Bundler, in order to be fast. 4 | # It gets overwritten when you run the `spring binstub` command. 5 | 6 | unless defined?(Spring) 7 | require 'rubygems' 8 | require 'bundler' 9 | 10 | lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) 11 | spring = lockfile.specs.detect { |spec| spec.name == 'spring' } 12 | if spring 13 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path 14 | gem 'spring', spring.version 15 | require 'spring/binstub' 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /rails/bin/update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | require 'fileutils' 4 | include FileUtils 5 | 6 | # path to your application root. 7 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 8 | 9 | def system!(*args) 10 | system(*args) || abort("\n== Command #{args} failed ==") 11 | end 12 | 13 | chdir APP_ROOT do 14 | # This script is a way to update your development environment automatically. 15 | # Add necessary update steps to this file. 16 | 17 | puts '== Installing dependencies ==' 18 | system! 'gem install bundler --conservative' 19 | system('bundle check') || system!('bundle install') 20 | 21 | puts "\n== Updating database ==" 22 | system! 'bin/rails db:migrate' 23 | 24 | puts "\n== Removing old logs and tempfiles ==" 25 | system! 'bin/rails log:clear tmp:clear' 26 | 27 | puts "\n== Restarting application server ==" 28 | system! 'bin/rails restart' 29 | end 30 | -------------------------------------------------------------------------------- /rails/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative 'config/environment' 4 | 5 | run Rails.application 6 | -------------------------------------------------------------------------------- /rails/config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative 'boot' 2 | 3 | require 'rails/all' 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(*Rails.groups) 8 | 9 | module AlgoliasearchRails 10 | class Application < Rails::Application 11 | # Settings in config/environments/* take precedence over those specified here. 12 | # Application configuration should go into files in config/initializers 13 | # -- all .rb files in that directory are automatically loaded. 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /rails/config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 2 | 3 | require 'bundler/setup' # Set up gems listed in the Gemfile. 4 | -------------------------------------------------------------------------------- /rails/config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: async 3 | 4 | test: 5 | adapter: async 6 | 7 | production: 8 | adapter: redis 9 | url: redis://localhost:6379/1 10 | -------------------------------------------------------------------------------- /rails/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | # 7 | default: &default 8 | adapter: sqlite3 9 | pool: 5 10 | timeout: 5000 11 | 12 | development: 13 | <<: *default 14 | database: db/development.sqlite3 15 | 16 | # Warning: The database defined as "test" will be erased and 17 | # re-generated from your development database when you run "rake". 18 | # Do not set this db to the same as development or production. 19 | test: 20 | <<: *default 21 | database: db/test.sqlite3 22 | 23 | production: 24 | <<: *default 25 | database: db/production.sqlite3 26 | -------------------------------------------------------------------------------- /rails/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative 'application' 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /rails/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports. 13 | config.consider_all_requests_local = true 14 | 15 | # Enable/disable caching. By default caching is disabled. 16 | if Rails.root.join('tmp/caching-dev.txt').exist? 17 | config.action_controller.perform_caching = true 18 | 19 | config.cache_store = :memory_store 20 | config.public_file_server.headers = { 21 | 'Cache-Control' => 'public, max-age=172800' 22 | } 23 | else 24 | config.action_controller.perform_caching = false 25 | 26 | config.cache_store = :null_store 27 | end 28 | 29 | # Don't care if the mailer can't send. 30 | config.action_mailer.raise_delivery_errors = false 31 | 32 | config.action_mailer.perform_caching = false 33 | 34 | # Print deprecation notices to the Rails logger. 35 | config.active_support.deprecation = :log 36 | 37 | # Raise an error on page load if there are pending migrations. 38 | config.active_record.migration_error = :page_load 39 | 40 | # Debug mode disables concatenation and preprocessing of assets. 41 | # This option may cause significant delays in view rendering with a large 42 | # number of complex assets. 43 | config.assets.debug = true 44 | 45 | # Suppress logger output for asset requests. 46 | config.assets.quiet = true 47 | 48 | # Raises error for missing translations 49 | # config.action_view.raise_on_missing_translations = true 50 | 51 | # Use an evented file watcher to asynchronously detect changes in source code, 52 | # routes, locales, etc. This feature depends on the listen gem. 53 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker 54 | end 55 | -------------------------------------------------------------------------------- /rails/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure public file server for tests with Cache-Control for performance. 16 | config.public_file_server.enabled = true 17 | config.public_file_server.headers = { 18 | 'Cache-Control' => 'public, max-age=3600' 19 | } 20 | 21 | # Show full error reports and disable caching. 22 | config.consider_all_requests_local = true 23 | config.action_controller.perform_caching = false 24 | 25 | # Raise exceptions instead of rendering exception templates. 26 | config.action_dispatch.show_exceptions = false 27 | 28 | # Disable request forgery protection in test environment. 29 | config.action_controller.allow_forgery_protection = false 30 | config.action_mailer.perform_caching = false 31 | 32 | # Tell Action Mailer not to deliver emails to the real world. 33 | # The :test delivery method accumulates sent emails in the 34 | # ActionMailer::Base.deliveries array. 35 | config.action_mailer.delivery_method = :test 36 | 37 | # Print deprecation notices to the stderr. 38 | config.active_support.deprecation = :stderr 39 | 40 | # Raises error for missing translations 41 | # config.action_view.raise_on_missing_translations = true 42 | end 43 | -------------------------------------------------------------------------------- /rails/config/initializers/algoliasearch.rb: -------------------------------------------------------------------------------- 1 | AlgoliaSearch.configuration = { 2 | application_id: ENV['ALGOLIA_APPLICATION_ID'], 3 | api_key: ENV['ALGOLIA_API_KEY'] 4 | } 5 | -------------------------------------------------------------------------------- /rails/config/initializers/application_controller_renderer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # ApplicationController.renderer.defaults.merge!( 4 | # http_host: 'example.org', 5 | # https: false 6 | # ) 7 | -------------------------------------------------------------------------------- /rails/config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = '1.0' 5 | 6 | # Add additional assets to the asset load path 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | 9 | # Precompile additional assets. 10 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. 11 | # Rails.application.config.assets.precompile += %w( search.js ) 12 | -------------------------------------------------------------------------------- /rails/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /rails/config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Specify a serializer for the signed and encrypted cookie jars. 4 | # Valid options are :json, :marshal, and :hybrid. 5 | Rails.application.config.action_dispatch.cookies_serializer = :json 6 | -------------------------------------------------------------------------------- /rails/config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /rails/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /rails/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | -------------------------------------------------------------------------------- /rails/config/initializers/new_framework_defaults.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains migration options to ease your Rails 5.0 upgrade. 4 | # 5 | # Read the Rails 5.0 release notes for more info on each option. 6 | 7 | # Enable per-form CSRF tokens. Previous versions had false. 8 | Rails.application.config.action_controller.per_form_csrf_tokens = true 9 | 10 | # Enable origin-checking CSRF mitigation. Previous versions had false. 11 | Rails.application.config.action_controller.forgery_protection_origin_check = true 12 | 13 | # Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. 14 | # Previous versions had false. 15 | ActiveSupport.to_time_preserves_timezone = true 16 | 17 | # Require `belongs_to` associations by default. Previous versions had false. 18 | Rails.application.config.active_record.belongs_to_required_by_default = true 19 | 20 | # Do not halt callback chains when a callback returns false. Previous versions had true. 21 | ActiveSupport.halt_callback_chains_on_return_false = false 22 | 23 | # Configure SSL options to enable HSTS with subdomains. Previous versions had false. 24 | Rails.application.config.ssl_options = { hsts: { subdomains: true } } 25 | -------------------------------------------------------------------------------- /rails/config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.session_store :cookie_store, key: '_algoliasearch-rails_session' 4 | -------------------------------------------------------------------------------- /rails/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /rails/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more, please read the Rails Internationalization guide 20 | # available at http://guides.rubyonrails.org/i18n.html. 21 | 22 | en: 23 | hello: "Hello world" 24 | -------------------------------------------------------------------------------- /rails/config/puma.rb: -------------------------------------------------------------------------------- 1 | # Puma can serve each request in a thread from an internal thread pool. 2 | # The `threads` method setting takes two numbers a minimum and maximum. 3 | # Any libraries that use thread pools should be configured to match 4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 5 | # and maximum, this matches the default thread size of Active Record. 6 | # 7 | threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i 8 | threads threads_count, threads_count 9 | 10 | # Specifies the `port` that Puma will listen on to receive requests, default is 3000. 11 | # 12 | port ENV.fetch("PORT") { 3000 } 13 | 14 | # Specifies the `environment` that Puma will run in. 15 | # 16 | environment ENV.fetch("RAILS_ENV") { "development" } 17 | 18 | # Specifies the number of `workers` to boot in clustered mode. 19 | # Workers are forked webserver processes. If using threads and workers together 20 | # the concurrency of the application would be max `threads` * `workers`. 21 | # Workers do not work on JRuby or Windows (both of which do not support 22 | # processes). 23 | # 24 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 } 25 | 26 | # Use the `preload_app!` method when specifying a `workers` number. 27 | # This directive tells Puma to first boot the application and load code 28 | # before forking the application. This takes advantage of Copy On Write 29 | # process behavior so workers use less memory. If you use this option 30 | # you need to make sure to reconnect any threads in the `on_worker_boot` 31 | # block. 32 | # 33 | # preload_app! 34 | 35 | # The code in the `on_worker_boot` will be called if you are using 36 | # clustered mode by specifying a number of `workers`. After each worker 37 | # process is booted this block will be run, if you are using `preload_app!` 38 | # option you will want to use this block to reconnect to any threads 39 | # or connections that may have been created at application boot, Ruby 40 | # cannot share connections between processes. 41 | # 42 | # on_worker_boot do 43 | # ActiveRecord::Base.establish_connection if defined?(ActiveRecord) 44 | # end 45 | 46 | # Allow puma to be restarted by `rails restart` command. 47 | plugin :tmp_restart 48 | -------------------------------------------------------------------------------- /rails/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | get 'search/index' 3 | 4 | root 'search#index' 5 | end 6 | -------------------------------------------------------------------------------- /rails/config/secrets.yml: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rails secret` to generate a secure secret key. 9 | 10 | # Make sure the secrets in this file are kept private 11 | # if you're sharing your code publicly. 12 | 13 | development: 14 | secret_key_base: 4b5f89376c308e9e39293f062ee875c0504b29d6396e3d2cb0cb84aee54a2ec70e3fee414b988825eb46da8cdf83abb1e8bed8c08491593a7ac8f71807bd0a58 15 | 16 | test: 17 | secret_key_base: 33fee676a882ea81c3732b1ae949586fda081d01a2b1100f6779ce2f4ef73d351d241a1494f56fa44ecc57f90e0562adc3cf24429a488901436b965093a12342 18 | 19 | # Do not keep production secrets in the repository, 20 | # instead read values from the environment. 21 | production: 22 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> 23 | -------------------------------------------------------------------------------- /rails/config/spring.rb: -------------------------------------------------------------------------------- 1 | %w( 2 | .ruby-version 3 | .rbenv-vars 4 | tmp/restart.txt 5 | tmp/caching-dev.txt 6 | ).each { |path| Spring.watch(path) } 7 | -------------------------------------------------------------------------------- /rails/db/migrate/20190906152917_create_contacts.rb: -------------------------------------------------------------------------------- 1 | class CreateContacts < ActiveRecord::Migration[5.0] 2 | def change 3 | create_table :contacts do |t| 4 | t.string :name 5 | t.string :email 6 | t.string :company 7 | t.string :address 8 | t.string :city 9 | t.string :county 10 | t.string :state 11 | t.string :zip 12 | t.string :phone 13 | t.string :fax 14 | t.string :web 15 | t.integer :followers 16 | t.string :note 17 | t.datetime :created_at 18 | t.datetime :updated_at 19 | 20 | t.timestamps 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /rails/db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # Note that this schema.rb definition is the authoritative source for your 6 | # database schema. If you need to create the application database on another 7 | # system, you should be using db:schema:load, not running all the migrations 8 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 9 | # you'll amass, the slower it'll run and the greater likelihood for issues). 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema.define(version: 20190906152917) do 14 | 15 | create_table "contacts", force: :cascade do |t| 16 | t.string "name" 17 | t.string "email" 18 | t.string "company" 19 | t.string "address" 20 | t.string "city" 21 | t.string "county" 22 | t.string "state" 23 | t.string "zip" 24 | t.string "phone" 25 | t.string "fax" 26 | t.string "web" 27 | t.integer "followers" 28 | t.string "note" 29 | t.datetime "created_at", null: false 30 | t.datetime "updated_at", null: false 31 | end 32 | 33 | end 34 | -------------------------------------------------------------------------------- /rails/db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) 7 | # Character.create(name: 'Luke', movie: movies.first) 8 | Contact.delete_all 9 | Contact.clear_index! 10 | records = JSON.parse(File.read("#{Rails.root}/db/contacts.json")) 11 | records.each do |record| 12 | Contact.create record 13 | end 14 | Contact.reindex! 15 | -------------------------------------------------------------------------------- /rails/lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/lib/assets/.keep -------------------------------------------------------------------------------- /rails/lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/lib/tasks/.keep -------------------------------------------------------------------------------- /rails/log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/log/.keep -------------------------------------------------------------------------------- /rails/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The page you were looking for doesn't exist.

62 |

You may have mistyped the address or the page may have moved.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /rails/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The change you wanted was rejected.

62 |

Maybe you tried to change something you didn't have access to.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /rails/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

We're sorry, but something went wrong.

62 |
63 |

If you are the application owner check the logs for more information.

64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /rails/public/apple-touch-icon-precomposed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/public/apple-touch-icon-precomposed.png -------------------------------------------------------------------------------- /rails/public/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/public/apple-touch-icon.png -------------------------------------------------------------------------------- /rails/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/public/favicon.ico -------------------------------------------------------------------------------- /rails/public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /rails/test/controllers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/test/controllers/.keep -------------------------------------------------------------------------------- /rails/test/controllers/search_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class SearchControllerTest < ActionDispatch::IntegrationTest 4 | test "should get index" do 5 | get search_index_url 6 | assert_response :success 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /rails/test/fixtures/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/test/fixtures/.keep -------------------------------------------------------------------------------- /rails/test/fixtures/contacts.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | name: MyString 5 | email: MyString 6 | company: MyString 7 | address: MyString 8 | city: MyString 9 | county: MyString 10 | state: MyString 11 | zip: MyString 12 | phone: MyString 13 | fax: MyString 14 | web: MyString 15 | followers: 1 16 | note: MyString 17 | created_at: 2019-09-06 17:29:17 18 | updated_at: 2019-09-06 17:29:17 19 | 20 | two: 21 | name: MyString 22 | email: MyString 23 | company: MyString 24 | address: MyString 25 | city: MyString 26 | county: MyString 27 | state: MyString 28 | zip: MyString 29 | phone: MyString 30 | fax: MyString 31 | web: MyString 32 | followers: 1 33 | note: MyString 34 | created_at: 2019-09-06 17:29:17 35 | updated_at: 2019-09-06 17:29:17 36 | -------------------------------------------------------------------------------- /rails/test/fixtures/files/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/test/fixtures/files/.keep -------------------------------------------------------------------------------- /rails/test/helpers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/test/helpers/.keep -------------------------------------------------------------------------------- /rails/test/integration/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/test/integration/.keep -------------------------------------------------------------------------------- /rails/test/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/test/mailers/.keep -------------------------------------------------------------------------------- /rails/test/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/test/models/.keep -------------------------------------------------------------------------------- /rails/test/models/contact_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ContactTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /rails/test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV['RAILS_ENV'] ||= 'test' 2 | require File.expand_path('../../config/environment', __FILE__) 3 | require 'rails/test_help' 4 | 5 | class ActiveSupport::TestCase 6 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. 7 | fixtures :all 8 | 9 | # Add more helper methods to be used by all tests here... 10 | end 11 | -------------------------------------------------------------------------------- /rails/tmp/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/tmp/.keep -------------------------------------------------------------------------------- /rails/vendor/assets/javascripts/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/vendor/assets/javascripts/.keep -------------------------------------------------------------------------------- /rails/vendor/assets/stylesheets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/rails/vendor/assets/stylesheets/.keep -------------------------------------------------------------------------------- /ruby-v1/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | -------------------------------------------------------------------------------- /ruby-v1/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | # See https://github.com/algolia/algoliasearch-client-ruby 4 | gem "algoliasearch", ">=1.26" 5 | 6 | -------------------------------------------------------------------------------- /ruby-v1/README.md: -------------------------------------------------------------------------------- 1 | # About Algolia's API Client Ruby 2 | 3 | Algolia's API Client ruby was created by, and is maintained by [Algolia](https://github.com/algolia). The Algolia Search API Client for Ruby lets you easily use the Algolia Search REST API from your ruby code. 4 | 5 | ## Get started locally 6 | 7 | > **Requires:** 8 | - **[Ruby > 1.8.7](https://www.ruby-lang.org)** 9 | - **[Bundle](https://bundler.io/)** 10 | 11 | First, use *bundle* to playground dependencies: 12 | ```bash 13 | # Go inside the playground ruby folder 14 | cd api-clients-playground/ruby 15 | # Install dependencies 16 | bundle install 17 | ``` 18 | 19 | Finally, edit and run the code on `index.rb`: 20 | ``` 21 | ruby index.rb 22 | ``` 23 | -------------------------------------------------------------------------------- /ruby-v1/debug.log: -------------------------------------------------------------------------------- 1 | # Logfile created on 2020-09-16 17:07:40 +0200 by logger.rb/66358 2 | -------------------------------------------------------------------------------- /ruby-v1/index.rb: -------------------------------------------------------------------------------- 1 | require 'algoliasearch' 2 | 3 | Algolia.init(application_id: 'ALGOLIA_APP_ID', 4 | api_key: 'ALGOLIA_SECRET') 5 | index = Algolia::Index.new('INDEX_NAME') 6 | 7 | res = index.search('') 8 | puts res 9 | -------------------------------------------------------------------------------- /ruby/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | debug.log 3 | -------------------------------------------------------------------------------- /ruby/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | # See https://github.com/algolia/algoliasearch-client-ruby 4 | gem 'algolia', '~> 2.0' 5 | -------------------------------------------------------------------------------- /ruby/README.md: -------------------------------------------------------------------------------- 1 | # About Algolia's API Client Ruby 2 | 3 | Algolia's API Client ruby was created by, and is maintained by [Algolia](https://github.com/algolia). The Algolia Search API Client for Ruby lets you easily use the Algolia Search REST API from your ruby code. 4 | 5 | ## Get started locally 6 | 7 | > **Requires:** 8 | - **[Ruby > 2.2](https://www.ruby-lang.org)** 9 | - **[Bundle](https://bundler.io/)** 10 | 11 | First, use *bundle* to install the playground dependencies: 12 | ```bash 13 | # Go inside the playground ruby folder 14 | cd api-clients-playground/ruby-v2 15 | # Install dependencies 16 | bundle install 17 | ``` 18 | 19 | Finally, edit and run the code on `index.rb`: 20 | ``` 21 | bundle exec ruby index.rb 22 | ``` 23 | -------------------------------------------------------------------------------- /ruby/index.rb: -------------------------------------------------------------------------------- 1 | require 'algolia' 2 | 3 | client = Algolia::Search::Client.create('ALGOLIA_APPLICATION_ID','ALGOLIA_ADMIN_KEY') 4 | index = client.init_index('index_name') 5 | 6 | res = index.search('') 7 | puts res 8 | -------------------------------------------------------------------------------- /scala/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | 4 | # sbt specific 5 | .cache 6 | .lib/ 7 | dist/* 8 | target/ 9 | lib_managed/ 10 | src_managed/ 11 | project/boot/ 12 | project/plugins/project/ 13 | gpg.sbt 14 | 15 | # Scala-IDE specific 16 | .scala_dependencies 17 | .worksheet 18 | .idea 19 | *.iml 20 | -------------------------------------------------------------------------------- /scala/.scalafmt.conf: -------------------------------------------------------------------------------- 1 | version=2.0.0-RC5 2 | maxColumn = 100 3 | -------------------------------------------------------------------------------- /scala/README.md: -------------------------------------------------------------------------------- 1 | # Algolia's Scala playground 2 | 3 | ## Requirements 4 | 5 | - [JDK8 or above](https://openjdk.java.net/install/) 6 | - [Scala 2.12 or above](https://www.scala-lang.org/download/) 7 | - [SBT](https://www.scala-lang.org/download/) 8 | 9 | ## Using the playground 10 | 11 | ### From the IDE 12 | 13 | We recommend you to use [IntellijIDEA](https://www.jetbrains.com/idea/). 14 | 15 | Open `Main.scala` in Intellij and run the Main object. 16 | 17 | ### From sbt 18 | 19 | To run the playground from sbt: 20 | 21 | ```bash 22 | sbt compile 23 | 24 | sbt run 25 | ``` 26 | -------------------------------------------------------------------------------- /scala/build.sbt: -------------------------------------------------------------------------------- 1 | name := "scala-playground" 2 | 3 | version := "0.1" 4 | 5 | scalaVersion := "2.12.8" 6 | 7 | libraryDependencies += "com.algolia" %% "algoliasearch-scala" % "[1,)" 8 | 9 | trapExit := false 10 | -------------------------------------------------------------------------------- /scala/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.2.8 2 | -------------------------------------------------------------------------------- /scala/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.0") 2 | -------------------------------------------------------------------------------- /scala/src/main/scala/Contact.scala: -------------------------------------------------------------------------------- 1 | case class Contact(firstname: String, lastname: String, followers: Int, company: String) 2 | -------------------------------------------------------------------------------- /scala/src/main/scala/Main.scala: -------------------------------------------------------------------------------- 1 | import algolia.AlgoliaClient 2 | import algolia.AlgoliaDsl._ 3 | 4 | import scala.concurrent.{Await, Future} 5 | import scala.concurrent.ExecutionContext.Implicits.global 6 | import scala.concurrent.duration.Duration 7 | 8 | object Main extends App { 9 | 10 | val applicationId: String = System.getenv("ALGOLIA_APPLICATION_ID") 11 | val apiKey: String = System.getenv("ALGOLIA_ADMIN_API_KEY") 12 | 13 | val client = new AlgoliaClient(applicationId, apiKey) 14 | 15 | val indexing1 = client.execute { 16 | index into "contacts" `object` Contact("Jimmie", "Barninger", 93, "California Paint") 17 | } 18 | 19 | val indexing2 = client.execute { 20 | index into "contacts" `object` Contact("Warren", "Speach", 42, "Norwalk Crmc") 21 | } 22 | 23 | Await.ready(Future.sequence(Seq(indexing1, indexing2)), Duration.Inf) 24 | 25 | System.exit(0) 26 | } 27 | -------------------------------------------------------------------------------- /swift/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /Packages 4 | /*.xcodeproj 5 | xcuserdata/ 6 | /.swiftpm 7 | -------------------------------------------------------------------------------- /swift/Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "object": { 3 | "pins": [ 4 | { 5 | "package": "AlgoliaSearchClientSwift", 6 | "repositoryURL": "https://github.com/algolia/algoliasearch-client-swift", 7 | "state": { 8 | "branch": null, 9 | "revision": "a0496004ed4d97073775230a077b6b9ed78ecbce", 10 | "version": "8.0.0-beta.3" 11 | } 12 | }, 13 | { 14 | "package": "swift-log", 15 | "repositoryURL": "https://github.com/apple/swift-log.git", 16 | "state": { 17 | "branch": null, 18 | "revision": "74d7b91ceebc85daf387ebb206003f78813f71aa", 19 | "version": "1.2.0" 20 | } 21 | } 22 | ] 23 | }, 24 | "version": 1 25 | } 26 | -------------------------------------------------------------------------------- /swift/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.2 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "Playground", 8 | dependencies: [ 9 | .package(name: "AlgoliaSearchClientSwift", url: "https://github.com/algolia/algoliasearch-client-swift", from: "8.0.0-beta.3") 10 | ], 11 | targets: [ 12 | .target( 13 | name: "Playground", 14 | dependencies: ["AlgoliaSearchClientSwift"]), 15 | .testTarget( 16 | name: "PlaygroundTests", 17 | dependencies: ["Playground"]), 18 | ] 19 | ) 20 | -------------------------------------------------------------------------------- /swift/README.md: -------------------------------------------------------------------------------- 1 | # About Algolia's API CLient Swift 2 | 3 | Algolia's API Client Swift was created by, and is maintained by [Algolia](https://github.com/algolia). The Algolia Search API Client for Swift lets you easily use the Algolia Search REST API from your Swift code. 4 | 5 | ## Get started locally 6 | 7 | > **Requires:** 8 | - Swift 5 9 | - iOS 8 / macOS 10.10 / watchOS 2 / tvOS 9 10 | 11 | First, install the playground dependecies: 12 | ```bash 13 | # Go inside the swift playground folder 14 | cd api-clients-playground/swift 15 | 16 | # Install dependencies 17 | swift resolve 18 | ``` 19 | 20 | Finally, edit and run the code on `main.swift`: 21 | ``` 22 | swift run 23 | ``` 24 | -------------------------------------------------------------------------------- /swift/Sources/Playground/main.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import AlgoliaSearchClientSwift 3 | 4 | let client = Client(appID: "APPID", apiKey: "APIKEY") 5 | let index = client.index(withName: "INDEX NAME") 6 | 7 | do { 8 | let results = try index.search(query: "") 9 | print(results) 10 | } catch let error { 11 | print(error) 12 | } 13 | -------------------------------------------------------------------------------- /swift/Tests/LinuxMain.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | import PlaygroundTests 4 | 5 | var tests = [XCTestCaseEntry]() 6 | tests += PlaygroundTests.allTests() 7 | XCTMain(tests) 8 | -------------------------------------------------------------------------------- /swift/Tests/PlaygroundTests/PlaygroundTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | import class Foundation.Bundle 3 | 4 | final class PlaygroundTests: XCTestCase { 5 | func testExample() throws { 6 | // This is an example of a functional test case. 7 | // Use XCTAssert and related functions to verify your tests produce the correct 8 | // results. 9 | 10 | // Some of the APIs that we use below are available in macOS 10.13 and above. 11 | guard #available(macOS 10.13, *) else { 12 | return 13 | } 14 | 15 | let fooBinary = productsDirectory.appendingPathComponent("Playground") 16 | 17 | let process = Process() 18 | process.executableURL = fooBinary 19 | 20 | let pipe = Pipe() 21 | process.standardOutput = pipe 22 | 23 | try process.run() 24 | process.waitUntilExit() 25 | 26 | let data = pipe.fileHandleForReading.readDataToEndOfFile() 27 | let output = String(data: data, encoding: .utf8) 28 | 29 | XCTAssertEqual(output, "Hello, world!\n") 30 | } 31 | 32 | /// Returns path to the built products directory. 33 | var productsDirectory: URL { 34 | #if os(macOS) 35 | for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") { 36 | return bundle.bundleURL.deletingLastPathComponent() 37 | } 38 | fatalError("couldn't find the products directory") 39 | #else 40 | return Bundle.main.bundleURL 41 | #endif 42 | } 43 | 44 | static var allTests = [ 45 | ("testExample", testExample), 46 | ] 47 | } 48 | -------------------------------------------------------------------------------- /swift/Tests/PlaygroundTests/XCTestManifests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | #if !canImport(ObjectiveC) 4 | public func allTests() -> [XCTestCaseEntry] { 5 | return [ 6 | testCase(PlaygroundTests.allTests), 7 | ] 8 | } 9 | #endif 10 | -------------------------------------------------------------------------------- /swift/Vapor/README.md: -------------------------------------------------------------------------------- 1 | # The Algolia Client In Vapor 2 | 3 | ## Futures 4 | 5 | The Algolia Swift client uses callbacks for handling the asynchronous calls. 6 | In Vapor (and in Swift NIO) it is important to receive the response on the 7 | same `EventLoop` on which the operation was initiated on. Using callbacks for 8 | this could be cumbersome. 9 | 10 | A good solution for this is to utilise `Future`s by wrapping the original 11 | client's methods in an `EventLoopPromise` using function overloading in an 12 | extension. 13 | 14 | The original: 15 | 16 | ```swift 17 | func saveObjects( 18 | _ objects: [T], 19 | autoGeneratingObjectID: Bool = false, 20 | requestOptions: RequestOptions? = nil, 21 | completion: @escaping ResultBatchesCallback) -> Operation {} 22 | ``` 23 | 24 | The overload: 25 | 26 | ```swift 27 | func saveObjects( 28 | _ objects: [T], 29 | autoGeneratingObjectID: Bool = false, 30 | requestOptions: RequestOptions? = nil, 31 | on eventLoop: EventLoop) -> Future 32 | { 33 | let promise = eventLoop.makePromise(of: Void.self) 34 | self.saveObjects( 35 | objects, 36 | autoGeneratingObjectID: autoGeneratingObjectID, 37 | requestOptions: requestOptions, 38 | completion: { result in 39 | switch result { 40 | case .success: 41 | promise.succeed(()) 42 | case .failure(let error): 43 | promise.fail(error) 44 | } 45 | }) 46 | return promise.futureResult 47 | } 48 | ``` 49 | 50 | See `SearchClient+NIO.swift` for a set of examples. 51 | 52 | ### Usage 53 | 54 | The new overloads now expect the `EventLoop` and return a `Future`. 55 | 56 | ```swift 57 | let algoliaIndex = self 58 | .searchClient 59 | .index(withName: "SomeIndex") 60 | 61 | algoliaIndex 62 | .exists(on: self.client.eventLoop) 63 | .flatMap { exists in 64 | if exists { 65 | // do stuff 66 | } 67 | } 68 | ``` 69 | 70 | ## Dependency Injection 71 | 72 | Vapor 4 solves the DI problem very elegantly by adding extensions to the `Request` 73 | object. 74 | 75 | ```swift 76 | import AlgoliaSearchClient 77 | import Foundation 78 | import Vapor 79 | 80 | /// The class wraps the Algolia client to be an injectable Vapor service. 81 | final class Algolia { 82 | private let client: Client 83 | private let searchClient: SearchClient 84 | 85 | /// Creates and returns a 86 | /// - Parameter client: The Vapor client handling the incoming request. 87 | init(client: Client) { 88 | guard 89 | let appId: String = Environment.get("ALGOLIA_APP_ID"), 90 | let apiKey: String = Environment.get("ALGOLIA_API_KEY") 91 | else { 92 | log.error("ALGOLIA_APP_ID and/or ALGOLIA_API_KEY is missing from ENV") 93 | exit(9) 94 | } 95 | self.client = client 96 | self.searchClient = SearchClient( 97 | appID: ApplicationID(rawValue: appId), 98 | apiKey: APIKey(rawValue: apiKey)) 99 | } 100 | } 101 | 102 | extension Request { 103 | var algolia: Algolia { 104 | .init(client: self.client) 105 | } 106 | } 107 | ``` 108 | 109 | In the Controller then: 110 | 111 | ```swift 112 | let index = self 113 | .searchClient 114 | .index(withName: "SomeIndex") 115 | 116 | _ = req 117 | .algolia 118 | .update(index: index) 119 | .flatMapErrorThrowing { error in 120 | log.error("Failed to update the Algolia index", error) 121 | } 122 | ``` 123 | -------------------------------------------------------------------------------- /symfony/.env.test: -------------------------------------------------------------------------------- 1 | # define your env variables for the test env here 2 | KERNEL_CLASS='App\Kernel' 3 | APP_SECRET='$ecretf0rt3st' 4 | SYMFONY_DEPRECATIONS_HELPER=999999 5 | 6 | # Configure your database drive for sqlite in .env 7 | DATABASE_URL= 8 | 9 | ALGOLIA_APP_ID= 10 | ALGOLIA_API_KEY= 11 | -------------------------------------------------------------------------------- /symfony/.gitignore: -------------------------------------------------------------------------------- 1 | migrations/ 2 | ###> symfony/web-server-bundle ### 3 | /.web-server-pid 4 | ###< symfony/web-server-bundle ### 5 | .DS_Store 6 | .idea 7 | ###> symfony/framework-bundle ### 8 | /.env.local 9 | /.env 10 | /.env.local.php 11 | /.env.*.local 12 | /config/secrets/prod/prod.decrypt.private.php 13 | /public/bundles/ 14 | /var/ 15 | /vendor/ 16 | ###> symfony/phpunit-bridge ### 17 | .phpunit.result.cache 18 | /phpunit.xml 19 | ###< symfony/phpunit-bridge ### 20 | 21 | ###> phpunit/phpunit ### 22 | /phpunit.xml 23 | .phpunit.result.cache 24 | ###< phpunit/phpunit ### 25 | -------------------------------------------------------------------------------- /symfony/README.md: -------------------------------------------------------------------------------- 1 | # About Algolia's Symfony bundle 2 | 3 | Algolia Symfony bundle was created by, and is maintained by [Algolia](https://github.com/algolia). 4 | 5 | ## Get started locally 6 | > requires : 7 | * [Composer](https://getcomposer.org/) 8 | * [PHP 7.2+](https://www.php.net/releases/index.php) 9 | 10 | ```bash 11 | # Install from Algolia's Playground from Github 12 | git clone https://github.com/algolia/api-clients-playground 13 | 14 | # Move to Symfony folder. 15 | cd api-clients-playground/symfony 16 | 17 | # Install dependencies 18 | composer install 19 | 20 | # Configure your database drive for sqlite in .env 21 | DATABASE_URL=sqlite:///%kernel.project_dir%/var/data.db 22 | 23 | # Generate migration file 24 | php bin/console make:migration 25 | 26 | # Migrate you database in you local storage 27 | php bin/console doctrine:migrations:migrate 28 | 29 | # Add your credential in .env 30 | ALGOLIA_APP_ID='YOUR APPLICATION ID' 31 | ALGOLIA_API_KEY='YOUR ADMIN API KEY' 32 | 33 | # Fill you local database 34 | php bin/console doctrine:fixtures:load 35 | 36 | # Import your data to algolia 37 | php bin/console search:import 38 | 39 | # See the search query 40 | php bin/console server:run 41 | ``` 42 | 43 | > See the result of the query here : [localhost](http://127.0.0.1:8000) 44 | -------------------------------------------------------------------------------- /symfony/bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | =1.2) 9 | if (is_array($env = @include dirname(__DIR__).'/.env.local.php')) { 10 | $_ENV += $env; 11 | } elseif (! class_exists(Dotenv::class)) { 12 | throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.'); 13 | } else { 14 | // load all the .env files 15 | (new Dotenv(false))->loadEnv(dirname(__DIR__).'/.env'); 16 | } 17 | 18 | $_SERVER += $_ENV; 19 | $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev'; 20 | $_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; 21 | $_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int)$_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], 22 | FILTER_VALIDATE_BOOLEAN) ? '1' : '0'; 23 | -------------------------------------------------------------------------------- /symfony/config/bundles.php: -------------------------------------------------------------------------------- 1 | ['dev' => true], 5 | Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], 6 | Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], 7 | Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], 8 | Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], 9 | Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true], 10 | Algolia\SearchBundle\AlgoliaSearchBundle::class => ['all' => true], 11 | ]; 12 | -------------------------------------------------------------------------------- /symfony/config/packages/algolia_search.yaml: -------------------------------------------------------------------------------- 1 | # All available configuration can be found here: 2 | # https://www.algolia.com/doc/api-client/symfony/configuration/ 3 | algolia_search: 4 | # Don't index automatically DB updates https://www.algolia.com/doc/framework-integration/symfony/indexing/index-data-into-algolia/?client=php#indexing-automatically-via-doctrine-events 5 | doctrineSubscribedEvents: [] 6 | indices: 7 | - name: articles 8 | class: App\Entity\Article 9 | -------------------------------------------------------------------------------- /symfony/config/packages/cache.yaml: -------------------------------------------------------------------------------- 1 | framework: 2 | cache: 3 | # Unique name of your app: used to compute stable namespaces for cache keys. 4 | #prefix_seed: your_vendor_name/app_name 5 | 6 | # The "app" cache stores to the filesystem by default. 7 | # The data in this cache should persist between deploys. 8 | # Other options include: 9 | 10 | # Redis 11 | #app: cache.adapter.redis 12 | #default_redis_provider: redis://localhost 13 | 14 | # APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues) 15 | #app: cache.adapter.apcu 16 | 17 | # Namespaced pools use the above "app" backend by default 18 | #pools: 19 | #my.dedicated.cache: null 20 | -------------------------------------------------------------------------------- /symfony/config/packages/dev/routing.yaml: -------------------------------------------------------------------------------- 1 | framework: 2 | router: 3 | strict_requirements: true 4 | -------------------------------------------------------------------------------- /symfony/config/packages/doctrine.yaml: -------------------------------------------------------------------------------- 1 | doctrine: 2 | dbal: 3 | url: '%env(resolve:DATABASE_URL)%' 4 | 5 | # IMPORTANT: You MUST configure your server version, 6 | # either here or in the DATABASE_URL env var (see .env file) 7 | #server_version: '13' 8 | orm: 9 | auto_generate_proxy_classes: true 10 | naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware 11 | auto_mapping: true 12 | mappings: 13 | App: 14 | is_bundle: false 15 | type: annotation 16 | dir: '%kernel.project_dir%/src/Entity' 17 | prefix: 'App\Entity' 18 | alias: App 19 | -------------------------------------------------------------------------------- /symfony/config/packages/doctrine_migrations.yaml: -------------------------------------------------------------------------------- 1 | doctrine_migrations: 2 | migrations_paths: 3 | # namespace is arbitrary but should be different from App\Migrations 4 | # as migrations classes should NOT be autoloaded 5 | 'DoctrineMigrations': '%kernel.project_dir%/migrations' 6 | -------------------------------------------------------------------------------- /symfony/config/packages/framework.yaml: -------------------------------------------------------------------------------- 1 | # see https://symfony.com/doc/current/reference/configuration/framework.html 2 | framework: 3 | secret: '%env(APP_SECRET)%' 4 | #csrf_protection: true 5 | http_method_override: false 6 | 7 | # Enables session support. Note that the session will ONLY be started if you read or write from it. 8 | # Remove or comment this section to explicitly disable session support. 9 | session: 10 | handler_id: null 11 | cookie_secure: auto 12 | cookie_samesite: lax 13 | storage_factory_id: session.storage.factory.native 14 | 15 | #esi: true 16 | #fragments: true 17 | php_errors: 18 | log: true 19 | 20 | when@test: 21 | framework: 22 | test: true 23 | session: 24 | storage_factory_id: session.storage.factory.mock_file 25 | -------------------------------------------------------------------------------- /symfony/config/packages/prod/doctrine.yaml: -------------------------------------------------------------------------------- 1 | doctrine: 2 | orm: 3 | auto_generate_proxy_classes: false 4 | query_cache_driver: 5 | type: pool 6 | pool: doctrine.system_cache_pool 7 | result_cache_driver: 8 | type: pool 9 | pool: doctrine.result_cache_pool 10 | 11 | framework: 12 | cache: 13 | pools: 14 | doctrine.result_cache_pool: 15 | adapter: cache.app 16 | doctrine.system_cache_pool: 17 | adapter: cache.system 18 | -------------------------------------------------------------------------------- /symfony/config/packages/prod/routing.yaml: -------------------------------------------------------------------------------- 1 | framework: 2 | router: 3 | strict_requirements: null 4 | -------------------------------------------------------------------------------- /symfony/config/packages/routing.yaml: -------------------------------------------------------------------------------- 1 | framework: 2 | router: 3 | utf8: true 4 | 5 | # Configure how to generate URLs in non-HTTP contexts, such as CLI commands. 6 | # See https://symfony.com/doc/current/routing.html#generating-urls-in-commands 7 | #default_uri: http://localhost 8 | 9 | when@prod: 10 | framework: 11 | router: 12 | strict_requirements: null 13 | -------------------------------------------------------------------------------- /symfony/config/packages/test/doctrine.yaml: -------------------------------------------------------------------------------- 1 | doctrine: 2 | dbal: 3 | # "TEST_TOKEN" is typically set by ParaTest 4 | dbname_suffix: '_test%env(default::TEST_TOKEN)%' 5 | -------------------------------------------------------------------------------- /symfony/config/packages/test/framework.yaml: -------------------------------------------------------------------------------- 1 | framework: 2 | test: true 3 | session: 4 | storage_id: session.storage.mock_file 5 | -------------------------------------------------------------------------------- /symfony/config/packages/test/routing.yaml: -------------------------------------------------------------------------------- 1 | framework: 2 | router: 3 | strict_requirements: true 4 | -------------------------------------------------------------------------------- /symfony/config/preload.php: -------------------------------------------------------------------------------- 1 | doctrine/doctrine-bundle ### 5 | database: 6 | ports: 7 | - "5432" 8 | ###< doctrine/doctrine-bundle ### 9 | -------------------------------------------------------------------------------- /symfony/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | ###> doctrine/doctrine-bundle ### 5 | database: 6 | image: postgres:${POSTGRES_VERSION:-13}-alpine 7 | environment: 8 | POSTGRES_DB: ${POSTGRES_DB:-app} 9 | # You should definitely change the password in production 10 | POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-ChangeMe} 11 | POSTGRES_USER: ${POSTGRES_USER:-symfony} 12 | volumes: 13 | - db-data:/var/lib/postgresql/data:rw 14 | # You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data! 15 | # - ./docker/db/data:/var/lib/postgresql/data:rw 16 | ###< doctrine/doctrine-bundle ### 17 | 18 | volumes: 19 | ###> doctrine/doctrine-bundle ### 20 | db-data: 21 | ###< doctrine/doctrine-bundle ### 22 | -------------------------------------------------------------------------------- /symfony/migrations/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/symfony/migrations/.gitignore -------------------------------------------------------------------------------- /symfony/phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | tests 23 | 24 | 25 | 26 | 27 | 28 | src 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 42 | 43 | -------------------------------------------------------------------------------- /symfony/public/index.php: -------------------------------------------------------------------------------- 1 | bootEnv(dirname(__DIR__).'/.env'); 11 | 12 | if ($_SERVER['APP_DEBUG']) { 13 | umask(0000); 14 | 15 | Debug::enable(); 16 | } 17 | 18 | if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) { 19 | Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST); 20 | } 21 | 22 | if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) { 23 | Request::setTrustedHosts([$trustedHosts]); 24 | } 25 | 26 | $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); 27 | $request = Request::createFromGlobals(); 28 | $response = $kernel->handle($request); 29 | $response->send(); 30 | $kernel->terminate($request, $response); 31 | -------------------------------------------------------------------------------- /symfony/src/Controller/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/symfony/src/Controller/.gitignore -------------------------------------------------------------------------------- /symfony/src/Controller/ArticleController.php: -------------------------------------------------------------------------------- 1 | searchService = $searchService; 17 | } 18 | 19 | /** 20 | * @return JsonResponse 21 | */ 22 | public function index(): JsonResponse 23 | { 24 | $result = $this->searchService->rawSearch(Article::class, ''); 25 | 26 | return new JsonResponse($result); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /symfony/src/DataFixtures/AppFixtures.php: -------------------------------------------------------------------------------- 1 | setTitle('Foo'); 16 | $article->setAuthor('Bar'); 17 | $article->setLikesCount(mt_rand(10, 100)); 18 | $manager->persist($article); 19 | } 20 | 21 | $manager->flush(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /symfony/src/Entity/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/symfony/src/Entity/.gitignore -------------------------------------------------------------------------------- /symfony/src/Entity/Article.php: -------------------------------------------------------------------------------- 1 | id; 42 | } 43 | 44 | public function getTitle(): string 45 | { 46 | return $this->title; 47 | } 48 | 49 | public function setTitle(string $title): self 50 | { 51 | $this->title = $title; 52 | 53 | return $this; 54 | } 55 | 56 | public function getAuthor(): string 57 | { 58 | return $this->author; 59 | } 60 | 61 | public function setAuthor(string $author): self 62 | { 63 | $this->author = $author; 64 | 65 | return $this; 66 | } 67 | 68 | public function getLikesCount(): int 69 | { 70 | return $this->likesCount; 71 | } 72 | 73 | public function setLikesCount(int $likesCount): self 74 | { 75 | $this->likesCount = $likesCount; 76 | 77 | return $this; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /symfony/src/Entity/News.php: -------------------------------------------------------------------------------- 1 | import('../config/{packages}/*.yaml'); 17 | $container->import('../config/{packages}/'.$this->environment.'/*.yaml'); 18 | 19 | if (is_file(\dirname(__DIR__).'/config/services.yaml')) { 20 | $container->import('../config/services.yaml'); 21 | $container->import('../config/{services}_'.$this->environment.'.yaml'); 22 | } else { 23 | $container->import('../config/{services}.php'); 24 | } 25 | } 26 | 27 | protected function configureRoutes(RoutingConfigurator $routes): void 28 | { 29 | $routes->import('../config/{routes}/'.$this->environment.'/*.yaml'); 30 | $routes->import('../config/{routes}/*.yaml'); 31 | 32 | if (is_file(\dirname(__DIR__).'/config/routes.yaml')) { 33 | $routes->import('../config/routes.yaml'); 34 | } else { 35 | $routes->import('../config/{routes}.php'); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /symfony/src/Migrations/.gitignore: -------------------------------------------------------------------------------- 1 | *.php -------------------------------------------------------------------------------- /symfony/src/Repository/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/algolia/api-clients-playground/987beffac3434a9312a1fa3a620dfe4d16ecbc32/symfony/src/Repository/.gitignore -------------------------------------------------------------------------------- /symfony/src/Repository/ArticleRepository.php: -------------------------------------------------------------------------------- 1 | bootEnv(dirname(__DIR__).'/.env'); 11 | } 12 | --------------------------------------------------------------------------------