Skip to content

Commit 482806c

Browse files
authored
Update CompoundBoostMultiQuery.kt
1 parent caf533a commit 482806c

File tree

1 file changed

+48
-43
lines changed

1 file changed

+48
-43
lines changed

source/examples/atlas-examples/CompoundBoostMultiQuery.kt

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import com.mongodb.client.model.Aggregates.limit
22
import com.mongodb.client.model.Aggregates.project
3-
import com.mongodb.client.model.Filters.eq
43
import com.mongodb.client.model.Projections.*
54
import com.mongodb.kotlin.client.coroutine.MongoClient
65
import kotlinx.coroutines.runBlocking
@@ -10,60 +9,66 @@ fun main() {
109
val uri = "<connection string>"
1110
val mongoClient = MongoClient.create(uri)
1211

13-
val database = mongoClient.getDatabase("local_school_district")
14-
val collection = database.getCollection<Document>("schools")
12+
val database = mongoClient.getDatabase("sample_mflix")
13+
val collection = database.getCollection<Document>("movies")
1514

1615
runBlocking {
17-
val agg = Document("index", "compound-query-custom-score-tutorial")
18-
.append(
19-
"must", listOf(
16+
val agg = Document(
17+
"\$search",
18+
Document("index", "compound-query-custom-score-tutorial")
19+
.append(
20+
"compound",
2021
Document(
21-
"text",
22-
Document("path", "genres")
23-
.append("query", "comedy")
24-
.append(
25-
"score",
26-
Document(
27-
"boost",
28-
Document("value", 9)
29-
)
30-
)
31-
),
32-
Document(
33-
"text",
34-
Document("path", "title")
35-
.append("query", "snow")
36-
.append(
37-
"score",
38-
Document(
39-
"boost",
40-
Document("value", 5)
41-
)
22+
"must", listOf(
23+
Document(
24+
"text",
25+
Document("path", "genres")
26+
.append("query", "comedy")
27+
.append(
28+
"score",
29+
Document(
30+
"boost",
31+
Document("value", 9)
32+
)
33+
)
34+
),
35+
Document(
36+
"text",
37+
Document("path", "title")
38+
.append("query", "snow")
39+
.append(
40+
"score",
41+
Document(
42+
"boost",
43+
Document("value", 5)
44+
)
45+
)
4246
)
47+
)
4348
)
44-
)
45-
)
46-
.append(
47-
"should", listOf(
48-
Document(
49-
"range",
50-
Document("path", "year")
51-
.append("gte", 2013)
52-
.append("lte", 2015)
53-
.append(
54-
"score",
49+
.append(
50+
"should", listOf(
5551
Document(
56-
"boost",
57-
Document("value", 3)
52+
"range",
53+
Document("path", "year")
54+
.append("gte", 2013)
55+
.append("lte", 2015)
56+
.append(
57+
"score",
58+
Document(
59+
"boost",
60+
Document("value", 3)
61+
)
62+
)
5863
)
5964
)
60-
)
65+
)
6166
)
62-
)
67+
)
6368

6469
val resultsFlow = collection.aggregate<Document>(
6570
listOf(
66-
eq("\$search", eq("compound", agg)),
71+
agg,
6772
limit(10),
6873
project(fields(
6974
excludeId(),

0 commit comments

Comments
 (0)