@@ -132,7 +132,7 @@ private void testGetContext(boolean limit, boolean hitList)
132
132
// Search freetext for the term "def"
133
133
QueryBuilder qb = new QueryBuilder ().setFreetext ("def" );
134
134
Context c = new Context (qb .build (), qb .getQueries ());
135
- assertTrue (c .getContext (in , out , "" , "" , "" , null , limit , hits ));
135
+ assertTrue (c .getContext (in , out , "" , "" , "" , null , limit , qb . isDefSearch (), hits ));
136
136
137
137
if (hitList ) {
138
138
assertEquals (1 , hits .size ());
@@ -156,7 +156,7 @@ private void testGetContext(boolean limit, boolean hitList)
156
156
hits = hitList ? new ArrayList <Hit >() : null ;
157
157
qb = new QueryBuilder ().setDefs ("def" );
158
158
c = new Context (qb .build (), qb .getQueries ());
159
- assertTrue (c .getContext (in , out , "" , "" , "" , defs , limit , hits ));
159
+ assertTrue (c .getContext (in , out , "" , "" , "" , defs , limit , qb . isDefSearch (), hits ));
160
160
161
161
if (hitList ) {
162
162
assertEquals (1 , hits .size ());
@@ -170,13 +170,30 @@ private void testGetContext(boolean limit, boolean hitList)
170
170
actualOutput = hitList ? hits .get (0 ).getLine () : out .toString ();
171
171
assertEquals (expectedOutput , actualOutput );
172
172
173
+ in = new StringReader ("abc def ghi\n " );
174
+ out = hitList ? null : new StringWriter ();
175
+ hits = hitList ? new ArrayList <Hit >() : null ;
176
+ assertTrue (c .getContext (in , out , "" , "" , "" , null , limit , qb .isDefSearch (), hits ));
177
+
178
+ if (hitList ) {
179
+ assertEquals (0 , hits .size ());
180
+ }
181
+
182
+ expectedOutput = hitList
183
+ ? ""
184
+ : "" ;
185
+ actualOutput = hitList ? "" : out .toString ();
186
+ //test case - if this is def search, don't show false results (defs
187
+ // weren't defined)
188
+ assertEquals (expectedOutput , actualOutput );
189
+
173
190
// Search with no input (will search definitions)
174
191
in = null ;
175
192
out = hitList ? null : new StringWriter ();
176
193
hits = hitList ? new ArrayList <Hit >() : null ;
177
194
qb = new QueryBuilder ().setDefs ("def" );
178
195
c = new Context (qb .build (), qb .getQueries ());
179
- assertTrue (c .getContext (in , out , "" , "" , "" , defs , limit , hits ));
196
+ assertTrue (c .getContext (in , out , "" , "" , "" , defs , limit , qb . isDefSearch (), hits ));
180
197
181
198
if (hitList ) {
182
199
assertEquals (1 , hits .size ());
@@ -196,7 +213,7 @@ private void testGetContext(boolean limit, boolean hitList)
196
213
hits = hitList ? new ArrayList <Hit >() : null ;
197
214
qb = new QueryBuilder ().setFreetext ("no_match" );
198
215
c = new Context (qb .build (), qb .getQueries ());
199
- assertFalse (c .getContext (in , out , "" , "" , "" , null , limit , hits ));
216
+ assertFalse (c .getContext (in , out , "" , "" , "" , null , limit , qb . isDefSearch (), hits ));
200
217
if (hitList ) {
201
218
assertEquals (0 , hits .size ());
202
219
} else {
@@ -209,7 +226,7 @@ private void testGetContext(boolean limit, boolean hitList)
209
226
hits = hitList ? new ArrayList <Hit >() : null ;
210
227
qb = new QueryBuilder ().setHist ("abc" );
211
228
c = new Context (qb .build (), qb .getQueries ());
212
- assertFalse (c .getContext (in , out , "" , "" , "" , null , limit , hits ));
229
+ assertFalse (c .getContext (in , out , "" , "" , "" , null , limit , qb . isDefSearch (), hits ));
213
230
if (hitList ) {
214
231
assertEquals (0 , hits .size ());
215
232
} else {
@@ -235,7 +252,7 @@ public void testLongLineNearBufferBoundary() throws ParseException {
235
252
Context c = new Context (qb .build (), qb .getQueries ());
236
253
StringWriter out = new StringWriter ();
237
254
boolean match =
238
- c .getContext (in , out , "" , "" , "" , null , true , null );
255
+ c .getContext (in , out , "" , "" , "" , null , true , qb . isDefSearch (), null );
239
256
assertTrue ("No match found" , match );
240
257
String s = out .toString ();
241
258
assertTrue ("Match not written to Writer" ,
@@ -263,7 +280,7 @@ public void testAllLinkWithLongLines() throws ParseException {
263
280
Context c = new Context (qb .build (), qb .getQueries ());
264
281
265
282
boolean match =
266
- c .getContext (in , out , "" , "" , "" , null , true , null );
283
+ c .getContext (in , out , "" , "" , "" , null , true , qb . isDefSearch (), null );
267
284
assertTrue ("No match found" , match );
268
285
String s = out .toString ();
269
286
assertTrue ("No [all...] link" , s .contains (">[all...]</a>" ));
@@ -290,7 +307,7 @@ public void testLongTruncatedLine() throws ParseException {
290
307
Context c = new Context (qb .build (), qb .getQueries ());
291
308
292
309
boolean match =
293
- c .getContext (in , out , "" , "" , "" , null , true , null );
310
+ c .getContext (in , out , "" , "" , "" , null , true , qb . isDefSearch (), null );
294
311
assertTrue ("No match found" , match );
295
312
String s = out .toString ();
296
313
assertTrue ("Match not listed" , s .contains ("<b>search_for_me</b>" ));
@@ -318,7 +335,7 @@ public void testMultiLineMatch() throws Exception {
318
335
Context c = new Context (qb .build (), qb .getQueries ());
319
336
assertTrue (
320
337
"No match found" ,
321
- c .getContext (in , out , "" , "" , "" , null , true , null ));
338
+ c .getContext (in , out , "" , "" , "" , null , true , qb . isDefSearch (), null ));
322
339
323
340
// Close the XML document body
324
341
out .append ("\n </document>" );
@@ -353,7 +370,7 @@ public void bug16848() throws Exception {
353
370
StringWriter out = new StringWriter ();
354
371
QueryBuilder qb = new QueryBuilder ().setFreetext ("mixed" );
355
372
Context c = new Context (qb .build (), qb .getQueries ());
356
- assertTrue (c .getContext (in , out , "" , "" , "" , null , false , null ));
373
+ assertTrue (c .getContext (in , out , "" , "" , "" , null , false , qb . isDefSearch (), null ));
357
374
assertEquals ("<a class=\" s\" href=\" #0\" ><span class=\" l\" >0</span> "
358
375
+ "<b>Mixed</b> case: abc AbC dEf</a><br/>" ,
359
376
out .toString ());
@@ -410,7 +427,7 @@ private void bug17582(QueryBuilder builder, int[] lines, String[] tags)
410
427
Context context = new Context (builder .build (), builder .getQueries ());
411
428
ArrayList <Hit > hits = new ArrayList <Hit >();
412
429
assertEquals (lines .length != 0 ,
413
- context .getContext (in , null , "" , "" , "" , defs , false , hits ));
430
+ context .getContext (in , null , "" , "" , "" , defs , false , builder . isDefSearch (), hits ));
414
431
assertEquals ("Unexpected number of hits" , lines .length , hits .size ());
415
432
for (int i = 0 ; i < lines .length ; i ++) {
416
433
assertEquals (Integer .toString (lines [i ]), hits .get (i ).getLineno ());
0 commit comments