@@ -604,13 +604,13 @@ public MatchResult match(
604604 }
605605 }
606606
607- class MatchOnlyTextMatcher implements FieldSpecificMatcher {
607+ class TextMatcher implements FieldSpecificMatcher {
608608 private final XContentBuilder actualMappings ;
609609 private final Settings .Builder actualSettings ;
610610 private final XContentBuilder expectedMappings ;
611611 private final Settings .Builder expectedSettings ;
612612
613- MatchOnlyTextMatcher (
613+ TextMatcher (
614614 XContentBuilder actualMappings ,
615615 Settings .Builder actualSettings ,
616616 XContentBuilder expectedMappings ,
@@ -622,6 +622,10 @@ class MatchOnlyTextMatcher implements FieldSpecificMatcher {
622622 this .expectedSettings = expectedSettings ;
623623 }
624624
625+ public String type () {
626+ return "text" ;
627+ }
628+
625629 @ Override
626630 @ SuppressWarnings ("unchecked" )
627631 public MatchResult match (
@@ -633,11 +637,13 @@ public MatchResult match(
633637 var expectedNormalized = normalize (expected );
634638 var actualNormalized = normalize (actual );
635639
636- // Match simply as match_only_text first.
640+ // Match simply as text first.
637641 if (actualNormalized .equals (expectedNormalized )) {
638642 return MatchResult .match ();
639643 }
640- //
644+
645+ // In some cases synthetic source for text fields is synthesized using the keyword multi field.
646+ // So in this case it's appropriate to match it using keyword matching logic (mainly to cover `null_value`).
641647 var multiFields = (Map <String , Object >) getMappingParameter ("fields" , actualMapping , expectedMapping );
642648 if (multiFields != null ) {
643649 var keywordMatcher = new KeywordMatcher (actualMappings , actualSettings , expectedMappings , expectedSettings );
@@ -655,7 +661,7 @@ public MatchResult match(
655661 actualSettings ,
656662 expectedMappings ,
657663 expectedSettings ,
658- "Values of type [match_only_text ] don't match, " + prettyPrintCollections (actual , expected )
664+ "Values of type [" + type () + " ] don't match, " + prettyPrintCollections (actual , expected )
659665 )
660666 );
661667 }
@@ -669,70 +675,19 @@ private Set<Object> normalize(List<Object> values) {
669675 }
670676 }
671677
672- class TextMatcher implements FieldSpecificMatcher {
673- private final XContentBuilder actualMappings ;
674- private final Settings .Builder actualSettings ;
675- private final XContentBuilder expectedMappings ;
676- private final Settings .Builder expectedSettings ;
677-
678- TextMatcher (
678+ class MatchOnlyTextMatcher extends TextMatcher {
679+ MatchOnlyTextMatcher (
679680 XContentBuilder actualMappings ,
680681 Settings .Builder actualSettings ,
681682 XContentBuilder expectedMappings ,
682683 Settings .Builder expectedSettings
683684 ) {
684- this .actualMappings = actualMappings ;
685- this .actualSettings = actualSettings ;
686- this .expectedMappings = expectedMappings ;
687- this .expectedSettings = expectedSettings ;
685+ super (actualMappings , actualSettings , expectedMappings , expectedSettings );
688686 }
689687
690688 @ Override
691- @ SuppressWarnings ("unchecked" )
692- public MatchResult match (
693- List <Object > actual ,
694- List <Object > expected ,
695- Map <String , Object > actualMapping ,
696- Map <String , Object > expectedMapping
697- ) {
698- var expectedNormalized = normalize (expected );
699- var actualNormalized = normalize (actual );
700-
701- // Match simply as text first.
702- if (actualNormalized .equals (expectedNormalized )) {
703- return MatchResult .match ();
704- }
705-
706- // In some cases synthetic source for text fields is synthesized using the keyword multi field.
707- // So in this case it's appropriate to match it using keyword matching logic (mainly to cover `null_value`).
708- var multiFields = (Map <String , Object >) getMappingParameter ("fields" , actualMapping , expectedMapping );
709- if (multiFields != null ) {
710- var keywordMatcher = new KeywordMatcher (actualMappings , actualSettings , expectedMappings , expectedSettings );
711-
712- var keywordFieldMapping = (Map <String , Object >) multiFields .get ("subfield_keyword" );
713- var keywordMatchResult = keywordMatcher .match (actual , expected , keywordFieldMapping , keywordFieldMapping );
714- if (keywordMatchResult .isMatch ()) {
715- return MatchResult .match ();
716- }
717- }
718-
719- return MatchResult .noMatch (
720- formatErrorMessage (
721- actualMappings ,
722- actualSettings ,
723- expectedMappings ,
724- expectedSettings ,
725- "Values of type [text] don't match, " + prettyPrintCollections (actual , expected )
726- )
727- );
728- }
729-
730- private Set <Object > normalize (List <Object > values ) {
731- if (values == null ) {
732- return Set .of ();
733- }
734-
735- return values .stream ().filter (Objects ::nonNull ).collect (Collectors .toSet ());
689+ public String type () {
690+ return "match_only_text" ;
736691 }
737692 }
738693
0 commit comments