Skip to content

Commit 64ea8a8

Browse files
committed
feat(javascript): more guides + better types
1 parent 623dc6a commit 64ea8a8

18 files changed

+114
-13
lines changed

templates/javascript/guides/search/deleteMultipleIndices.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ try {
3131
{{#dynamicSnippet}}deleteMultipleIndicesReplica{{/dynamicSnippet}};
3232
console.log("Deleted replica indices.");
3333
}
34-
} catch (e) {
34+
} catch (e: any) {
3535
console.error(e);
3636
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Condition, Consequence, Rule } from 'algoliasearch';
2+
3+
const condition: Condition = {
4+
anchoring: 'is',
5+
pattern: '{facet:brand}',
6+
}
7+
8+
const consequence: Consequence = {
9+
filterPromotes: true,
10+
}
11+
12+
const rule: Rule = {
13+
enabled: true,
14+
objectID: 'rule_with_filterPromotes',
15+
conditions: [condition],
16+
consequence,
17+
}

templates/javascript/guides/search/saveObjectsChunks.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ try {
1212
const chunk = records.slice(beginIndex, beginIndex + chunkSize);
1313
{{#dynamicSnippet}}saveObjectsChunks{{/dynamicSnippet}}
1414
}
15-
} catch (e) {
15+
} catch (e: any) {
1616
console.error(e);
1717
}

templates/javascript/guides/search/saveObjectsMCM.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Object.keys(configurations).forEach(async (appID) => {
1616
const client = algoliasearch(appID, configurations[appID]);
1717
1818
{{#dynamicSnippet}}saveObjectsPlaylists{{/dynamicSnippet}}
19-
} catch (e) {
19+
} catch (e: any) {
2020
console.error(e);
2121
}
2222
});

templates/javascript/guides/search/saveObjectsModified.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ try {
1717
});
1818

1919
{{#dynamicSnippet}}saveObjectsRecords{{/dynamicSnippet}}
20-
} catch (e) {
20+
} catch (e: any) {
2121
console.error(e);
2222
}

templates/javascript/guides/search/saveObjectsPublicUser.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ try {
66
{{> snippets/init}}
77

88
{{#dynamicSnippet}}saveObjectsPlaylistsWithUserIDPublic{{/dynamicSnippet}}
9-
} catch (e) {
9+
} catch (e: any) {
1010
console.error(e);
1111
}

templates/javascript/guides/search/savePopularRecords.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ try {
1515
});
1616

1717
{{#dynamicSnippet}}saveObjectsRecords{{/dynamicSnippet}}
18-
} catch (e) {
18+
} catch (e: any) {
1919
console.error(e);
2020
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{{> snippets/import}}
2+
3+
try {
4+
{{> snippets/init}}
5+
6+
const query = 'query';
7+
8+
// 1. Change the sort dynamically based on the UI events
9+
const sortByPrice = false;
10+
11+
// 2. Get the index name based on sortByPrice
12+
const indexName = sortByPrice ? 'products_price_desc' : 'products';
13+
14+
// 3. Search on dynamic index name (primary or replica)
15+
{{#dynamicSnippet}}searchWithIndexNameVar{{/dynamicSnippet}};
16+
} catch (e: any) {
17+
console.error(e.message);
18+
}

templates/javascript/guides/search/searchRecentlyPublishedBooks.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ try {
1111
};
1212

1313
{{#dynamicSnippet}}searchWithSearchParams{{/dynamicSnippet}}
14-
} catch (e) {
14+
} catch (e: any) {
1515
console.error(e);
1616
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{{> snippets/import}}
2+
import type { SearchParamsObject } from 'algoliasearch';
3+
4+
5+
try {
6+
{{> snippets/init}}
7+
8+
/*
9+
'94.228.178.246' should be replaced with your user's IP address.
10+
Depending on your stack there are multiple ways to get this information.
11+
*/
12+
const ip = '94.228.178.246';
13+
const query = 'query';
14+
15+
const searchParams: SearchParamsObject = {
16+
query,
17+
analytics: true,
18+
};
19+
20+
{{#dynamicSnippet}}searchWithSearchParamsAndForwardedHeader{{/dynamicSnippet}};
21+
} catch (e: any) {
22+
console.error(e);
23+
}
24+

0 commit comments

Comments
 (0)