Skip to content

Commit e0939bd

Browse files
committed
chore(docs): add optional filters guide snippets
1 parent b4c1f5c commit e0939bd

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package documentation.guides.rule
2+
3+
import com.algolia.search.dsl.attributesForFaceting
4+
import com.algolia.search.dsl.optionalFilters
5+
import com.algolia.search.dsl.query
6+
import com.algolia.search.dsl.settings
7+
import documentation.index
8+
import runBlocking
9+
import kotlin.test.Ignore
10+
11+
@Ignore
12+
class GuideOptionalFilters {
13+
14+
/** Optional filter **/
15+
fun snippet1() {
16+
runBlocking {
17+
val query = query("phone") {
18+
optionalFilters {
19+
and {
20+
facet("brand", "Apple", score = 3)
21+
facet("brand", "Samsung", score = 2)
22+
facet("brand", "-Huawei")
23+
}
24+
}
25+
}
26+
index.search(query = query)
27+
}
28+
}
29+
30+
/** Filter score **/
31+
fun snippet2() {
32+
runBlocking {
33+
val query = query {
34+
optionalFilters {
35+
and {
36+
facet("brand", "Apple", score = 2)
37+
facet("type", "tablet")
38+
}
39+
}
40+
}
41+
index.search(query = query)
42+
}
43+
}
44+
45+
/** Filter only faceting **/
46+
fun snippets3() {
47+
runBlocking {
48+
val settings = settings {
49+
attributesForFaceting {
50+
+"filterOnly(brand)"
51+
}
52+
}
53+
index.setSettings(settings)
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)