Skip to content

Commit f16f483

Browse files
committed
guides: half of them
1 parent 7d7c925 commit f16f483

22 files changed

+472
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 GlobalAlgoliaUserID
11+
{
12+
async Task Main(string[] args)
13+
{
14+
var client = new SearchClient(
15+
new SearchConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
16+
{
17+
DefaultHeaders = new Dictionary<string, string> { { "X-Algolia-UserToken", "test-user-123" } }
18+
}
19+
);
20+
Console.WriteLine(client.Config.DefaultHeaders);
21+
}
22+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 McmSearchWithout {
11+
12+
private static string GetAppIdFor(string user) {
13+
return ""; // Implement your own logic here
14+
}
15+
16+
private static string GetIndexingApiKeyFor(string user) {
17+
return ""; // Implement your own logic here
18+
}
19+
20+
async Task Main(string[] args)
21+
{
22+
23+
// Fetch from your own data storage and with your own code
24+
// the associated application ID and API key for this user
25+
var appId = GetAppIdFor("user42");
26+
var apiKey = GetIndexingApiKeyFor("user42");
27+
28+
var client = new SearchClient(new SearchConfig(appId, apiKey));
29+
var searchParams = new SearchParams(new SearchParamsObject
30+
{
31+
Query = "<YOUR_SEARCH_QUERY>",
32+
FacetFilters = new List<string> { "user:user42", "user:public" }
33+
}
34+
);
35+
36+
{{#dynamicSnippet}}searchWithSearchParams{{/dynamicSnippet}};
37+
}
38+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{> snippets/import}}
2+
3+
void globalAlgoliaUserID() async {
4+
final client = SearchClient(
5+
appId: 'ALGOLIA_APPLICATION_ID',
6+
apiKey: 'ALGOLIA_API_KEY',
7+
options: ClientOptions(
8+
headers: {
9+
'X-Algolia-User-ID': 'test-user-123',
10+
},
11+
));
12+
print(client.options.headers);
13+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{{> snippets/import}}
2+
3+
String getAppIDFor(String _) {
4+
return ""; // Implement your own logic here
5+
}
6+
7+
String getIndexingApiKeyFor(String _) {
8+
return ""; // Implement your own logic here
9+
}
10+
11+
void mcmSearchWithout() async {
12+
// Fetch from your own data storage and with your own code
13+
// the associated application ID and API key for this user
14+
final appId = getAppIDFor("user42");
15+
final apiKey = getIndexingApiKeyFor("user42");
16+
17+
final client = SearchClient(appId: appId, apiKey: apiKey);
18+
final searchParams = SearchParamsObject(
19+
query: "<YOUR_SEARCH_QUERY>",
20+
facetFilters: ["user:user42", "user:public"]
21+
);
22+
23+
await {{#dynamicSnippet}}searchWithSearchParams{{/dynamicSnippet}};
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"net/http"
7+
)
8+
9+
{{> snippets/import}}
10+
11+
func globalAlgoliaUserID() {
12+
client, err := search.NewClient("YourApplicationID", "YourAdminAPIKey")
13+
if err != nil {
14+
fmt.Println(err)
15+
}
16+
17+
client.AddDefaultHeader("X-Algolia-UserToken", "test-user-123")
18+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"net/http"
7+
)
8+
9+
{{> snippets/import}}
10+
11+
func getAppIDFor(_ string) (string, error) {
12+
return "", nil // Implement your logic here
13+
}
14+
15+
func getIndexingApiKeyFor(_ string) (string, error) {
16+
return "", nil // Implement your logic here
17+
}
18+
19+
func mcmSearchWithout() {
20+
// Fetch from your own data storage and with your own code
21+
// the associated application ID and API key for this user
22+
appID, err := getAppIDFor("user42")
23+
if err != nil {
24+
fmt.Println(err)
25+
return
26+
}
27+
28+
apiKey, err := getIndexingApiKeyFor("user42")
29+
if err != nil {
30+
fmt.Println(err)
31+
return
32+
}
33+
34+
client, err := search.NewClient(appID, apiKey)
35+
if err != nil {
36+
fmt.Println(err)
37+
return
38+
}
39+
40+
searchParams := search.SearchParamsObjectAsSearchParams(
41+
search.NewSearchParamsObject().
42+
SetQuery("<YOUR_SEARCH_QUERY>").
43+
SetFacetFilters([]string{"user:user42", "user:public"}),
44+
)
45+
46+
_, err = {{#dynamicSnippet}}searchWithSearchParams{{/dynamicSnippet}}
47+
if err != nil {
48+
panic(err)
49+
}
50+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.algolia;
2+
3+
{{> snippets/import}}
4+
5+
public class globalAlgoliaUserID {
6+
7+
public static void main(String[] args) throws Exception {
8+
SearchClient client = new SearchClient(
9+
"ALGOLIA_APPLICATION_ID",
10+
"ALGOLIA_API_KEY",
11+
ClientOptions.builder().addDefaultHeader("X-Algolia-UserToken", "test-user-123").build()
12+
);
13+
client.close();
14+
}
15+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.algolia;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
{{> snippets/import}}
7+
8+
public class mcmSearchWithout {
9+
10+
private static String getAppIDFor(String user) {
11+
return ""; // Implement your own logic here
12+
}
13+
14+
private static String getIndexingApiKeyFor(String user) {
15+
return ""; // Implement your own logic here
16+
}
17+
18+
public static void main(String[] args) throws Exception {
19+
20+
// Fetch from your own data storage and with your own code
21+
// the associated application ID and API key for this user
22+
String appID = getAppIDFor("user42");
23+
String apiKey = getIndexingApiKeyFor("user42");
24+
25+
try (SearchClient client = new SearchClient(appID, apiKey)) {
26+
SearchParams searchParams = new SearchParamsObject()
27+
.setQuery("<YOUR_SEARCH_QUERY>")
28+
.setFacetFilters(List.of("user:user42", "user:public"));
29+
30+
{{#dynamicSnippet}}searchWithSearchParams{{/dynamicSnippet}};
31+
} catch (Exception e) {
32+
System.out.println("An error occurred: " + e.getMessage());
33+
}
34+
}
35+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{{> snippets/import}}
2+
3+
const client = algoliasearch(appID, apiKey, {
4+
baseHeaders: {
5+
'X-Algolia-User-ID': 'test-user-123',
6+
},
7+
});
8+
console.log(client);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{{> snippets/import}}
2+
import type { IndexSettings } from 'algoliasearch';
3+
4+
const getAppIDFor = (_: string) => {
5+
return ""; // Implement your own logic here
6+
}
7+
const getIndexingApiKeyFor = (_: string) => {
8+
return ""; // Implement your own logic here
9+
}
10+
11+
// Fetch from your own data storage and with your own code
12+
// the associated application ID and API key for this user
13+
const appID = getAppIDFor("user42");
14+
const apiKey = getIndexingApiKeyFor("user42");
15+
16+
const client = algoliasearch(appID, apiKey);
17+
const searchParams: SearchParams = {
18+
query: "<YOUR_SEARCH_QUERY>",
19+
facetFilters: ["user:user42", "user:public"]
20+
};
21+
22+
{{#dynamicSnippet}}searchWithSearchParams{{/dynamicSnippet}}

0 commit comments

Comments
 (0)