6
6
*/
7
7
package org .hibernate .search .integrationtest .backend .tck .search .highlight ;
8
8
9
- import static org .assertj .core .api .Assertions .assertThat ;
10
9
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
11
10
import static org .hibernate .search .util .impl .integrationtest .common .assertion .SearchHitsAssert .assertThatHits ;
12
11
import static org .junit .jupiter .api .Assumptions .assumeFalse ;
13
12
import static org .junit .jupiter .api .Assumptions .assumeTrue ;
14
13
15
- import java .time .LocalDate ;
16
14
import java .util .Arrays ;
17
15
import java .util .Collections ;
18
16
import java .util .List ;
22
20
import org .hibernate .search .engine .backend .document .model .dsl .IndexSchemaElement ;
23
21
import org .hibernate .search .engine .backend .document .model .dsl .IndexSchemaObjectField ;
24
22
import org .hibernate .search .engine .backend .types .Highlightable ;
25
- import org .hibernate .search .engine .backend .types .IndexFieldTraits ;
26
- import org .hibernate .search .engine .backend .types .ObjectStructure ;
27
- import org .hibernate .search .engine .backend .types .Projectable ;
28
23
import org .hibernate .search .engine .backend .types .TermVector ;
29
24
import org .hibernate .search .engine .search .highlighter .SearchHighlighter ;
30
25
import org .hibernate .search .engine .search .highlighter .dsl .HighlighterEncoder ;
@@ -54,20 +49,15 @@ abstract class AbstractHighlighterIT {
54
49
public final ExpectedLog4jLog logged = ExpectedLog4jLog .create ();
55
50
56
51
protected static final SimpleMappedIndex <IndexBinding > index = SimpleMappedIndex .of ( IndexBinding ::new );
57
- protected static final SimpleMappedIndex <IndexBinding > matchingIndex = SimpleMappedIndex .of ( IndexBinding ::new )
58
- .name ( "matchingIndex" );
59
- protected static final SimpleMappedIndex <NotMatchingTypeIndexBinding > notMatchingTypeIndex =
52
+ private static final SimpleMappedIndex <NotMatchingTypeIndexBinding > notMatchingTypeIndex =
60
53
SimpleMappedIndex .of ( NotMatchingTypeIndexBinding ::new )
61
54
.name ( "notMatchingTypeIndex" );
62
- protected static final SimpleMappedIndex <NestedIndexBinding > nestedIndex = SimpleMappedIndex .of ( NestedIndexBinding ::new )
63
- .name ( "nestedIndex" );
64
55
65
56
@ BeforeAll
66
57
static void setup () {
67
58
setupHelper .start ().withIndex ( index )
68
- .withIndex ( matchingIndex )
69
59
.withIndex ( notMatchingTypeIndex )
70
- .withIndex ( nestedIndex ). setup ();
60
+ .setup ();
71
61
72
62
index .bulkIndexer ()
73
63
.add ( "1" , d -> d .addValue ( "string" , "some value" ) )
@@ -118,63 +108,12 @@ static void setup() {
118
108
} )
119
109
.add ( "12" , d -> {
120
110
d .addValue ( "stringNoTermVector" , "boo and boo and boo much more times" );
121
- d .addValue ( "stringNotProjectable" , "The quick brown fox jumps right over the little lazy dog" );
122
111
} )
123
112
.join ();
124
-
125
- matchingIndex .bulkIndexer ()
126
- .add ( "100" , d -> d .addValue ( "string" , "string with dog" ) )
127
- .join ();
128
113
}
129
114
130
115
abstract HighlighterOptionsStep <?> highlighter (SearchHighlighterFactory factory );
131
116
132
- @ Test
133
- void highlightable_enabled_trait () {
134
- assertThat ( Arrays .asList ( "string" , "objectFlattened.string" ) )
135
- .allSatisfy ( fieldPath -> assertThat ( index .toApi ().descriptor ().field ( fieldPath ) )
136
- .hasValueSatisfying ( fieldDescriptor -> assertThat ( fieldDescriptor .type ().traits () )
137
- .as ( "traits of field '" + fieldPath + "'" )
138
- .contains ( "projection:highlight" ) ) );
139
- }
140
-
141
- @ Test
142
- void projectable_no_trait () {
143
- String fieldPath = "stringNotProjectable" ;
144
- if ( TckConfiguration .get ().getBackendFeatures ().supportsHighlightableWithoutProjectable () ) {
145
- assertThat ( index .toApi ().descriptor ().field ( fieldPath ) )
146
- .hasValueSatisfying ( fieldDescriptor -> assertThat ( fieldDescriptor .type ().traits () )
147
- .as ( "traits of field '" + fieldPath + "'" )
148
- .contains ( IndexFieldTraits .Projections .HIGHLIGHT ) );
149
- }
150
- else {
151
- assertThat ( index .toApi ().descriptor ().field ( fieldPath ) )
152
- .hasValueSatisfying ( fieldDescriptor -> assertThat ( fieldDescriptor .type ().traits () )
153
- .as ( "traits of field '" + fieldPath + "'" )
154
- .doesNotContain ( IndexFieldTraits .Projections .HIGHLIGHT ) );
155
- }
156
- }
157
-
158
- @ Test
159
- void highlightable_enabled_trait_nested () {
160
- assertThat ( Arrays .asList (
161
- "objectNested.string" ,
162
- "objectNested.level2objectDefault.string" ,
163
- "objectNested.level2objectNested.string" ,
164
- "objectNested.level2objectFlattened.string" ,
165
- "objectDefault.level2objectNested.string" ,
166
- "objectFlattened.level2objectNested.string"
167
- ) )
168
- .allSatisfy ( inObjectFieldPath -> assertThat ( nestedIndex .toApi ().descriptor ().field ( inObjectFieldPath ) )
169
- .hasValueSatisfying ( fieldDescriptor -> assertThat ( fieldDescriptor .type ().traits () )
170
- .as ( "traits of field '" + inObjectFieldPath + "'" )
171
- // See HSEARCH-4841: highlighting is forbidden on nested fields...
172
- // but here we're inspecting the field *type*, which unfortunately
173
- // is independent of the field structure and thus doesn't know
174
- // highlighting is not available.
175
- .contains ( IndexFieldTraits .Projections .HIGHLIGHT ) ) );
176
- }
177
-
178
117
@ Test
179
118
void highlighterNoConfigurationAtAll () {
180
119
StubMappingScope scope = index .createScope ();
@@ -790,67 +729,6 @@ void unknownNamedHighlighter() {
790
729
);
791
730
}
792
731
793
- @ Test
794
- void highlightNonAnalyzedField () {
795
- assertThatThrownBy (
796
- () -> index .createScope ().query ().select (
797
- f -> f .highlight ( "notAnalyzedString" )
798
- ).where ( f -> f .matchAll () )
799
- .toQuery ()
800
- ).isInstanceOf ( SearchException .class )
801
- .hasMessageContainingAll (
802
- "Cannot use 'projection:highlight' on field 'notAnalyzedString':" ,
803
- "Make sure the field is marked as searchable/sortable/projectable/aggregable/highlightable (whichever is relevant)." ,
804
- "If it already is, then 'projection:highlight' is not available for fields of this type."
805
- );
806
- }
807
-
808
- @ Test
809
- void multipleIndexesScopeIncompatibleTypes () {
810
- assertThatThrownBy (
811
- () -> index .createScope ( notMatchingTypeIndex ).query ().select (
812
- f -> f .highlight ( "string" )
813
- ).where ( f -> f .matchAll () )
814
- .toQuery ()
815
- ).isInstanceOf ( SearchException .class )
816
- .hasMessageContainingAll (
817
- "Inconsistent support for 'projection:highlight'" ,
818
- "'projection:highlight' can be used in some of the targeted indexes, but not all of them." ,
819
- "Make sure the field is marked as searchable/sortable/projectable/aggregable/highlightable (whichever is relevant) in all indexes, and that the field has the same type in all indexes"
820
- );
821
- }
822
-
823
- @ Test
824
- void multipleIndexesScopeIncompatibleTypesInObjectField () {
825
- assertThatThrownBy (
826
- () -> index .createScope ( notMatchingTypeIndex ).query ().select (
827
- f -> f .highlight ( "objectFlattened.string" )
828
- ).where ( f -> f .matchAll () )
829
- .toQuery ()
830
- ).isInstanceOf ( SearchException .class )
831
- .hasMessageContainingAll (
832
- "Inconsistent support for 'projection:highlight'" ,
833
- "'projection:highlight' can be used in some of the targeted indexes, but not all of them." ,
834
- "Make sure the field is marked as searchable/sortable/projectable/aggregable/highlightable (whichever is relevant) in all indexes, and that the field has the same type in all indexes."
835
- );
836
- }
837
-
838
- @ Test
839
- void multipleIndexesScopeCompatibleTypes () {
840
- SearchQuery <List <String >> highlights = index .createScope ( matchingIndex ).query ().select (
841
- f -> f .highlight ( "string" )
842
- ).where ( f -> f .match ().field ( "string" ).matching ( "dog" ) )
843
- .highlighter ( h -> highlighter ( h ) )
844
- .toQuery ();
845
-
846
- assertThatHits ( highlights .fetchAllHits () )
847
- .hasHitsAnyOrder ( Arrays .asList (
848
- Collections .singletonList ( "string with <em>dog</em>" ),
849
- Collections .singletonList ( "This string mentions a <em>dog</em>" ),
850
- Collections .singletonList ( "This string mentions a <em>dog</em> too" )
851
- ) );
852
- }
853
-
854
732
@ Test
855
733
void prebuiltHighlighter () {
856
734
SearchHighlighter highlighter = highlighter ( index .createScope ().highlighter () ).tag ( "---" , "---" )
@@ -908,36 +786,6 @@ void prebuiltHighlighterWrongScope() {
908
786
);
909
787
}
910
788
911
- @ Test
912
- void inObjectProjection () {
913
- List <String > objects = Arrays .asList ( "objectDefault" , "objectFlattened" );
914
- for ( String object : objects ) {
915
- for ( String level2 : objects ) {
916
- assertThatThrownBy ( () -> nestedIndex .query ().select (
917
- f -> f .object ( object )
918
- .from (
919
- f .composite ().from (
920
- f .field ( object + ".string" ),
921
- f .object ( object + ".level2" + level2 )
922
- .from ( f .highlight ( object + ".level2" + level2 + ".string" ) )
923
- .asList ()
924
- ).asList ()
925
- )
926
- .asList ()
927
- )
928
- .where ( f -> f .matchAll () )
929
- .toQuery () )
930
- .as ( object )
931
- .isInstanceOf ( SearchException .class )
932
- .hasMessageContainingAll (
933
- "Highlight projection cannot be applied within nested context of" ,
934
- object ,
935
- level2
936
- );
937
- }
938
- }
939
- }
940
-
941
789
@ Test
942
790
void phraseMatching () {
943
791
SearchQuery <List <String >> highlights = index .createScope ().query ().select (
@@ -971,7 +819,7 @@ private List<List<String>> phraseMatchingResult() {
971
819
}
972
820
}
973
821
974
- private static class IndexBinding {
822
+ protected static class IndexBinding {
975
823
final IndexFieldReference <String > stringField ;
976
824
final IndexFieldReference <String > anotherStringField ;
977
825
final IndexFieldReference <String > objectFlattenedString ;
@@ -980,7 +828,6 @@ private static class IndexBinding {
980
828
final IndexObjectFieldReference objectFlattened ;
981
829
final IndexFieldReference <String > stringNoTermVectorField ;
982
830
final IndexFieldReference <Integer > intField ;
983
- final IndexFieldReference <String > stringNotProjectableField ;
984
831
985
832
IndexBinding (IndexSchemaElement root ) {
986
833
stringField = root .field ( "string" , f -> f .asString ()
@@ -1016,66 +863,14 @@ private static class IndexBinding {
1016
863
).toReference ();
1017
864
1018
865
intField = root .field ( "int" , f -> f .asInteger () ).toReference ();
1019
-
1020
- stringNotProjectableField = root .field ( "stringNotProjectable" , f -> f .asString ()
1021
- .analyzer ( DefaultAnalysisDefinitions .ANALYZER_STANDARD_ENGLISH .name )
1022
- ).toReference ();
1023
- }
1024
- }
1025
-
1026
- private static class NestedIndexBinding {
1027
-
1028
- NestedIndexBinding (IndexSchemaElement root ) {
1029
- createObjects ( "" , root , 2 , true );
1030
- }
1031
-
1032
- private void createObjects (String prefix , IndexSchemaElement element , int level , boolean addNested ) {
1033
- IndexSchemaObjectField objectDefault = element .objectField ( prefix + "objectDefault" );
1034
-
1035
- createString ( "string" , objectDefault );
1036
- if ( addNested ) {
1037
- createObjects ( "level" + ( level ), objectDefault , level + 1 , false );
1038
- }
1039
- objectDefault .toReference ();
1040
-
1041
- IndexSchemaObjectField objectNested = element .objectField ( prefix + "objectNested" , ObjectStructure .NESTED );
1042
- createString ( "string" , objectNested );
1043
- if ( addNested ) {
1044
- createObjects ( "level" + ( level ), objectNested , level + 1 , false );
1045
- }
1046
- objectNested .toReference ();
1047
-
1048
- IndexSchemaObjectField objectFlattened =
1049
- element .objectField ( prefix + "objectFlattened" , ObjectStructure .FLATTENED );
1050
- createString ( "string" , objectFlattened );
1051
- if ( addNested ) {
1052
- createObjects ( "level" + ( level ), objectFlattened , level + 1 , false );
1053
- }
1054
- objectFlattened .toReference ();
1055
- }
1056
-
1057
- private IndexFieldReference <String > createString (String name , IndexSchemaObjectField objectField ) {
1058
- return objectField .field ( name , f -> f .asString ()
1059
- .highlightable ( Arrays .asList ( Highlightable .UNIFIED , Highlightable .PLAIN ) )
1060
- .analyzer ( DefaultAnalysisDefinitions .ANALYZER_STANDARD_ENGLISH .name )
1061
- ).toReference ();
1062
866
}
1063
867
}
1064
868
1065
869
private static class NotMatchingTypeIndexBinding {
1066
870
final IndexFieldReference <Integer > stringField ;
1067
- final IndexObjectFieldReference nested ;
1068
- final IndexFieldReference <LocalDate > objectFlattenedString ;
1069
871
1070
872
NotMatchingTypeIndexBinding (IndexSchemaElement root ) {
1071
873
stringField = root .field ( "string" , f -> f .asInteger () ).toReference ();
1072
-
1073
- IndexSchemaObjectField objectField = root .objectField ( "objectFlattened" );
1074
- nested = objectField .toReference ();
1075
-
1076
- objectFlattenedString = objectField .field ( "string" , f -> f .asLocalDate ()
1077
- .projectable ( Projectable .YES )
1078
- ).toReference ();
1079
874
}
1080
875
}
1081
876
}
0 commit comments