@@ -477,6 +477,51 @@ public void Text()
477477 result . Title . Should ( ) . Be ( "Declaration of Independence" ) ;
478478 }
479479
480+ [ Theory ]
481+ [ InlineData ( "automobile" , "transportSynonyms" , "Blue Car" ) ]
482+ [ InlineData ( "boat" , "transportSynonyms" , "And the Ship Sails On" ) ]
483+ public void TextWithSynonymsReturnsCorrectResult ( string query , string synonym , string expected )
484+ {
485+ var sortDefinition = Builders < Movie > . Sort . Ascending ( x => x . Title ) ;
486+ var result =
487+ GetSynonymTestCollection ( ) . Aggregate ( )
488+ . Search ( Builders < Movie > . Search . Text ( x => x . Title , query , synonym ) , indexName : "synonyms-tests" )
489+ . Sort ( sortDefinition )
490+ . Project < Movie > ( Builders < Movie > . Projection . Include ( "Title" ) . Exclude ( "_id" ) )
491+ . Limit ( 1 )
492+ . Single ( ) ;
493+
494+ result . Title . Should ( ) . Be ( expected ) ;
495+ }
496+
497+ [ Fact ]
498+ public void TextWithSynonymsMappings ( )
499+ {
500+ var automobileAndAttireSearchResults = SearchMultipleSynonymMapping (
501+ Builders < Movie > . Search . Text ( x => x . Title , "automobile" , "transportSynonyms" ) ,
502+ Builders < Movie > . Search . Text ( x => x . Title , "attire" , "attireSynonyms" ) ) ;
503+
504+ var vehicleAndDressSearchResults = SearchMultipleSynonymMapping (
505+ Builders < Movie > . Search . Text ( x => x . Title , "vehicle" , "transportSynonyms" ) ,
506+ Builders < Movie > . Search . Text ( x => x . Title , "dress" , "attireSynonyms" ) ) ;
507+
508+ var boatAndHatSearchResults = SearchMultipleSynonymMapping (
509+ Builders < Movie > . Search . Text ( x => x . Title , "boat" , "transportSynonyms" ) ,
510+ Builders < Movie > . Search . Text ( x => x . Title , "hat" , "attireSynonyms" ) ) ;
511+
512+ var vesselAndFedoraSearchResults = SearchMultipleSynonymMapping (
513+ Builders < Movie > . Search . Text ( x => x . Title , "vessel" , "transportSynonyms" ) ,
514+ Builders < Movie > . Search . Text ( x => x . Title , "fedora" , "attireSynonyms" ) ) ;
515+
516+ automobileAndAttireSearchResults . Should ( ) . NotBeNull ( ) ;
517+ vehicleAndDressSearchResults . Should ( ) . NotBeNull ( ) ;
518+ boatAndHatSearchResults . Should ( ) . NotBeNull ( ) ;
519+ vesselAndFedoraSearchResults . Should ( ) . NotBeNull ( ) ;
520+
521+ automobileAndAttireSearchResults . Should ( ) . BeEquivalentTo ( vehicleAndDressSearchResults ) ;
522+ boatAndHatSearchResults . Should ( ) . NotBeEquivalentTo ( vesselAndFedoraSearchResults ) ;
523+ }
524+
480525 [ Fact ]
481526 public void Wildcard ( )
482527 {
@@ -500,9 +545,15 @@ private HistoricalDocument SearchSingle(
500545 fluent = fluent . Project ( projectionDefinition ) ;
501546 }
502547
503- return fluent . Limit ( 1 ) . ToList ( ) . Single ( ) ;
548+ return fluent . Limit ( 1 ) . Single ( ) ;
504549 }
505550
551+ private List < BsonDocument > SearchMultipleSynonymMapping ( params SearchDefinition < Movie > [ ] clauses ) =>
552+ GetSynonymTestCollection ( ) . Aggregate ( )
553+ . Search ( Builders < Movie > . Search . Compound ( ) . Should ( clauses ) , indexName : "synonyms-tests" )
554+ . Project ( Builders < Movie > . Projection . Include ( "Title" ) . Exclude ( "_id" ) )
555+ . ToList ( ) ;
556+
506557 private IMongoCollection < HistoricalDocument > GetTestCollection ( ) => _disposableMongoClient
507558 . GetDatabase ( "sample_training" )
508559 . GetCollection < HistoricalDocument > ( "posts" ) ;
@@ -511,6 +562,10 @@ private IMongoCollection<T> GetTestCollection<T>() => _disposableMongoClient
511562 . GetDatabase ( "sample_training" )
512563 . GetCollection < T > ( "posts" ) ;
513564
565+ private IMongoCollection < Movie > GetSynonymTestCollection ( ) => _disposableMongoClient
566+ . GetDatabase ( "sample_mflix" )
567+ . GetCollection < Movie > ( "movies" ) ;
568+
514569 private IMongoCollection < AirbnbListing > GetGeoTestCollection ( ) => _disposableMongoClient
515570 . GetDatabase ( "sample_airbnb" )
516571 . GetCollection < AirbnbListing > ( "listingsAndReviews" ) ;
@@ -522,6 +577,13 @@ public class Comment
522577 public string Author { get ; set ; }
523578 }
524579
580+ [ BsonIgnoreExtraElements ]
581+ public class Movie
582+ {
583+ [ BsonElement ( "title" ) ]
584+ public string Title { get ; set ; }
585+ }
586+
525587 [ BsonIgnoreExtraElements ]
526588 public class HistoricalDocumentWithCommentsOnly
527589 {
0 commit comments