Skip to content

Commit

Permalink
docs(csharp): add guides (#2695)
Browse files Browse the repository at this point in the history
  • Loading branch information
morganleroi authored Feb 16, 2024
1 parent c757282 commit 0bafedc
Show file tree
Hide file tree
Showing 15 changed files with 743 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ await client.waitTask('<SOURCE_INDEX_NAME>', response.taskID);
// TBD
</TabItem>

<TabItem value="csharp">

```csharp
using Algolia.Search.Clients;
using Algolia.Search.Models.Search;
using Algolia.Search.Utils;

var client = new SearchClient("<YOUR_APP_ID>", "<YOUR_API_KEY>");
var response = await client.OperationIndexAsync("<SOURCE_INDEX_NAME>",
new OperationIndexParams(OperationType.Copy, "<DESTINATION_INDEX_NAME>"));

await client.WaitForTaskAsync("<SOURCE_INDEX_NAME>", response.TaskID);
```

</TabItem>

</TabsLanguage>

## Rename/move an index
Expand Down Expand Up @@ -283,6 +299,22 @@ if err != nil {
}
```

</TabItem>

<TabItem value="csharp">

```csharp
using Algolia.Search.Clients;
using Algolia.Search.Models.Search;
using Algolia.Search.Utils;

var client = new SearchClient("<YOUR_APP_ID>", "<YOUR_API_KEY>");
var response = await client.OperationIndexAsync("<SOURCE_INDEX_NAME>",
new OperationIndexParams(OperationType.Move, "<DESTINATION_INDEX_NAME>"));

await client.WaitForTaskAsync("<SOURCE_INDEX_NAME>", response.TaskID);
```

</TabItem>
</TabsLanguage>

Expand Down Expand Up @@ -429,4 +461,28 @@ if err != nil {
```

</TabItem>

<TabItem value="csharp">

```csharp
using Algolia.Search.Clients;
using Algolia.Search.Models.Search;
using Algolia.Search.Utils;

var client = new SearchClient("<YOUR_APP_ID>", "<YOUR_API_KEY>");
var response = await client.OperationIndexAsync("<SOURCE_INDEX_NAME>",
new OperationIndexParams(OperationType.Copy, "<DESTINATION_INDEX_NAME>")
{
Scope =
[
ScopeType.Synonyms,
ScopeType.Rules
]
});

await client.WaitForTaskAsync("<SOURCE_INDEX_NAME>", response.TaskID);
```

</TabItem>

</TabsLanguage>
79 changes: 79 additions & 0 deletions website/docs/clients/guides/customized-client-usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ searchClient, _ := search.NewClientWithConfig(search.Configuration{
})
```
</TabItem>

<TabItem value="csharp">

```csharp
using Algolia.Search.Clients;
using Microsoft.Extensions.Logging;

var loggerFactory = LoggerFactory.Create(builder =>
{
// Log everything from Algolia in the console, including debug logs
builder.AddFilter("Algolia", LogLevel.Debug).AddConsole();
});

var client = new SearchClient("<YOUR_APP_ID>", "<YOUR_API_KEY>", loggerFactory);
```

</TabItem>

</TabsLanguage>

## Send additional information in your request with `requestOptions`
Expand Down Expand Up @@ -239,6 +257,39 @@ searchClient.Search(
```

</TabItem>

<TabItem value="csharp">

```csharp
using Algolia.Search.Clients;
using Algolia.Search.Http;
using Algolia.Search.Models.Search;

var client = new SearchClient("<YOUR_APP_ID>", "<YOUR_API_KEY>");

client.SearchSingleIndex<Hit>("<YOUR_INDEX_NAME>",
new SearchParams(new SearchParamsObject { Query = "<YOUR_QUERY>", HitsPerPage = 50 }),
// You can use the fluent builder to add extra headers, query parameters, and set the timeout.
new RequestOptionBuilder()
// This header is added to the request
.AddExtraHeader("additional-header", "hello")
.AddExtraHeader("another-header", "hello again")
// As we re-define `hitsPerPage`, it will override the value defined in the method's parameters.
.AddExtraQueryParameters("hitsPerPage", 100)
.SetTimeout(TimeSpan.FromMinutes(1)).Build());

client.SearchSingleIndex<Hit>("<YOUR_INDEX_NAME>",
new SearchParams(new SearchParamsObject { Query = "<YOUR_QUERY>", HitsPerPage = 50 }),
// You can also directly instantiate the RequestOptions object
new RequestOptions
{
Headers = new Dictionary<string, string> { { "additional-header", "hello" } },
QueryParameters = new Dictionary<string, object> { { "hitsPerPage", 100 } }
});
```

</TabItem>

</TabsLanguage>

## Provide your own user-agent
Expand Down Expand Up @@ -356,6 +407,21 @@ searchClient, _ := search.NewClientWithConfig(search.Configuration{
```

</TabItem>

<TabItem value="csharp">

```csharp
using Algolia.Search.Clients;

var searchConfig = new SearchConfig("<YOUR_APP_ID>", "<YOUR_API_KEY>");

// This will append `; my user agent (optional version)` to the current value of `x-algolia-agent` for every requests
searchConfig.UserAgent.AddSegment("my user agent", "optional version");
var client = new SearchClient(searchConfig);
```

</TabItem>

</TabsLanguage>

## Use your own HTTP requester
Expand Down Expand Up @@ -485,5 +551,18 @@ searchClient, _ := search.NewClientWithConfig(search.Configuration{
})
```

</TabItem>

<TabItem value="csharp">

> Create your own requester by creating a class that implements `IHttpRequester`, and use it by passing it to the client constructor.
```csharp
using Algolia.Search.Clients;

var config = new SearchConfig("<YOUR_APP_ID>", "<YOUR_API_KEY>");
var client = new SearchClient(config, new MyOwnRequester());
```

</TabItem>
</TabsLanguage>
28 changes: 26 additions & 2 deletions website/docs/clients/guides/delete-objects.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ In Algolia, you can delete multiple objects efficiently using the batch function

## Delete Multiple Objects

To delete multiple objects using batch, create a *batch write params* object that contains the array of delete requests.
Each delete request should have the `action` set to `deleteObject` and the `body` containing the respective object ID.
To delete multiple objects using batch, create a *batch write params* object that contains the array of delete requests.
Each delete request should have the `action` set to `deleteObject` and the `body` containing the respective object ID.
This allows you to define multiple delete operations within the `requests` array.

<TabsLanguage>
Expand Down Expand Up @@ -142,6 +142,30 @@ if err != nil {
```

</TabItem>


<TabItem value="csharp">

```csharp
using Algolia.Search.Clients;
using Algolia.Search.Models.Search;

var client = new SearchClient("<YOUR_APP_ID>", "<YOUR_API_KEY>");

var objectIDs = new List<string> { "1", "2", "3", "4", "5" };

var requests = objectIDs
.Select(objectId => new BatchRequest
{
Action = Algolia.Search.Models.Search.Action.Delete,
Body = new { objectID = objectId }
}).ToList();

await client.BatchAsync("<YOUR_INDEX_NAME>", new BatchWriteParams(requests));
```

</TabItem>

</TabsLanguage>

By executing the above code, all the objects with the specified object IDs will be deleted from your index.
Expand Down
72 changes: 72 additions & 0 deletions website/docs/clients/guides/filtering-your-search.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ taskResponse, err := searchClient.WaitForTask(

</TabItem>

<TabItem value="csharp">

```csharp
using Algolia.Search.Clients;
using Algolia.Search.Models.Search;

var client = new SearchClient("<YOUR_APP_ID>", "<YOUR_API_KEY>");
await client.SetSettingsAsync("YOUR_INDEX_NAME", new IndexSettings
{
AttributesForFaceting = ["actor", "filterOnly(category)", "searchable(publisher)"]
});
```

</TabItem>
</TabsLanguage>

### 2. Filter by Attributes (at query time)
Expand Down Expand Up @@ -409,6 +423,39 @@ results, err := searchClient.Search(
```

</TabItem>


<TabItem value="csharp">

```csharp
using Algolia.Search.Clients;
using Algolia.Search.Models.Search;

var client = new SearchClient("<YOUR_APP_ID>", "<YOUR_API_KEY>");
await client.SearchSingleIndexAsync<Actor>("YOUR_INDEX_NAME", new SearchParams(new SearchParamsObject
{
Query = "<YOUR_QUERY>",
// Only "Scarlett Johansson" actor
Filters = "actor:Scarlett Johansson"
}));

await client.SearchSingleIndexAsync<Actor>("YOUR_INDEX_NAME", new SearchParams(new SearchParamsObject
{
Query = "<YOUR_QUERY>",
// Only "Tom Cruise" or "Scarlett Johansson" actor
Filters = "actor:Tom Cruise OR actor:Scarlett Johansson"
}));

await client.SearchSingleIndexAsync<Actor>("YOUR_INDEX_NAME", new SearchParams(new SearchParamsObject
{
Query = "<YOUR_QUERY>",
// Everything but "Nicolas Cage" actor
Filters = "NOT actor:Nicolas Cage"
}));
```

</TabItem>

</TabsLanguage>

#### Filtering by string using the `facetFilters` field
Expand Down Expand Up @@ -620,4 +667,29 @@ results, err := searchClient.Search(
```

</TabItem>

<TabItem value="csharp">

```csharp
using Algolia.Search.Clients;
using Algolia.Search.Models.Search;

var client = new SearchClient("<YOUR_APP_ID>", "<YOUR_API_KEY>");
await client.SearchSingleIndexAsync<Actor>("YOUR_INDEX_NAME", new SearchParams(new SearchParamsObject
{
Query = "<YOUR_QUERY>",
// Only "Scarlett Johansson" actor
FacetFilters = new FacetFilters("actor:Scarlett Johansson"),
}));

await client.SearchSingleIndexAsync<Actor>("YOUR_INDEX_NAME", new SearchParams(new SearchParamsObject
{
Query = "<YOUR_QUERY>",
// Only "Tom Cruise" or "Scarlett Johansson" actor
FacetFilters = new FacetFilters("actor:Tom Cruise OR actor:Scarlett Johansson"),
}));
```

</TabItem>

</TabsLanguage>
Loading

0 comments on commit 0bafedc

Please sign in to comment.