File tree Expand file tree Collapse file tree 5 files changed +165
-0
lines changed
templates/csharp/guides/search Expand file tree Collapse file tree 5 files changed +165
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments