@@ -43,24 +43,41 @@ private static void runAtlasTextSearch(MongoCollection<Document> collection) {
43
43
SearchPath .fieldPath ("title" ), "Future" ));
44
44
// end atlasTextSearch
45
45
46
- Bson projection = Aggregates .project (Projections .fields (Projections .include ("title" , "released" )));
46
+ // To condense result data, add this projection into the pipeline
47
+ // Bson projection = Aggregates.project(Projections.fields(Projections.include("title", "released")));
47
48
48
- List <Bson > aggregateStages = Arrays .asList (textSearch , projection );
49
+ List <Bson > aggregateStages = Arrays .asList (textSearch );
49
50
System .out .println ("aggregateStages: " + aggregateStages );
50
51
51
52
System .out .println ("explain:\n " + collection .aggregate (aggregateStages ).explain ());
52
53
collection .aggregate (aggregateStages ).forEach (result -> System .out .println (result ));
53
54
}
54
55
56
+ private static void runAtlasTextSearchMeta (MongoCollection <Document > collection ) {
57
+ Bson textSearchMeta =
58
+ // begin atlasSearchMeta
59
+ Aggregates .searchMeta (
60
+ SearchOperator .near (2010 , 1 , SearchPath .fieldPath ("year" )));
61
+ // end atlasSearchMeta
62
+
63
+ List <Bson > aggregateStages = Arrays .asList (textSearchMeta );
64
+ System .out .println ("aggregateStages: " + aggregateStages );
65
+
66
+ collection .aggregate (aggregateStages ).forEach (result -> System .out .println (result ));
67
+ }
68
+
55
69
public static void main (String [] args ) {
56
70
String uri = CONNECTION_URI ;
57
71
58
72
try (MongoClient mongoClient = MongoClients .create (uri )) {
59
73
MongoDatabase database = mongoClient .getDatabase ("sample_mflix" );
60
74
MongoCollection <Document > collection = database .getCollection ("movies" );
61
75
76
+
77
+ // Uncomment the methods that correspond to what you're testing
62
78
// runMatch(collection);
63
- runAtlasTextSearch (collection );
79
+ // runAtlasTextSearch(collection);
80
+ runAtlasTextSearchMeta (collection );
64
81
}
65
82
}
66
83
}
0 commit comments