27
27
/**
28
28
* Tests for the NeuralHighlighterEngine class
29
29
*/
30
- public class NeuralHighlighterManagerTests extends OpenSearchTestCase {
30
+ public class NeuralHighlighterEngineTests extends OpenSearchTestCase {
31
31
32
32
private static final String TEST_FIELD = "test_field" ;
33
33
private static final String MODEL_ID = "test_model_id" ;
34
34
private static final String TEST_CONTENT = "This is a test content. For highlighting purposes. With multiple sentences." ;
35
35
private static final String TEST_QUERY = "test content" ;
36
36
37
- private NeuralHighlighterEngine manager ;
37
+ private NeuralHighlighterEngine highlighterEngine ;
38
38
private MLCommonsClientAccessor mlCommonsClientAccessor ;
39
39
40
40
@ Override
41
41
public void setUp () throws Exception {
42
42
super .setUp ();
43
43
mlCommonsClientAccessor = mock (MLCommonsClientAccessor .class );
44
- manager = new NeuralHighlighterEngine (mlCommonsClientAccessor );
44
+ highlighterEngine = new NeuralHighlighterEngine (mlCommonsClientAccessor );
45
45
46
46
// Setup default mock behavior
47
47
setupDefaultMockBehavior ();
@@ -75,22 +75,22 @@ public void testGetModelId() {
75
75
Map <String , Object > options = new HashMap <>();
76
76
options .put ("model_id" , MODEL_ID );
77
77
78
- String modelId = manager .getModelId (options );
78
+ String modelId = highlighterEngine .getModelId (options );
79
79
assertEquals ("Should extract model ID correctly" , MODEL_ID , modelId );
80
80
}
81
81
82
82
public void testGetModelIdMissing () {
83
83
Map <String , Object > options = new HashMap <>();
84
84
85
- IllegalArgumentException exception = expectThrows (IllegalArgumentException .class , () -> manager .getModelId (options ));
85
+ IllegalArgumentException exception = expectThrows (IllegalArgumentException .class , () -> highlighterEngine .getModelId (options ));
86
86
assertNotNull (exception );
87
87
assertTrue (exception .getMessage ().contains ("Missing required option: model_id" ));
88
88
}
89
89
90
90
public void testExtractOriginalQuery () {
91
91
// Test with TermQuery
92
92
TermQuery termQuery = new TermQuery (new Term (TEST_FIELD , "term" ));
93
- String queryText = manager .extractOriginalQuery (termQuery , TEST_FIELD );
93
+ String queryText = highlighterEngine .extractOriginalQuery (termQuery , TEST_FIELD );
94
94
assertEquals ("Should extract term text" , "term" , queryText );
95
95
96
96
// Test with BooleanQuery
@@ -99,19 +99,19 @@ public void testExtractOriginalQuery() {
99
99
builder .add (new TermQuery (new Term (TEST_FIELD , "term2" )), BooleanClause .Occur .MUST );
100
100
BooleanQuery booleanQuery = builder .build ();
101
101
102
- queryText = manager .extractOriginalQuery (booleanQuery , TEST_FIELD );
102
+ queryText = highlighterEngine .extractOriginalQuery (booleanQuery , TEST_FIELD );
103
103
assertEquals ("Should extract combined terms" , "term1 term2" , queryText );
104
104
105
105
// Test with NeuralKNNQuery
106
106
NeuralKNNQuery neuralQuery = mock (NeuralKNNQuery .class );
107
107
when (neuralQuery .getOriginalQueryText ()).thenReturn ("neural query" );
108
108
109
- queryText = manager .extractOriginalQuery (neuralQuery , TEST_FIELD );
109
+ queryText = highlighterEngine .extractOriginalQuery (neuralQuery , TEST_FIELD );
110
110
assertEquals ("Should extract neural query text" , "neural query" , queryText );
111
111
}
112
112
113
113
public void testGetHighlightedSentences () {
114
- String result = manager .getHighlightedSentences (MODEL_ID , TEST_QUERY , TEST_CONTENT );
114
+ String result = highlighterEngine .getHighlightedSentences (MODEL_ID , TEST_QUERY , TEST_CONTENT );
115
115
116
116
assertNotNull ("Should return highlighted text" , result );
117
117
assertTrue ("Should contain highlighting tags" , result .contains ("<em>" ) && result .contains ("</em>" ));
@@ -139,7 +139,7 @@ public void testApplyHighlighting() {
139
139
highlights .add (resultMap );
140
140
141
141
String text = "This is a test string" ;
142
- String result = manager .applyHighlighting (text , highlights );
142
+ String result = highlighterEngine .applyHighlighting (text , highlights );
143
143
144
144
assertEquals ("Should apply highlights correctly" , "<em>This</em> is <em>a te</em>st string" , result );
145
145
}
@@ -165,7 +165,7 @@ public void testApplyHighlightingWithOverlaps() {
165
165
highlights .add (resultMap );
166
166
167
167
String text = "This is a test string" ;
168
- String result = manager .applyHighlighting (text , highlights );
168
+ String result = highlighterEngine .applyHighlighting (text , highlights );
169
169
170
170
// Should merge the overlapping highlights
171
171
assertEquals ("Should merge overlapping highlights" , "<em>This is a </em>test string" , result );
@@ -205,7 +205,7 @@ public void testApplyHighlightingWithInvalidPositions() {
205
205
highlights .add (resultMap );
206
206
207
207
String text = "This is a test string" ;
208
- String result = manager .applyHighlighting (text , highlights );
208
+ String result = highlighterEngine .applyHighlighting (text , highlights );
209
209
210
210
// Should only apply the valid highlight
211
211
assertEquals ("Should only apply valid highlights" , "<em>This</em> is a test string" , result );
0 commit comments