Skip to content

Commit 5a3979e

Browse files
committed
chore(docs): dynamic filtring snippets
1 parent a89c524 commit 5a3979e

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package documentation.guides.rule
2+
3+
import com.algolia.search.model.Attribute
4+
import com.algolia.search.model.ObjectID
5+
import com.algolia.search.model.rule.Anchoring
6+
import com.algolia.search.model.rule.AutomaticFacetFilters
7+
import com.algolia.search.model.rule.Condition
8+
import com.algolia.search.model.rule.Consequence
9+
import com.algolia.search.model.rule.Edit
10+
import com.algolia.search.model.rule.Pattern
11+
import com.algolia.search.model.rule.Rule
12+
import com.algolia.search.model.search.Query
13+
import documentation.index
14+
import runBlocking
15+
import kotlin.test.Ignore
16+
17+
@Ignore
18+
class GuideDynamicFiltring {
19+
20+
/** API filter rule example **/
21+
fun snippet1() {
22+
runBlocking {
23+
val rule = Rule(
24+
objectID = ObjectID("red-color"),
25+
conditions = listOf(
26+
Condition(anchoring = Anchoring.Contains, pattern = Pattern.Literal("red"))
27+
),
28+
consequence = Consequence(
29+
query = Query(filters = "color:red"),
30+
edits = listOf(Edit(delete = "read"))
31+
)
32+
)
33+
34+
index.saveRule(rule)
35+
}
36+
}
37+
38+
/** API facet rule example **/
39+
fun snippet2() {
40+
runBlocking {
41+
val rule = Rule(
42+
objectID = ObjectID("color-facets"),
43+
conditions = listOf(
44+
Condition(
45+
anchoring = Anchoring.Contains,
46+
pattern = Pattern.Literal("{facet:color}")
47+
)
48+
),
49+
consequence = Consequence(
50+
automaticFacetFilters = listOf(
51+
AutomaticFacetFilters(attribute = Attribute("color"))
52+
)
53+
)
54+
)
55+
56+
index.saveRule(rule)
57+
}
58+
}
59+
60+
/** API filter by type **/
61+
fun snippet3() {
62+
runBlocking {
63+
val rule = Rule(
64+
objectID = ObjectID("t-shirt"),
65+
conditions = listOf(
66+
Condition(
67+
anchoring = Anchoring.Contains,
68+
pattern = Pattern.Literal("t-shirt")
69+
)
70+
),
71+
consequence = Consequence(
72+
edits = listOf(Edit(delete = "t-shirt")),
73+
query = Query(filters = "clothing_type:shirt")
74+
)
75+
)
76+
77+
index.saveRule(rule)
78+
}
79+
}
80+
81+
/** API numerical filtering **/
82+
fun snippet4() {
83+
runBlocking {
84+
val toasterRule = Rule(
85+
objectID = ObjectID("toaster"),
86+
conditions = listOf(
87+
Condition(anchoring = Anchoring.Contains, pattern = Pattern.Literal("toaster"))
88+
),
89+
consequence = Consequence(
90+
query = Query(filters = "product_type:toaster"),
91+
edits = listOf(Edit(delete = "toaster"))
92+
)
93+
)
94+
95+
val cheapRule = Rule(
96+
objectID = ObjectID("cheap"),
97+
conditions = listOf(
98+
Condition(anchoring = Anchoring.Contains, pattern = Pattern.Literal("cheap"))
99+
),
100+
consequence = Consequence(
101+
query = Query(filters = "price < 10"),
102+
edits = listOf(Edit(delete = "cheap"))
103+
)
104+
)
105+
106+
index.saveRules(listOf(toasterRule, cheapRule))
107+
}
108+
}
109+
}

0 commit comments

Comments
 (0)