@@ -581,6 +581,74 @@ void near() {
581
581
);
582
582
}
583
583
584
+ @ Test
585
+ void phrase () {
586
+ assertAll (
587
+ () -> assertThrows (IllegalArgumentException .class , () ->
588
+ // queries must not be empty
589
+ SearchOperator .phrase (singleton (fieldPath ("fieldName" )), emptyList ())
590
+ ),
591
+ () -> assertThrows (IllegalArgumentException .class , () ->
592
+ // paths must not be empty
593
+ SearchOperator .phrase (emptyList (), singleton ("term" ))
594
+ ),
595
+ () -> assertEquals (
596
+ new BsonDocument ("phrase" ,
597
+ new BsonDocument ("path" , fieldPath ("fieldName" ).toBsonValue ())
598
+ .append ("query" , new BsonString ("term" ))
599
+ ),
600
+ SearchOperator .phrase (
601
+ fieldPath ("fieldName" ),
602
+ "term" )
603
+ .toBsonDocument ()
604
+ ),
605
+ () -> assertEquals (
606
+ new BsonDocument ("phrase" ,
607
+ new BsonDocument ("path" , new BsonArray (asList (
608
+ fieldPath ("fieldName" ).toBsonValue (),
609
+ wildcardPath ("wildc*rd" ).toBsonValue ())))
610
+ .append ("query" , new BsonArray (asList (
611
+ new BsonString ("term1" ),
612
+ new BsonString ("term2" ))))
613
+ ),
614
+ SearchOperator .phrase (
615
+ asList (
616
+ fieldPath ("fieldName" ),
617
+ wildcardPath ("wildc*rd" )),
618
+ asList (
619
+ "term1" ,
620
+ "term2" ))
621
+ .toBsonDocument ()
622
+ ),
623
+ () -> assertEquals (
624
+ new BsonDocument ("phrase" ,
625
+ new BsonDocument ("path" , fieldPath ("fieldName" ).toBsonValue ())
626
+ .append ("query" , new BsonString ("term" ))
627
+ .append ("synonyms" , new BsonString ("synonymMappingName" ))
628
+ ),
629
+ SearchOperator .phrase (
630
+ singleton (fieldPath ("fieldName" )),
631
+ singleton ("term" ))
632
+ .synonyms ("synonymMappingName" )
633
+ .toBsonDocument ()
634
+ ),
635
+ () -> assertEquals (
636
+ new BsonDocument ("phrase" ,
637
+ new BsonDocument ("path" , fieldPath ("fieldName" ).toBsonValue ())
638
+ .append ("query" , new BsonString ("term" ))
639
+ .append ("synonyms" , new BsonString ("synonymMappingName" ))
640
+ .append ("slop" , new BsonInt32 (5 ))
641
+ ),
642
+ SearchOperator .phrase (
643
+ singleton (fieldPath ("fieldName" )),
644
+ singleton ("term" ))
645
+ .synonyms ("synonymMappingName" )
646
+ .slop (5 )
647
+ .toBsonDocument ()
648
+ )
649
+ );
650
+ }
651
+
584
652
private static SearchOperator docExamplePredefined () {
585
653
return SearchOperator .exists (
586
654
fieldPath ("fieldName" ));
0 commit comments