@@ -43,24 +43,41 @@ private static void runAtlasTextSearch(MongoCollection<Document> collection) {
4343 SearchPath .fieldPath ("title" ), "Future" ));
4444 // end atlasTextSearch
4545
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")));
4748
48- List <Bson > aggregateStages = Arrays .asList (textSearch , projection );
49+ List <Bson > aggregateStages = Arrays .asList (textSearch );
4950 System .out .println ("aggregateStages: " + aggregateStages );
5051
5152 System .out .println ("explain:\n " + collection .aggregate (aggregateStages ).explain ());
5253 collection .aggregate (aggregateStages ).forEach (result -> System .out .println (result ));
5354 }
5455
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+
5569 public static void main (String [] args ) {
5670 String uri = CONNECTION_URI ;
5771
5872 try (MongoClient mongoClient = MongoClients .create (uri )) {
5973 MongoDatabase database = mongoClient .getDatabase ("sample_mflix" );
6074 MongoCollection <Document > collection = database .getCollection ("movies" );
6175
76+
77+ // Uncomment the methods that correspond to what you're testing
6278 // runMatch(collection);
63- runAtlasTextSearch (collection );
79+ // runAtlasTextSearch(collection);
80+ runAtlasTextSearchMeta (collection );
6481 }
6582 }
6683}
0 commit comments