Skip to content

Commit 4eabf95

Browse files
committed
Update comments
1 parent 868d179 commit 4eabf95

3 files changed

Lines changed: 12 additions & 17 deletions

File tree

mflix/server/java-spring/src/main/java/com/mongodb/samplemflix/service/MovieServiceImpl.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,7 @@ public List<Movie> searchMovies(MovieSearchRequest searchRequest) {
638638
// Use compound operator with "should" clauses to create a scoring hierarchy:
639639
// 1. phrase match (highest score) - exact phrase in same array element
640640
// 2. text match without fuzzy (high score) - all terms present, exact spelling
641-
// 3. text match with fuzzy (lower score) - typo-tolerant fallback
642-
// This ensures "James Cameron" ranks higher than "James Mangold" + "Cameron Crowe"
643-
// while still supporting typo tolerance.
641+
// 3. text match with fuzzy (lower score) - typo-tolerant fallback; update fuzzy settings as needed
644642
// For more details, see: https://www.mongodb.com/docs/atlas/atlas-search/operators-collectors/text/
645643
if (searchRequest.getDirectors() != null && !searchRequest.getDirectors().trim().isEmpty()) {
646644
String directorsQuery = searchRequest.getDirectors().trim();
@@ -660,6 +658,7 @@ public List<Movie> searchMovies(MovieSearchRequest searchRequest) {
660658
.append("query", directorsQuery)
661659
.append("path", Movie.Fields.DIRECTORS)
662660
.append("matchCriteria", "all")
661+
// Fuzzy settings: allow up to 1 edit, require first 2 characters to match
663662
.append("fuzzy", new Document()
664663
.append("maxEdits", 1)
665664
.append("prefixLength", 2)))
@@ -668,7 +667,7 @@ public List<Movie> searchMovies(MovieSearchRequest searchRequest) {
668667
));
669668
}
670669

671-
// Add writers search if provided (see directors comments for compound should scoring hierarchy)
670+
// Add writers search if provided (see directors comments for compound scoring hierarchy)
672671
if (searchRequest.getWriters() != null && !searchRequest.getWriters().trim().isEmpty()) {
673672
String writersQuery = searchRequest.getWriters().trim();
674673
searchPhrases.add(new Document("compound", new Document()
@@ -692,7 +691,7 @@ public List<Movie> searchMovies(MovieSearchRequest searchRequest) {
692691
));
693692
}
694693

695-
// Add cast search if provided (see directors comments for compound should scoring hierarchy)
694+
// Add cast search if provided (see directors comments for compound scoring hierarchy)
696695
if (searchRequest.getCast() != null && !searchRequest.getCast().trim().isEmpty()) {
697696
String castQuery = searchRequest.getCast().trim();
698697
searchPhrases.add(new Document("compound", new Document()

mflix/server/js-express/src/controllers/movieController.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,7 @@ export async function searchMovies(req: Request, res: Response): Promise<void> {
581581
// Use compound operator with "should" clauses to create a scoring hierarchy:
582582
// 1. phrase match (highest score) - exact phrase in same array element
583583
// 2. text match without fuzzy (high score) - all terms present, exact spelling
584-
// 3. text match with fuzzy (lower score) - typo-tolerant fallback
585-
// This ensures "James Cameron" ranks higher than "James Mangold" + "Cameron Crowe"
586-
// while still supporting typo tolerance.
584+
// 3. text match with fuzzy (lower score) - typo-tolerant fallback; update fuzzy settings as needed
587585
// For more details, see: https://www.mongodb.com/docs/atlas/atlas-search/operators-collectors/text/
588586
if (directors) {
589587
searchPhrases.push({
@@ -599,7 +597,7 @@ export async function searchMovies(req: Request, res: Response): Promise<void> {
599597
query: directors,
600598
path: "directors",
601599
matchCriteria: "all",
602-
fuzzy: { maxEdits: 1, prefixLength: 2 },
600+
fuzzy: { maxEdits: 1, prefixLength: 2 }, // Allow up to 1 edit, require first 2 characters to match
603601
},
604602
},
605603
],
@@ -609,7 +607,7 @@ export async function searchMovies(req: Request, res: Response): Promise<void> {
609607
}
610608

611609
if (writers) {
612-
// See comments above regarding compound should scoring hierarchy.
610+
// See comments above regarding compound scoring hierarchy.
613611
searchPhrases.push({
614612
compound: {
615613
should: [
@@ -630,7 +628,7 @@ export async function searchMovies(req: Request, res: Response): Promise<void> {
630628
}
631629

632630
if (cast) {
633-
// See comments above regarding compound should scoring hierarchy.
631+
// See comments above regarding compound scoring hierarchy.
634632
searchPhrases.push({
635633
compound: {
636634
should: [

mflix/server/python-fastapi/src/routers/movies.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ async def search_movies(
157157
# Use compound operator with "should" clauses to create a scoring hierarchy:
158158
# 1. phrase match (highest score) - exact phrase in same array element
159159
# 2. text match without fuzzy (high score) - all terms present, exact spelling
160-
# 3. text match with fuzzy (lower score) - typo-tolerant fallback
161-
# This ensures "James Cameron" ranks higher than "James Mangold" + "Cameron Crowe"
162-
# while still supporting typo tolerance.
160+
# 3. text match with fuzzy (lower score) - typo-tolerant fallback; update fuzzy settings as needed
163161
# For more details, see: https://www.mongodb.com/docs/atlas/atlas-search/operators-collectors/text/
164162
search_phrases.append({
165163
"compound": {
@@ -170,14 +168,14 @@ async def search_movies(
170168
{"text": {"query": directors, "path": "directors", "matchCriteria": "all"}},
171169
# Lower score: fuzzy match (typo tolerance)
172170
{"text": {"query": directors, "path": "directors", "matchCriteria": "all",
173-
"fuzzy": {"maxEdits": 1, "prefixLength": 2}}}
171+
"fuzzy": {"maxEdits": 1, "prefixLength": 2}}} # Allow up to 1 edit, require first 2 characters to match
174172
],
175173
"minimumShouldMatch": 1
176174
}
177175
})
178176

179177
if writers is not None:
180-
# See comments above regarding compound should scoring hierarchy.
178+
# See comments above regarding compound scoring hierarchy.
181179
search_phrases.append({
182180
"compound": {
183181
"should": [
@@ -191,7 +189,7 @@ async def search_movies(
191189
})
192190

193191
if cast is not None:
194-
# See comments above regarding compound should scoring hierarchy.
192+
# See comments above regarding compound scoring hierarchy.
195193
search_phrases.append({
196194
"compound": {
197195
"should": [

0 commit comments

Comments
 (0)