Skip to content

Commit 97aa813

Browse files
committed
feat(csharp): more guides
1 parent 93c8ad7 commit 97aa813

File tree

5 files changed

+165
-0
lines changed

5 files changed

+165
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace Algolia;
2+
3+
using System;
4+
using System.Text.Json;
5+
using System.Net.Http;
6+
using System.Collections.Generic;
7+
8+
{{> snippets/import}}
9+
10+
class EnableFilterPromote {
11+
12+
async Task Main(string[] args)
13+
{
14+
var condition = new Condition
15+
{
16+
Anchoring = Anchoring.Is,
17+
Pattern = "{facet:brand}"
18+
};
19+
20+
var consequence = new Consequence
21+
{
22+
FilterPromotes = true
23+
};
24+
25+
var rule = new Rule
26+
{
27+
ObjectID = "rule_with_filterPromotes",
28+
Conditions = [condition],
29+
Consequence = consequence
30+
};
31+
}
32+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace Algolia;
2+
3+
using System;
4+
using System.Text.Json;
5+
using System.Net.Http;
6+
using System.Collections.Generic;
7+
8+
{{> snippets/import}}
9+
10+
class SearchInReplicaIndex {
11+
12+
async Task Main(string[] args)
13+
{
14+
15+
try {
16+
{{> snippets/init}}
17+
18+
var query = "query";
19+
20+
// 1. Change the sort dynamically based on the UI events
21+
var sortByPrice = false;
22+
23+
// 2. Get the index name based on sortByPrice
24+
var indexName = sortByPrice ? "products_price_desc" : "products";
25+
26+
// 3. Search on dynamic index name (primary or replica)
27+
{{#dynamicSnippet}}searchWithIndexNameVar{{/dynamicSnippet}};
28+
} catch (Exception e) {
29+
Console.WriteLine(e.Message);
30+
}
31+
}
32+
}
33+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace Algolia;
2+
3+
using System;
4+
using System.Text.Json;
5+
using System.Net.Http;
6+
using System.Collections.Generic;
7+
8+
{{> snippets/import}}
9+
10+
class SearchWithAnalyticsAndHeader {
11+
12+
async Task Main(string[] args)
13+
{
14+
15+
try {
16+
{{> snippets/init}}
17+
18+
/*
19+
'94.228.178.246' should be replaced with your user's IP address.
20+
Depending on your stack there are multiple ways to get this information.
21+
*/
22+
var ip = "94.228.178.246";
23+
var query = "query";
24+
25+
var searchParams = new SearchParams(new SearchParamsObject { Query = query, Analytics = true });
26+
27+
{{#dynamicSnippet}}searchWithSearchParamsAndForwardedHeader{{/dynamicSnippet}};
28+
} catch (Exception e) {
29+
Console.WriteLine(e.Message);
30+
}
31+
}
32+
}
33+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespace Algolia;
2+
3+
using System;
4+
using System.Text.Json;
5+
using System.Net.Http;
6+
using System.Collections.Generic;
7+
8+
{{> snippets/import}}
9+
10+
class SearchWithLogicalOr {
11+
12+
async Task Main(string[] args)
13+
{
14+
15+
try {
16+
{{> snippets/init}}
17+
18+
var query = "the query";
19+
20+
var optionalWords = new OptionalWords(["the", "query"]);
21+
22+
var searchParams = new SearchParams(new SearchParamsObject
23+
{
24+
Query = query,
25+
OptionalWords = optionalWords
26+
});
27+
28+
{{#dynamicSnippet}}searchWithSearchParams{{/dynamicSnippet}};
29+
} catch (Exception e) {
30+
Console.WriteLine(e.Message);
31+
}
32+
}
33+
}
34+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace Algolia;
2+
3+
using System;
4+
using System.Text.Json;
5+
using System.Net.Http;
6+
using System.Collections.Generic;
7+
8+
{{> snippets/import}}
9+
10+
class UseConditionlessRule {
11+
12+
async Task Main(string[] args)
13+
{
14+
15+
try {
16+
{{> snippets/init}}
17+
18+
var objectID = "a-rule-id";
19+
20+
var rule = new Rule
21+
{
22+
ObjectID = objectID,
23+
Consequence = new Consequence(/* Set relevant consequence */),
24+
// Set validity (optional)
25+
Validity = [new TimeRange { From = 1688774400L, Until = 1738972800L }]
26+
};
27+
28+
{{#dynamicSnippet}}saveRule{{/dynamicSnippet}};
29+
} catch (Exception e) {
30+
Console.WriteLine(e.Message);
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)