Skip to content

Commit d2127cf

Browse files
Fluf22shortcuts
andauthored
feat(clients): more manual snippets for doc (#4452)
Co-authored-by: shortcuts <[email protected]>
1 parent 6bbbc8b commit d2127cf

File tree

121 files changed

+1608
-275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+1608
-275
lines changed

config/generation.config.mjs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ export const patterns = [
2424
'!clients/algoliasearch-client-csharp/algoliasearch/Transport/**',
2525
'!clients/algoliasearch-client-csharp/algoliasearch/Models/Common/**',
2626

27-
'!docs/guides/csharp/src/program.cs',
28-
2927
'tests/output/csharp/global.json',
3028

3129
// Dart
@@ -52,8 +50,6 @@ export const patterns = [
5250
'!clients/algoliasearch-client-go/algolia/debug/*',
5351
'!clients/algoliasearch-client-go/algolia/utils/*',
5452

55-
'!docs/guides/go/src/main.go',
56-
5753
'!tests/output/go/go.*',
5854

5955
// Java
@@ -104,14 +100,6 @@ export const patterns = [
104100
'!clients/algoliasearch-client-php/lib/Configuration/ConfigWithRegion.php',
105101
'clients/algoliasearch-client-php/composer.json',
106102

107-
'docs/guides/php/**',
108-
'!docs/guides/php/.gitignore',
109-
'!docs/guides/php/composer.json',
110-
'!docs/guides/php/phpstan.neon',
111-
'docs/guides/php/composer.phar',
112-
'docs/guides/php/composer.lock',
113-
'docs/guides/php/vendor/**',
114-
115103
// Python
116104
'clients/algoliasearch-client-python/**',
117105
'!clients/algoliasearch-client-python/algoliasearch/http/**',
@@ -127,8 +115,6 @@ export const patterns = [
127115
'!tests/output/python/**/__init__.py',
128116
'tests/output/python/requirements.txt',
129117

130-
'docs/guides/python/**',
131-
'!docs/guides/python/pyproject.toml',
132118

133119
// Ruby
134120
'!clients/algoliasearch-client-ruby/**',

docs/guides/php/composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
{
2+
"repositories": [
3+
{
4+
"type": "path",
5+
"url": "../../../clients/algoliasearch-client-php"
6+
}
7+
],
28
"require": {
39
"algolia/algoliasearch-client-php": "*",
410
"ext-json": "*"

generators/src/main/java/com/algolia/codegen/cts/guides/GuidesGenerator.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ public void addSupportingFiles(List<SupportingFile> supportingFiles, String outp
4646
)
4747
);
4848
}
49+
50+
switch (language) {
51+
case "csharp":
52+
supportingFiles.add(
53+
new SupportingFile("guides/program.mustache", "docs/guides/" + language + outputFolder + "program" + extension)
54+
);
55+
break;
56+
case "go":
57+
supportingFiles.add(new SupportingFile("guides/main.mustache", "docs/guides/" + language + outputFolder + "main" + extension));
58+
break;
59+
case "php":
60+
supportingFiles.add(new SupportingFile("guides/.gitignore", "docs/guides/" + language + outputFolder + ".gitignore"));
61+
supportingFiles.add(new SupportingFile("guides/composer.json", "docs/guides/" + language + outputFolder + "composer.json"));
62+
supportingFiles.add(new SupportingFile("guides/phpstan.neon", "docs/guides/" + language + outputFolder + "phpstan.neon"));
63+
break;
64+
default:
65+
break;
66+
}
4967
}
5068

5169
@Override

generators/src/main/java/com/algolia/codegen/cts/tests/ParametersWithDataType.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,12 @@ private Map<String, Object> traverseParams(
181181
}
182182

183183
// for snippets, we want pretty index names, unless they are already pretty
184-
if (prettyIndexName && paramName.equals("indexName") && !((String) testOutput.get("value")).startsWith("<")) {
184+
if (
185+
prettyIndexName &&
186+
paramName.equals("indexName") &&
187+
!((String) testOutput.get("value")).startsWith("<") &&
188+
!((Boolean) testOutput.getOrDefault("isVerbatim", false))
189+
) {
185190
testOutput.put("value", "<YOUR_INDEX_NAME>");
186191
}
187192

scripts/ci/codegen/pushToRepository.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ async function pushToRepository(repository: string, config: RepositoryConfigurat
158158
head: task.prBranch,
159159
});
160160

161+
await run(`gh pr merge ${data.number} --auto`);
162+
161163
console.log(`Pull request created on ${OWNER}/${repository}`);
162164
console.log(` > ${data.url}`);
163165
}

scripts/common.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import clientsConfig from '../config/clients.config.json' with { type: 'json' };
1010
import releaseConfig from '../config/release.config.json' with { type: 'json' };
1111

1212
import { Cache } from './cache.ts';
13-
import { getDockerImage, getTestOutputFolder } from './config.ts';
13+
import { getClientsConfigField, getDockerImage } from './config.ts';
1414
import { generateOpenapitools } from './pre-gen/index.ts';
1515
import { getGitAuthor } from './release/common.ts';
1616
import { buildSpecs } from './specs/index.ts';
@@ -294,9 +294,12 @@ export async function setupAndGen(
294294

295295
for (const gen of generators) {
296296
if (mode === 'guides') {
297-
await run(`rm -rf ${path.join('docs', mode, gen.language, getTestOutputFolder(gen.language))}`, {
298-
language: gen.language,
299-
});
297+
await run(
298+
`rm -rf ${path.join('docs', mode, gen.language, getClientsConfigField(gen.language, ['snippets', 'outputFolder']))}`,
299+
{
300+
language: gen.language,
301+
},
302+
);
300303
}
301304

302305
const spinner = createSpinner(`generating ${mode} for ${gen.key}`);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Algolia;
2+
3+
public static class Program
4+
{
5+
public static void Main() { }
6+
}
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+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{> snippets/import}}
2+
3+
void enableFilterPromote() async {
4+
final condition = Condition(
5+
pattern: "{facet:brand}",
6+
anchoring: Anchoring.is_,
7+
);
8+
9+
final consequence = Consequence(
10+
filterPromotes: true
11+
);
12+
13+
// ignore: unused_local_variable
14+
final rule = Rule(
15+
objectID: "rule_with_filterPromotes",
16+
conditions: [condition],
17+
consequence: consequence
18+
);
19+
}

templates/dart/guides/search/savePopularRecords.mustache

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ void savePopularRecords() async {
1212
indexName: "indexName", browseParams: browseParams
1313
);
1414
for (final hit in browseResponse.hits) {
15-
final isPopular = hit['nbFollowers'] > 1000;
15+
final props = hit.toJson();
16+
final isPopular = props['nbFollowers'] > 1000;
1617
final updatedProduct = {
17-
...hit,
18+
...props,
1819
'isPopular': isPopular,
1920
};
2021
records.add(updatedProduct);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{> snippets/import}}
2+
3+
void searchInReplicaIndex() async {
4+
{{> snippets/init}}
5+
6+
// 1. Change the sort dynamically based on the UI events
7+
final sortByPrice = false;
8+
9+
// 2. Get the index name based on sortByPrice
10+
// ignore: dead_code
11+
final indexName = sortByPrice ? "products_price_desc" : "products";
12+
13+
// 3. Search on dynamic index name (primary or replica)
14+
await {{#dynamicSnippet}}searchWithIndexNameVar{{/dynamicSnippet}};
15+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{{> snippets/import}}
2+
3+
void searchWithAnalyticsAndHeader() async {
4+
{{> snippets/init}}
5+
6+
/*
7+
'94.228.178.246' should be replaced with your user's IP address.
8+
Depending on your stack there are multiple ways to get this information.
9+
*/
10+
final ip = "94.228.178.246";
11+
final query = "query";
12+
13+
final searchParams = SearchParamsObject(
14+
query: query,
15+
analytics: true
16+
);
17+
18+
await {{#dynamicSnippet}}searchWithSearchParamsAndForwardedHeader{{/dynamicSnippet}};
19+
}
20+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{{> snippets/import}}
2+
3+
void searchWithLogicalOr() async {
4+
{{> snippets/init}}
5+
final query = "the query";
6+
final optionalWords = ["the", "query"];
7+
final searchParams = SearchParamsObject(
8+
query: query,
9+
optionalWords: optionalWords,
10+
);
11+
await {{#dynamicSnippet}}searchWithSearchParams{{/dynamicSnippet}};
12+
}

0 commit comments

Comments
 (0)