Skip to content

Commit fa3acd1

Browse files
committed
feat(dart): more guides
1 parent f886306 commit fa3acd1

7 files changed

+90
-2
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
final rule = Rule(
14+
objectID: "rule_with_filterPromotes",
15+
conditions: [condition],
16+
consequence: consequence
17+
);
18+
}

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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
final indexName = sortByPrice ? "products_price_desc" : "products";
11+
12+
// 3. Search on dynamic index name (primary or replica)
13+
await {{#dynamicSnippet}}searchWithIndexNameVar{{/dynamicSnippet}};
14+
}
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+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{{> snippets/import}}
2+
3+
void useConditionlessRule() async {
4+
{{> snippets/init}}
5+
6+
final objectID = "a-rule-id";
7+
8+
final rule = Rule(
9+
objectID: objectID,
10+
consequence: Consequence(
11+
// Set relevant consequence
12+
),
13+
// Set validity (optional)
14+
validity: [
15+
TimeRange(
16+
from: 1688774400,
17+
until: 1738972800
18+
)
19+
]
20+
);
21+
22+
await {{#dynamicSnippet}}saveRule{{/dynamicSnippet}};
23+
}

0 commit comments

Comments
 (0)