diff --git a/website/docs/clients/guides/copy-or-move-index-rules-settings-synonyms.mdx b/website/docs/clients/guides/copy-or-move-index-rules-settings-synonyms.mdx index 7b4ca93113..4119fca128 100644 --- a/website/docs/clients/guides/copy-or-move-index-rules-settings-synonyms.mdx +++ b/website/docs/clients/guides/copy-or-move-index-rules-settings-synonyms.mdx @@ -73,6 +73,42 @@ UpdatedAtResponse response = client.operationIndex( client.waitForTask("", response.getTaskID()); ``` + + + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +operationIndexRequest := searchClient.NewApiOperationIndexRequest( + indexName, + search.NewOperationIndexParams(search.OPERATIONTYPE_COPY, ""), +) + +operationIndex, err := searchClient.OperationIndex(operationIndexRequest) +if err != nil { + panic(err) +} + +taskResponse, err := searchClient.WaitForTask( + indexName, + operationIndex.TaskID, + nil, + nil, + nil, +) +if err != nil { + panic(err) +} +``` + @@ -212,9 +248,41 @@ await client.waitTask('', response.taskID); ``` - -// TBD + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +operationIndexRequest := searchClient.NewApiOperationIndexRequest( + indexName, + search.NewOperationIndexParams(search.OPERATIONTYPE_MOVE, ""), +) + +operationIndex, err := searchClient.OperationIndex(operationIndexRequest) +if err != nil { + panic(err) +} + +taskResponse, err := searchClient.WaitForTask( + indexName, + operationIndex.TaskID, + nil, + nil, + nil, +) +if err != nil { + panic(err) +} +``` + @@ -322,6 +390,43 @@ await client.waitTask('', response.taskID); -// TBD + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +operationIndexRequest := searchClient.NewApiOperationIndexRequest( + indexName, + search.NewOperationIndexParams( + search.OPERATIONTYPE_MOVE, + "", + search.WithOperationIndexParamsScope([]search.ScopeType{search.SCOPETYPE_RULES}), + ), +) + +operationIndex, err := searchClient.OperationIndex(operationIndexRequest) +if err != nil { + panic(err) +} + +taskResponse, err := searchClient.WaitForTask( + indexName, + operationIndex.TaskID, + nil, + nil, + nil, +) +if err != nil { + panic(err) +} +``` + diff --git a/website/docs/clients/guides/customized-client-usage.mdx b/website/docs/clients/guides/customized-client-usage.mdx index 73d589cfea..841e6275f5 100644 --- a/website/docs/clients/guides/customized-client-usage.mdx +++ b/website/docs/clients/guides/customized-client-usage.mdx @@ -49,7 +49,6 @@ val client = SearchClient( ) ) ``` - @@ -65,7 +64,15 @@ var client = SearchClient( -// TBD + If you enable the `debug` property of the Go API client, it will print the request and response to the standard output. + +```go +searchClient := search.NewClientWithConfig(search.Configuration{ + AppID: "", + ApiKey: "", + Debug: true, +}) +``` @@ -199,7 +206,38 @@ await client.search( -// TBD + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +searchClient.Search( + searchClient.NewApiSearchRequest( + search.NewSearchMethodParams([]search.SearchQuery{ + search.SearchForHitsAsSearchQuery( + search.NewSearchForHits( + indexName, + search.WithSearchForHitsQuery("jeans"), + search.WithSearchForHitsHitsPerPage(50), + ), + ), + }), + ), + // This header is added to the request + search.HeaderParamOption("additional-header", "hello"), + + // As we re-define `hitsPerPage`, it will override the value defined in the method's parameters. + search.QueryParamOption("hitsPerPage", 100), +) +``` + @@ -295,7 +333,28 @@ var client = SearchClient( -// TBD + +> In the Go client, you can use the NewClientWithConfig method to create a new API client with the given configuration to fully customize the client behaviour. Only the AppID and APIKey are required, other configuration parameters will be defaulted if not provided. + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +searchClient := search.NewClientWithConfig(search.Configuration{ + AppID: appID, + ApiKey: apiKey, + Hosts: nil, + DefaultHeader: nil, + UserAgent: "my user agent (optional version)", + Debug: false, + Requester: nil, + ReadTimeout: 0, + WriteTimeout: 0, + Compression: 0, +}) +``` + @@ -385,8 +444,46 @@ var client = SearchClient( ``` - -// TBD + +> In the Go client, you can use the NewClientWithConfig method to create a new API client with the given configuration to fully customize the client behaviour. Only the AppID and APIKey are required, other configuration parameters will be defaulted if not provided. + +```go +import ( +"net/http" + +"github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +type MyCustomRequester struct { + client *http.Client +} + +func NewCustomRequester() *MyCustomRequester { + return &MyCustomRequester{ + client: http.DefaultClient, + } +} + +func (r *MyCustomRequester) Request(req *http.Request) (*http.Response, error) { + println("MyCustomRequester > Request: ", req.RequestURI) + + return r.client.Do(req) +} + +searchClient := search.NewClientWithConfig(search.Configuration{ + AppID: appID, + ApiKey: apiKey, + Hosts: nil, + DefaultHeader: nil, + UserAgent: "", + Debug: false, + Requester: NewCustomerRequester(), + ReadTimeout: 0, + WriteTimeout: 0, + Compression: 0, +}) +``` + diff --git a/website/docs/clients/guides/delete-objects.mdx b/website/docs/clients/guides/delete-objects.mdx index 1ce3dbbbb7..7222c49f94 100644 --- a/website/docs/clients/guides/delete-objects.mdx +++ b/website/docs/clients/guides/delete-objects.mdx @@ -97,7 +97,50 @@ await client.batch( -// TBD + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +objectIDs := []string{"1", "2", "3", "4", "5"} +batchRequests := make([]search.BatchRequest, 0, len(objectIDs)) + +for _, objectID := range objectIDs { + batchRequests = append( + batchRequests, + *search.NewBatchRequest(search.ACTION_DELETE, map[string]any{"objectID": objectID}), + ) +} + +batchWriteParams := search.NewBatchWriteParams(batchRequests) + +batchResponse, err := searchClient.Batch(searchClient.NewApiBatchRequest( + indexName, + batchWriteParams, +)) +if err != nil { + panic(err) +} + +taskResponse, err := searchClient.WaitForTask( + indexName, + batchResponse.TaskID, + nil, + nil, + nil, +) +if err != nil { + panic(err) +} +``` + diff --git a/website/docs/clients/guides/filtering-your-search.mdx b/website/docs/clients/guides/filtering-your-search.mdx index 1fddf8b322..cbbef897f4 100644 --- a/website/docs/clients/guides/filtering-your-search.mdx +++ b/website/docs/clients/guides/filtering-your-search.mdx @@ -87,7 +87,43 @@ client.setSettings( -// TBD + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +response, err := searchClient.SetSettings(searchClient.NewApiSetSettingsRequest( + indexName, + search.NewIndexSettings( + search.WithIndexSettingsAttributesForFaceting( + []string{ + "actor", + "filterOnly(category)", + "searchable(publisher)", + }, + ), + ), +)) +if err != nil { + panic(err) +} + +taskResponse, err := searchClient.WaitForTask( + indexName, + response.TaskID, + nil, + nil, + nil, +) +``` + @@ -308,7 +344,70 @@ await client.search( -// TBD + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +// Only "Scarlett Johansson" actor +results, err := searchClient.Search( + searchClient.NewApiSearchRequest( + search.NewSearchMethodParams( + []search.SearchQuery{ + search.SearchForHitsAsSearchQuery( + search.NewSearchForHits( + indexName, + search.WithSearchForHitsQuery(""), + search.WithSearchForHitsFilters("actor:Scarlett Johansson"), + ), + ), + }, + ), + ), +) + +// Only "Tom Cruise" or "Scarlett Johansson" actor +results, err := searchClient.Search( + searchClient.NewApiSearchRequest( + search.NewSearchMethodParams( + []search.SearchQuery{ + search.SearchForHitsAsSearchQuery( + search.NewSearchForHits( + indexName, + search.WithSearchForHitsQuery(""), + search.WithSearchForHitsFilters("actor:Tom Cruise OR actor:Scarlett Johansson"), + ), + ), + }, + ), + ), +) + +// Everything but "Nicolas Cage" actor +results, err := searchClient.Search( + searchClient.NewApiSearchRequest( + search.NewSearchMethodParams( + []search.SearchQuery{ + search.SearchForHitsAsSearchQuery( + search.NewSearchForHits( + indexName, + search.WithSearchForHitsQuery(""), + search.WithSearchForHitsFilters("NOT actor:Nicolas Cage"), + ), + ), + }, + ), + ), +) +``` + @@ -465,8 +564,60 @@ client.search( ``` - -// TBD + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +// Only "Scarlett Johansson" actor +results, err := searchClient.Search( + searchClient.NewApiSearchRequest( + search.NewSearchMethodParams( + []search.SearchQuery{ + search.SearchForHitsAsSearchQuery( + search.NewSearchForHits( + indexName, + search.WithSearchForHitsQuery(""), + search.WithSearchForHitsFacetFilters( + search.StringAsFacetFilters(search.PtrString("actor:Tom Cruise")), + ), + ), + ), + }, + ), + ), +) + +// Only "Tom Cruise" or "Scarlett Johansson" actor +results, err := searchClient.Search( + searchClient.NewApiSearchRequest( + search.NewSearchMethodParams( + []search.SearchQuery{ + search.SearchForHitsAsSearchQuery( + search.NewSearchForHits( + indexName, + search.WithSearchForHitsQuery(""), + search.WithSearchForHitsFacetFilters( + search.StringAsFacetFilters(search.PtrString("actor:Tom Cruise")), + ), + search.WithSearchForHitsFacetFilters( + search.StringAsFacetFilters(search.PtrString("actor:Scarlett Johansson")), + ), + ), + ), + }, + ), + ), +) +``` + diff --git a/website/docs/clients/guides/manage-dictionary-entries.mdx b/website/docs/clients/guides/manage-dictionary-entries.mdx index 3f39969a98..587481387f 100644 --- a/website/docs/clients/guides/manage-dictionary-entries.mdx +++ b/website/docs/clients/guides/manage-dictionary-entries.mdx @@ -5,7 +5,7 @@ title: Manage dictionary entries import { TabsLanguage } from '../../../src/components/TabsLanguage'; import TabItem from '@theme/TabItem'; -The REST API offers [a single endpoint to manage your dictorionary](https://api-clients-automation.netlify.app/specs/search#tag/Dictionaries/operation/batchDictionaryEntries). In this guide, we will demonstrate how to manage entries for different scenarios. +The REST API offers [a single endpoint to manage your dictionary](https://api-clients-automation.netlify.app/specs/search#tag/Dictionaries/operation/batchDictionaryEntries). In this guide, we will demonstrate how to manage entries for different scenarios. A `dictionaryName` can be either `stopwords`, `plurals` or `compounds`. @@ -126,7 +126,57 @@ await client.batchDictionaryEntries( -// TBD + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +response, err := searchClient.BatchDictionaryEntries( + searchClient.NewApiBatchDictionaryEntriesRequest( + // One of search.DICTIONARYTYPE_STOPWORDS, search.DICTIONARYTYPE_PLURALS or search.DICTIONARYTYPE_COMPOUNDS. + dictionaryType, + search.NewBatchDictionaryEntriesParams( + []search.BatchDictionaryEntriesRequest{ + *search.NewBatchDictionaryEntriesRequest( + search.DICTIONARYACTION_ADD_ENTRY, + *search.NewDictionaryEntry( + "1", + "en", + search.WithDictionaryEntryWord("fancy"), + search.WithDictionaryEntryWords([]string{"believe", "algolia"}), + search.WithDictionaryEntryDecomposition([]string{"trust", "algolia"}), + search.WithDictionaryEntryState(search.DICTIONARYENTRYSTATE_ENABLED), + ), + ), + }, + // Here we want to append data, so we don't clear existing entries. + search.WithBatchDictionaryEntriesParamsClearExistingDictionaryEntries(false), + ), + ), +) +if err != nil { + panic(err) +} + +taskResponse, err := searchClient.WaitForTask( + indexName, + response.TaskID, + nil, + nil, + nil, +) +if err != nil { + panic(err) +} +``` + @@ -247,7 +297,57 @@ await client.batchDictionaryEntries( -// TBD + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +response, err := searchClient.BatchDictionaryEntries( + searchClient.NewApiBatchDictionaryEntriesRequest( + // One of search.DICTIONARYTYPE_STOPWORDS, search.DICTIONARYTYPE_PLURALS or search.DICTIONARYTYPE_COMPOUNDS. + dictionaryType, + search.NewBatchDictionaryEntriesParams( + []search.BatchDictionaryEntriesRequest{ + *search.NewBatchDictionaryEntriesRequest( + search.DICTIONARYACTION_ADD_ENTRY, + *search.NewDictionaryEntry( + "1", + "en", + search.WithDictionaryEntryWord("fancy"), + search.WithDictionaryEntryWords([]string{"believe", "algolia"}), + search.WithDictionaryEntryDecomposition([]string{"trust", "algolia"}), + search.WithDictionaryEntryState(search.DICTIONARYENTRYSTATE_ENABLED), + ), + ), + }, + // Since we replace, we will create a new dictionary from those entries + search.WithBatchDictionaryEntriesParamsClearExistingDictionaryEntries(true), + ), + ), +) +if err != nil { + panic(err) +} + +taskResponse, err := searchClient.WaitForTask( + indexName, + response.TaskID, + nil, + nil, + nil, +) +if err != nil { + panic(err) +} +``` + @@ -321,7 +421,44 @@ await client.batchDictionaryEntries( -// TBD + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +response, err := searchClient.BatchDictionaryEntries( + searchClient.NewApiBatchDictionaryEntriesRequest( + // One of search.DICTIONARYTYPE_STOPWORDS, search.DICTIONARYTYPE_PLURALS or search.DICTIONARYTYPE_COMPOUNDS. + dictionaryType, + search.NewBatchDictionaryEntriesParams( + []search.BatchDictionaryEntriesRequest{}, // We don't push any new entries to it + search.WithBatchDictionaryEntriesParamsClearExistingDictionaryEntries(true), + ), + ), +) +if err != nil { + panic(err) +} + +taskResponse, err := searchClient.WaitForTask( + indexName, + response.TaskID, + nil, + nil, + nil, +) +if err != nil { + panic(err) +} +``` + @@ -416,7 +553,54 @@ await client.batchDictionaryEntries( -// TBD + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +response, err := searchClient.BatchDictionaryEntries( + searchClient.NewApiBatchDictionaryEntriesRequest( + // One of search.DICTIONARYTYPE_STOPWORDS, search.DICTIONARYTYPE_PLURALS or search.DICTIONARYTYPE_COMPOUNDS. + dictionaryType, + search.NewBatchDictionaryEntriesParams( + []search.BatchDictionaryEntriesRequest{ + *search.NewBatchDictionaryEntriesRequest( + // `deleteEntry` will remove any entries in the dictionary that have the same `objectID` as the `body.objectID` field. + search.DICTIONARYACTION_DELETE_ENTRY, + *search.NewDictionaryEntry( + "1", + "en", + ), + ), + }, + // We don't want to impact other entries. + search.WithBatchDictionaryEntriesParamsClearExistingDictionaryEntries(false), + ), + ), +) +if err != nil { + panic(err) +} + +taskResponse, err := searchClient.WaitForTask( + indexName, + response.TaskID, + nil, + nil, + nil, +) +if err != nil { + panic(err) +} +``` + diff --git a/website/docs/clients/guides/replace-all-rules-synonyms.mdx b/website/docs/clients/guides/replace-all-rules-synonyms.mdx index ee28a586ee..1d80f58e48 100644 --- a/website/docs/clients/guides/replace-all-rules-synonyms.mdx +++ b/website/docs/clients/guides/replace-all-rules-synonyms.mdx @@ -70,7 +70,40 @@ await client.saveRules( -// TBD + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +response, err := searchClient.SaveRules( + searchClient.NewApiSaveRulesRequest( + indexName, + []search.Rule{/* ... */}, + ).WithClearExistingRules(true), +) +if err != nil { + return 0 +} + +taskResponse, err := searchClient.WaitForTask( + indexName, + response.TaskID, + nil, + nil, + nil, +) +if err != nil { + panic(err) +} +``` + @@ -140,11 +173,45 @@ await client.saveSynonyms( -// TBD + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +response, err := searchClient.SaveSynonyms( + searchClient.NewApiSaveSynonymsRequest( + indexName, + []search.SynonymHit{ /* ... */ }, + ).WithReplaceExistingSynonyms(true), +) +if err != nil { + return 0 +} + +taskResponse, err := searchClient.WaitForTask( + indexName, + response.TaskID, + nil, + nil, + nil, +) +if err != nil { + panic(err) +} +``` + The `synonymHit`parameter should contain the synonyms you want to save. By executing the above code, all existing synonyms will be replaced with the new synonyms provided. -That's it! You have learned how to replace all existing rules and synonyms in Algolia using the `saveRules` and `saveSynonyms` methods respectively. \ No newline at end of file +That's it! You have learned how to replace all existing rules and synonyms in Algolia using the `saveRules` and `saveSynonyms` methods respectively. + diff --git a/website/docs/clients/guides/retrieving-facets.mdx b/website/docs/clients/guides/retrieving-facets.mdx index 51aac0c2b1..caff2ba167 100644 --- a/website/docs/clients/guides/retrieving-facets.mdx +++ b/website/docs/clients/guides/retrieving-facets.mdx @@ -160,8 +160,69 @@ await client.search( ``` - -// TBD + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +results, err := searchClient.Search( + searchClient.NewApiSearchRequest( + search.NewSearchMethodParams( + []search.SearchQuery{ + search.SearchForHitsAsSearchQuery( + search.NewSearchForHits( + indexName, + search.WithSearchForHitsFacets([]string{"author", "genre"}), + ), + ), + }, + ), + ), +) +if err != nil { + panic(err) +} +``` + +To extract all facet information, you can use a wildcard (`*`). + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +results, err := searchClient.Search( + searchClient.NewApiSearchRequest( + search.NewSearchMethodParams( + []search.SearchQuery{ + search.SearchForHitsAsSearchQuery( + search.NewSearchForHits( + indexName, + search.WithSearchForHitsFacets([]string{"*"}), + ), + ), + }, + ), + ), +) +if err != nil { + panic(err) +} +``` + diff --git a/website/docs/clients/guides/send-data-to-algolia.mdx b/website/docs/clients/guides/send-data-to-algolia.mdx index edc50dbb99..86e302fb39 100644 --- a/website/docs/clients/guides/send-data-to-algolia.mdx +++ b/website/docs/clients/guides/send-data-to-algolia.mdx @@ -69,7 +69,15 @@ var client = SearchClient(appId: '', apiKey: ''); -// TBD + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +searchClient := search.NewClient("", "") +``` + @@ -240,6 +248,53 @@ await client.waitTask('', response.taskID); -// TBD + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +actors := []map[string]interface{}{ + {"name": "Tom Cruise"}, + {"name": "Scarlett Johansson"}, +} + +requests := make([]search.BatchRequest, 0, len(actors)) + +for _, actor := range actors { + requests = append( + requests, + *search.NewBatchRequest(search.ACTION_ADD_OBJECT, actor), + ) +} + +response, err := searchClient.Batch( + searchClient.NewApiBatchRequest( + indexName, + search.NewBatchWriteParams(requests), + ), +) +if err != nil { + panic(err) +} + +taskResponse, err := searchClient.WaitForTask( + indexName, + response.TaskID, + nil, + nil, + nil, +) +if err != nil { + panic(err) +} +``` + diff --git a/website/docs/clients/guides/wait-for-a-task-to-finish.mdx b/website/docs/clients/guides/wait-for-a-task-to-finish.mdx index eeaf55a748..8d0ae2c461 100644 --- a/website/docs/clients/guides/wait-for-a-task-to-finish.mdx +++ b/website/docs/clients/guides/wait-for-a-task-to-finish.mdx @@ -153,8 +153,61 @@ await client.waitTask( ``` - -// TBD + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +response, err := searchClient.SaveObject( + searchClient.NewApiSaveObjectRequest( + indexName, + map[string]interface{}{ + "name": "Tom Cruise", + }, + ), +) +if err != nil { + panic(err) +} + +// Poll the task status with defaults values +taskResponse, err := searchClient.WaitForTask( + indexName, + response.TaskID, + nil, + nil, + nil, +) +if err != nil { + panic(err) +} + +// Poll the task status with your options +initialDelay := 1000*time.Millisecond +maxDelay := 10_000*time.Millisecond + +taskResponse, err := searchClient.WaitForTask( + indexName, + response.TaskID, + // Number of maximum retries to do. + search.PtrInt(100), + // The time to wait between retries, in milliseconds. + &initialDelay, + // The maximum delay to wait before making the request timeout, in milliseconds. + &maxDelay, +) +if err != nil { + panic(err) +} +``` + diff --git a/website/docs/clients/guides/wait-for-api-key-to-be-valid.mdx b/website/docs/clients/guides/wait-for-api-key-to-be-valid.mdx index f5aff73754..4ced4b6a01 100644 --- a/website/docs/clients/guides/wait-for-api-key-to-be-valid.mdx +++ b/website/docs/clients/guides/wait-for-api-key-to-be-valid.mdx @@ -196,6 +196,78 @@ await client.waitKeyDelete(key: keyResponse.key); -// TBD + +```go +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +apiKeyStruct := search.NewApiKey([]search.Acl{"search"}) + +addApiKeyResponse, err := searchClient.AddApiKey(searchClient.NewApiAddApiKeyRequest(apiKeyStruct)) +if err != nil { + panic(err) +} + +_, err = searchClient.WaitForApiKey( + addApiKeyResponse.Key, + apiKeyStruct, + "add", + nil, + nil, + nil, +) +if err != nil { + panic(err) +} + +apiKeyStruct.SetAcl([]search.Acl{"search", "addObject"}) + +updateApiKeyResponse, err := searchClient.UpdateApiKey( + searchClient.NewApiUpdateApiKeyRequest( + addApiKeyResponse.Key, + apiKeyStruct, + ), +) +if err != nil { + panic(err) +} + +_, err = searchClient.WaitForApiKey( + updateApiKeyResponse.Key, + apiKeyStruct, + "update", + nil, + nil, + nil, +) +if err != nil { + panic(err) +} + +deleteApiKeyResponse, err := searchClient.DeleteApiKey(searchClient.NewApiDeleteApiKeyRequest(addApiKeyResponse.Key)) +if err != nil { + panic(err) +} + +_, err = searchClient.WaitForApiKey( + deleteApiKeyResponse.Key, + apiKeyStruct, + "delete", + nil, + nil, + nil, +) +if err != nil { + panic(err) +} +``` + diff --git a/website/docs/clients/installation.mdx b/website/docs/clients/installation.mdx index 446f6b5fbb..1dcd99cdcb 100644 --- a/website/docs/clients/installation.mdx +++ b/website/docs/clients/installation.mdx @@ -111,6 +111,15 @@ dependencies { In multiplatform projects, add Algolia API client dependency to `commonMain`, and choose an [engine](https://ktor.io/docs/http-client-engines.html) for each target. + + + +First, install the Algolia API Go Client via the `go get` command: + +```bash +go get github.com/algolia/algoliasearch-client-go/v4 +``` + @@ -280,7 +289,73 @@ void main() async { -// TBD + +```go +package main + +import ( + "fmt" + + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +func main() { + // Instantiate the client + searchClient := search.NewClient("", "") + + // Add a new record to your Algolia index. + response, err := searchClient.AddOrUpdateObject( + searchClient.NewApiAddOrUpdateObjectRequest( + "", + "1", + map[string]interface{}{ + "name": "Foo", + "age": 42, + "city": "Paris", + }, + ), + ) + if err != nil { + panic(err) + } + + // Wait for the save operation to complete. + _, err = searchClient.WaitForTask( + indexName, + *response.TaskID, + nil, + nil, + nil, + ) + if err != nil { + panic(err) + } + + // Fetch search results. + searchResponse, err := searchClient.Search( + searchClient.NewApiSearchRequest( + search.NewSearchMethodParams( + []search.SearchQuery{ + search.SearchForHitsAsSearchQuery( + search.NewSearchForHits( + indexName, + search.WithSearchForHitsQuery(""), // Typo tolerant search. + ), + ), + }, + ), + ), + ) + if err != nil { + panic(err) + } + + for _, result := range searchResponse.Results { + fmt.Printf("Result: %v", result.SearchResponse) + } +} +``` + diff --git a/website/docs/clients/migration-guides/go.md b/website/docs/clients/migration-guides/go.md index 96f9472561..8dac60b3bc 100644 --- a/website/docs/clients/migration-guides/go.md +++ b/website/docs/clients/migration-guides/go.md @@ -9,5 +9,28 @@ Prior to the `initIndex` removal stated in the [common breaking changes](/docs/c That also mean you need to explicit the type you want to be returned from your queries, when it applies. ```go -// TBD +import ( + "github.com/algolia/algoliasearch-client-go/v4/algolia/search" +) + +indexName := "" +appID := "" +apiKey := "" + +searchClient := search.NewClient(appID, apiKey) + +results, err := searchClient.Search( + searchClient.NewApiSearchRequest( + search.NewSearchMethodParams( + []search.SearchQuery{ + search.SearchForHitsAsSearchQuery( + search.NewSearchForHits( + indexName, + search.WithSearchForHitsQuery(""), + ), + ), + }, + ), + ), +) ```