MtasSolrComponentKwic.java.html
34.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>MtasSolrComponentKwic.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">MTAS</a> > <a href="index.source.html" class="el_package">mtas.solr.handler.component.util</a> > <span class="el_source">MtasSolrComponentKwic.java</span></div><h1>MtasSolrComponentKwic.java</h1><pre class="source lang-java linenums">package mtas.solr.handler.component.util;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.handler.component.SearchComponent;
import org.apache.solr.handler.component.ShardRequest;
import mtas.analysis.token.MtasToken;
import mtas.codec.util.CodecUtil;
import mtas.search.spans.util.MtasSpanQuery;
import mtas.codec.util.CodecComponent.ComponentField;
import mtas.codec.util.CodecComponent.ComponentFields;
import mtas.codec.util.CodecComponent.ComponentKwic;
import mtas.codec.util.CodecComponent.KwicHit;
import mtas.codec.util.CodecComponent.KwicToken;
import mtas.solr.handler.component.MtasSolrSearchComponent;
/**
* The Class MtasSolrComponentKwic.
*/
public class MtasSolrComponentKwic implements MtasSolrComponent<ComponentKwic> {
/** The Constant PARAM_MTAS_KWIC. */
public static final String PARAM_MTAS_KWIC = MtasSolrSearchComponent.PARAM_MTAS
+ ".kwic";
/** The Constant NAME_MTAS_KWIC_FIELD. */
public static final String NAME_MTAS_KWIC_FIELD = "field";
/** The Constant NAME_MTAS_KWIC_QUERY_TYPE. */
public static final String NAME_MTAS_KWIC_QUERY_TYPE = "query.type";
/** The Constant NAME_MTAS_KWIC_QUERY_VALUE. */
public static final String NAME_MTAS_KWIC_QUERY_VALUE = "query.value";
/** The Constant NAME_MTAS_KWIC_QUERY_PREFIX. */
public static final String NAME_MTAS_KWIC_QUERY_PREFIX = "query.prefix";
/** The Constant NAME_MTAS_KWIC_QUERY_IGNORE. */
public static final String NAME_MTAS_KWIC_QUERY_IGNORE = "query.ignore";
/** The Constant NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH. */
public static final String NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH = "query.maximumIgnoreLength";
/** The Constant NAME_MTAS_KWIC_QUERY_VARIABLE. */
public static final String NAME_MTAS_KWIC_QUERY_VARIABLE = "query.variable";
/** The Constant SUBNAME_MTAS_KWIC_QUERY_VARIABLE_NAME. */
public static final String SUBNAME_MTAS_KWIC_QUERY_VARIABLE_NAME = "name";
/** The Constant SUBNAME_MTAS_KWIC_QUERY_VARIABLE_VALUE. */
public static final String SUBNAME_MTAS_KWIC_QUERY_VARIABLE_VALUE = "value";
/** The Constant NAME_MTAS_KWIC_KEY. */
public static final String NAME_MTAS_KWIC_KEY = "key";
/** The Constant NAME_MTAS_KWIC_PREFIX. */
public static final String NAME_MTAS_KWIC_PREFIX = "prefix";
/** The Constant NAME_MTAS_KWIC_NUMBER. */
public static final String NAME_MTAS_KWIC_NUMBER = "number";
/** The Constant NAME_MTAS_KWIC_START. */
public static final String NAME_MTAS_KWIC_START = "start";
/** The Constant NAME_MTAS_KWIC_LEFT. */
public static final String NAME_MTAS_KWIC_LEFT = "left";
/** The Constant NAME_MTAS_KWIC_RIGHT. */
public static final String NAME_MTAS_KWIC_RIGHT = "right";
/** The Constant NAME_MTAS_KWIC_OUTPUT. */
public static final String NAME_MTAS_KWIC_OUTPUT = "output";
/**
* Instantiates a new mtas solr component kwic.
*
* @param searchComponent the search component
*/
<span class="fc" id="L90"> public MtasSolrComponentKwic(MtasSolrSearchComponent searchComponent) {</span>
<span class="fc" id="L91"> }</span>
/**
* Gets the positive integer.
*
* @param number the number
* @return the positive integer
*/
private int getPositiveInteger(String number) {
try {
<span class="nc" id="L101"> return Math.max(0, Integer.parseInt(number));</span>
<span class="nc" id="L102"> } catch (NumberFormatException e) {</span>
<span class="nc" id="L103"> return 0;</span>
}
}
/*
* (non-Javadoc)
*
* @see
* mtas.solr.handler.component.util.MtasSolrComponent#prepare(org.apache.solr.
* handler.component.ResponseBuilder,
* mtas.codec.util.CodecComponent.ComponentFields)
*/
public void prepare(ResponseBuilder rb, ComponentFields mtasFields)
throws IOException {
<span class="nc" id="L117"> Set<String> ids = MtasSolrResultUtil</span>
<span class="nc" id="L118"> .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_KWIC);</span>
<span class="nc bnc" id="L119" title="All 2 branches missed."> if (!ids.isEmpty()) {</span>
<span class="nc" id="L120"> int tmpCounter = 0;</span>
<span class="nc" id="L121"> String[] fields = new String[ids.size()];</span>
<span class="nc" id="L122"> String[] queryTypes = new String[ids.size()];</span>
<span class="nc" id="L123"> String[] queryValues = new String[ids.size()];</span>
<span class="nc" id="L124"> String[] queryPrefixes = new String[ids.size()];</span>
<span class="nc" id="L125"> String[] queryIgnores = new String[ids.size()];</span>
<span class="nc" id="L126"> String[] queryMaximumIgnoreLengths = new String[ids.size()];</span>
<span class="nc" id="L127"> HashMap<String, String[]>[] queryVariables = new HashMap[ids.size()];</span>
<span class="nc" id="L128"> String[] keys = new String[ids.size()];</span>
<span class="nc" id="L129"> String[] prefixes = new String[ids.size()];</span>
<span class="nc" id="L130"> String[] numbers = new String[ids.size()];</span>
<span class="nc" id="L131"> String[] starts = new String[ids.size()];</span>
<span class="nc" id="L132"> String[] lefts = new String[ids.size()];</span>
<span class="nc" id="L133"> String[] rights = new String[ids.size()];</span>
<span class="nc" id="L134"> String[] outputs = new String[ids.size()];</span>
<span class="nc bnc" id="L135" title="All 2 branches missed."> for (String id : ids) {</span>
<span class="nc" id="L136"> fields[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L137"> .get(PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_FIELD, null);</span>
<span class="nc" id="L138"> queryTypes[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_QUERY_TYPE, null);
<span class="nc" id="L140"> queryValues[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_QUERY_VALUE,
null);
<span class="nc" id="L143"> queryPrefixes[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_QUERY_PREFIX,
null);
<span class="nc" id="L146"> queryIgnores[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_QUERY_IGNORE,
null);
<span class="nc" id="L149"> queryMaximumIgnoreLengths[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L150"> .get(PARAM_MTAS_KWIC + "." + id + "."</span>
+ NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH, null);
<span class="nc" id="L152"> Set<String> vIds = MtasSolrResultUtil.getIdsFromParameters(</span>
<span class="nc" id="L153"> rb.req.getParams(),</span>
PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_QUERY_VARIABLE);
<span class="nc" id="L155"> queryVariables[tmpCounter] = new HashMap<>();</span>
<span class="nc bnc" id="L156" title="All 2 branches missed."> if (!vIds.isEmpty()) {</span>
<span class="nc" id="L157"> HashMap<String, ArrayList<String>> tmpVariables = new HashMap<>();</span>
<span class="nc bnc" id="L158" title="All 2 branches missed."> for (String vId : vIds) {</span>
<span class="nc" id="L159"> String name = rb.req.getParams().get(</span>
PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_QUERY_VARIABLE
+ "." + vId + "." + SUBNAME_MTAS_KWIC_QUERY_VARIABLE_NAME,
null);
<span class="nc bnc" id="L163" title="All 2 branches missed."> if (name != null) {</span>
<span class="nc bnc" id="L164" title="All 2 branches missed."> if (!tmpVariables.containsKey(name)) {</span>
<span class="nc" id="L165"> tmpVariables.put(name, new ArrayList<String>());</span>
}
<span class="nc" id="L167"> String value = rb.req.getParams()</span>
<span class="nc" id="L168"> .get(PARAM_MTAS_KWIC + "." + id + "."</span>
+ NAME_MTAS_KWIC_QUERY_VARIABLE + "." + vId + "."
+ SUBNAME_MTAS_KWIC_QUERY_VARIABLE_VALUE, null);
<span class="nc bnc" id="L171" title="All 2 branches missed."> if (value != null) {</span>
<span class="nc" id="L172"> ArrayList<String> list = new ArrayList<>();</span>
<span class="nc" id="L173"> String[] subList = value.split("(?<!\\\\),");</span>
<span class="nc bnc" id="L174" title="All 2 branches missed."> for (int i = 0; i < subList.length; i++) {</span>
<span class="nc" id="L175"> list.add(</span>
<span class="nc" id="L176"> subList[i].replace("\\,", ",").replace("\\\\", "\\"));</span>
}
<span class="nc" id="L178"> tmpVariables.get(name).addAll(list);</span>
}
}
<span class="nc" id="L181"> }</span>
<span class="nc bnc" id="L182" title="All 2 branches missed."> for (Entry<String, ArrayList<String>> entry : tmpVariables</span>
<span class="nc" id="L183"> .entrySet()) {</span>
<span class="nc" id="L184"> queryVariables[tmpCounter].put(entry.getKey(),</span>
<span class="nc" id="L185"> entry.getValue().toArray(new String[entry.getValue().size()]));</span>
<span class="nc" id="L186"> }</span>
}
<span class="nc" id="L188"> keys[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L189"> .get(PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_KEY,</span>
<span class="nc" id="L190"> String.valueOf(tmpCounter))</span>
<span class="nc" id="L191"> .trim();</span>
<span class="nc" id="L192"> prefixes[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_PREFIX, null);
<span class="nc" id="L194"> numbers[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_NUMBER, null);
<span class="nc" id="L196"> starts[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L197"> .get(PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_START, null);</span>
<span class="nc" id="L198"> lefts[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L199"> .get(PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_LEFT, null);</span>
<span class="nc" id="L200"> rights[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L201"> .get(PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_RIGHT, null);</span>
<span class="nc" id="L202"> starts[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L203"> .get(PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_START, null);</span>
<span class="nc" id="L204"> outputs[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_OUTPUT, null);
<span class="nc" id="L206"> tmpCounter++;</span>
<span class="nc" id="L207"> }</span>
<span class="nc" id="L208"> String uniqueKeyField = rb.req.getSchema().getUniqueKeyField().getName();</span>
<span class="nc" id="L209"> mtasFields.doKwic = true;</span>
<span class="nc" id="L210"> rb.setNeedDocList(true);</span>
<span class="nc bnc" id="L211" title="All 2 branches missed."> for (String field : fields) {</span>
<span class="nc bnc" id="L212" title="All 4 branches missed."> if (field == null || field.isEmpty()) {</span>
<span class="nc" id="L213"> throw new IOException("no (valid) field in mtas kwic");</span>
<span class="nc bnc" id="L214" title="All 2 branches missed."> } else if (!mtasFields.list.containsKey(field)) {</span>
<span class="nc" id="L215"> mtasFields.list.put(field, new ComponentField(uniqueKeyField));</span>
}
}
<span class="nc" id="L218"> MtasSolrResultUtil.compareAndCheck(keys, fields, NAME_MTAS_KWIC_KEY,</span>
<span class="nc" id="L219"> NAME_MTAS_KWIC_FIELD, true);</span>
<span class="nc" id="L220"> MtasSolrResultUtil.compareAndCheck(queryValues, fields,</span>
<span class="nc" id="L221"> NAME_MTAS_KWIC_QUERY_VALUE, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L222"> MtasSolrResultUtil.compareAndCheck(queryTypes, fields,</span>
<span class="nc" id="L223"> NAME_MTAS_KWIC_QUERY_TYPE, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L224"> MtasSolrResultUtil.compareAndCheck(queryPrefixes, fields,</span>
<span class="nc" id="L225"> NAME_MTAS_KWIC_QUERY_PREFIX, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L226"> MtasSolrResultUtil.compareAndCheck(queryIgnores, fields,</span>
<span class="nc" id="L227"> NAME_MTAS_KWIC_QUERY_IGNORE, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L228"> MtasSolrResultUtil.compareAndCheck(queryMaximumIgnoreLengths, fields,</span>
NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH, NAME_MTAS_KWIC_FIELD,
<span class="nc" id="L230"> false);</span>
<span class="nc" id="L231"> MtasSolrResultUtil.compareAndCheck(prefixes, fields,</span>
<span class="nc" id="L232"> NAME_MTAS_KWIC_PREFIX, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L233"> MtasSolrResultUtil.compareAndCheck(numbers, fields, NAME_MTAS_KWIC_NUMBER,</span>
<span class="nc" id="L234"> NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L235"> MtasSolrResultUtil.compareAndCheck(starts, fields, NAME_MTAS_KWIC_START,</span>
<span class="nc" id="L236"> NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L237"> MtasSolrResultUtil.compareAndCheck(lefts, fields, NAME_MTAS_KWIC_LEFT,</span>
<span class="nc" id="L238"> NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L239"> MtasSolrResultUtil.compareAndCheck(rights, fields, NAME_MTAS_KWIC_RIGHT,</span>
<span class="nc" id="L240"> NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L241"> MtasSolrResultUtil.compareAndCheck(outputs, fields, NAME_MTAS_KWIC_OUTPUT,</span>
<span class="nc" id="L242"> NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc bnc" id="L243" title="All 2 branches missed."> for (int i = 0; i < fields.length; i++) {</span>
<span class="nc" id="L244"> ComponentField cf = mtasFields.list.get(fields[i]);</span>
<span class="nc bnc" id="L245" title="All 2 branches missed."> Integer maximumIgnoreLength = (queryMaximumIgnoreLengths[i] == null)</span>
<span class="nc" id="L246"> ? null : Integer.parseInt(queryMaximumIgnoreLengths[i]);</span>
<span class="nc" id="L247"> MtasSpanQuery q = MtasSolrResultUtil.constructQuery(queryValues[i],</span>
queryTypes[i], queryPrefixes[i], queryVariables[i], fields[i],
queryIgnores[i], maximumIgnoreLength);
// minimize number of queries
<span class="nc bnc" id="L251" title="All 2 branches missed."> if (cf.spanQueryList.contains(q)) {</span>
<span class="nc" id="L252"> q = cf.spanQueryList.get(cf.spanQueryList.indexOf(q));</span>
} else {
<span class="nc" id="L254"> cf.spanQueryList.add(q);</span>
}
<span class="nc bnc" id="L256" title="All 4 branches missed."> String key = (keys[i] == null) || (keys[i].isEmpty())</span>
<span class="nc" id="L257"> ? String.valueOf(i) + ":" + fields[i] + ":" + queryValues[i]</span>
<span class="nc" id="L258"> : keys[i].trim();</span>
<span class="nc" id="L259"> String prefix = prefixes[i];</span>
<span class="nc bnc" id="L260" title="All 2 branches missed."> Integer number = (numbers[i] != null) ? getPositiveInteger(numbers[i])</span>
: null;
<span class="nc" id="L262"> int start = getPositiveInteger(starts[i]);</span>
<span class="nc" id="L263"> int left = getPositiveInteger(lefts[i]);</span>
<span class="nc" id="L264"> int right = getPositiveInteger(rights[i]);</span>
<span class="nc" id="L265"> String output = outputs[i];</span>
<span class="nc" id="L266"> mtasFields.list.get(fields[i]).kwicList.add(new ComponentKwic(q, key,</span>
prefix, number, start, left, right, output));
}
}
<span class="nc" id="L270"> }</span>
/*
* (non-Javadoc)
*
* @see
* mtas.solr.handler.component.util.MtasSolrComponent#create(mtas.codec.util.
* CodecComponent.BasicComponent, java.lang.Boolean)
*/
public SimpleOrderedMap<Object> create(ComponentKwic kwic, Boolean encode) {
<span class="nc" id="L280"> SimpleOrderedMap<Object> mtasKwicResponse = new SimpleOrderedMap<>();</span>
<span class="nc" id="L281"> mtasKwicResponse.add("key", kwic.key);</span>
<span class="nc" id="L282"> ArrayList<NamedList<Object>> mtasKwicItemResponses = new ArrayList<>();</span>
<span class="nc bnc" id="L283" title="All 2 branches missed."> if (kwic.output.equals(ComponentKwic.KWIC_OUTPUT_HIT)) {</span>
<span class="nc bnc" id="L284" title="All 2 branches missed."> for (int docId : kwic.hits.keySet()) {</span>
<span class="nc" id="L285"> NamedList<Object> mtasKwicItemResponse = new SimpleOrderedMap<>();</span>
<span class="nc" id="L286"> List<KwicHit> list = kwic.hits.get(docId);</span>
<span class="nc" id="L287"> List<NamedList<Object>> mtasKwicItemResponseItems = new ArrayList<>();</span>
<span class="nc bnc" id="L288" title="All 2 branches missed."> for (KwicHit h : list) {</span>
<span class="nc" id="L289"> NamedList<Object> mtasKwicItemResponseItem = new SimpleOrderedMap<>();</span>
<span class="nc" id="L290"> SortedMap<Integer, List<List<String>>> hitData = new TreeMap<>();</span>
<span class="nc" id="L291"> SortedMap<Integer, List<List<String>>> leftData = null;</span>
<span class="nc" id="L292"> SortedMap<Integer, List<List<String>>> rightData = null;</span>
<span class="nc bnc" id="L293" title="All 2 branches missed."> if (kwic.left > 0) {</span>
<span class="nc" id="L294"> leftData = new TreeMap<>();</span>
}
<span class="nc bnc" id="L296" title="All 2 branches missed."> if (kwic.right > 0) {</span>
<span class="nc" id="L297"> rightData = new TreeMap<>();</span>
}
<span class="nc" id="L299"> for (int position = Math.max(0,</span>
<span class="nc bnc" id="L300" title="All 2 branches missed."> h.startPosition - kwic.left); position <= (h.endPosition</span>
<span class="nc" id="L301"> + kwic.right); position++) {</span>
<span class="nc bnc" id="L302" title="All 2 branches missed."> if (h.hits.containsKey(position)) {</span>
<span class="nc" id="L303"> List<List<String>> hitDataItem = new ArrayList<>();</span>
<span class="nc bnc" id="L304" title="All 2 branches missed."> for (String term : h.hits.get(position)) {</span>
<span class="nc" id="L305"> List<String> hitDataSubItem = new ArrayList<>();</span>
<span class="nc" id="L306"> hitDataSubItem.add(CodecUtil.termPrefix(term));</span>
<span class="nc" id="L307"> hitDataSubItem.add(CodecUtil.termValue(term));</span>
<span class="nc" id="L308"> hitDataItem.add(hitDataSubItem);</span>
<span class="nc" id="L309"> }</span>
<span class="nc bnc" id="L310" title="All 2 branches missed."> if (position < h.startPosition) {</span>
<span class="nc bnc" id="L311" title="All 2 branches missed."> if (leftData != null) {</span>
<span class="nc" id="L312"> leftData.put(position, hitDataItem);</span>
}
<span class="nc bnc" id="L314" title="All 2 branches missed."> } else if (position > h.endPosition) {</span>
<span class="nc bnc" id="L315" title="All 2 branches missed."> if (rightData != null) {</span>
<span class="nc" id="L316"> rightData.put(position, hitDataItem);</span>
}
} else {
<span class="nc" id="L319"> hitData.put(position, hitDataItem);</span>
}
}
}
<span class="nc bnc" id="L323" title="All 2 branches missed."> if (kwic.left > 0) {</span>
<span class="nc" id="L324"> mtasKwicItemResponseItem.add("left", leftData);</span>
}
<span class="nc" id="L326"> mtasKwicItemResponseItem.add("hit", hitData);</span>
<span class="nc bnc" id="L327" title="All 2 branches missed."> if (kwic.right > 0) {</span>
<span class="nc" id="L328"> mtasKwicItemResponseItem.add("right", rightData);</span>
}
<span class="nc" id="L330"> mtasKwicItemResponseItems.add(mtasKwicItemResponseItem);</span>
<span class="nc" id="L331"> }</span>
<span class="nc" id="L332"> mtasKwicItemResponse.add("documentKey", kwic.uniqueKey.get(docId));</span>
<span class="nc" id="L333"> mtasKwicItemResponse.add("documentTotal", kwic.subTotal.get(docId));</span>
<span class="nc" id="L334"> mtasKwicItemResponse.add("documentMinPosition",</span>
<span class="nc" id="L335"> kwic.minPosition.get(docId));</span>
<span class="nc" id="L336"> mtasKwicItemResponse.add("documentMaxPosition",</span>
<span class="nc" id="L337"> kwic.maxPosition.get(docId));</span>
<span class="nc" id="L338"> mtasKwicItemResponse.add("list", mtasKwicItemResponseItems);</span>
<span class="nc" id="L339"> mtasKwicItemResponses.add(mtasKwicItemResponse);</span>
<span class="nc" id="L340"> }</span>
<span class="nc bnc" id="L341" title="All 2 branches missed."> } else if (kwic.output.equals(ComponentKwic.KWIC_OUTPUT_TOKEN)) {</span>
<span class="nc bnc" id="L342" title="All 2 branches missed."> for (int docId : kwic.tokens.keySet()) {</span>
<span class="nc" id="L343"> NamedList<Object> mtasKwicItemResponse = new SimpleOrderedMap<>();</span>
<span class="nc" id="L344"> List<KwicToken> list = kwic.tokens.get(docId);</span>
<span class="nc" id="L345"> List<NamedList<Object>> mtasKwicItemResponseItems = new ArrayList<>();</span>
<span class="nc bnc" id="L346" title="All 2 branches missed."> for (KwicToken k : list) {</span>
<span class="nc" id="L347"> NamedList<Object> mtasKwicItemResponseItem = new SimpleOrderedMap<>();</span>
<span class="nc" id="L348"> mtasKwicItemResponseItem.add("startPosition", k.startPosition);</span>
<span class="nc" id="L349"> mtasKwicItemResponseItem.add("endPosition", k.endPosition);</span>
<span class="nc" id="L350"> ArrayList<NamedList<Object>> mtasKwicItemResponseItemTokens = new ArrayList<>();</span>
<span class="nc bnc" id="L351" title="All 2 branches missed."> for (MtasToken token : k.tokens) {</span>
<span class="nc" id="L352"> NamedList<Object> mtasKwicItemResponseItemToken = new SimpleOrderedMap<>();</span>
<span class="nc bnc" id="L353" title="All 2 branches missed."> if (token.getId() != null) {</span>
<span class="nc" id="L354"> mtasKwicItemResponseItemToken.add("mtasId", token.getId());</span>
}
<span class="nc" id="L356"> mtasKwicItemResponseItemToken.add("prefix", token.getPrefix());</span>
<span class="nc" id="L357"> mtasKwicItemResponseItemToken.add("value", token.getPostfix());</span>
<span class="nc bnc" id="L358" title="All 2 branches missed."> if (token.getPositionStart() != null) {</span>
<span class="nc" id="L359"> mtasKwicItemResponseItemToken.add("positionStart",</span>
<span class="nc" id="L360"> token.getPositionStart());</span>
<span class="nc" id="L361"> mtasKwicItemResponseItemToken.add("positionEnd",</span>
<span class="nc" id="L362"> token.getPositionEnd());</span>
}
<span class="nc bnc" id="L364" title="All 2 branches missed."> if (token.getPositions() != null) {</span>
<span class="nc" id="L365"> mtasKwicItemResponseItemToken.add("positions",</span>
<span class="nc" id="L366"> token.getPositions());</span>
}
<span class="nc bnc" id="L368" title="All 2 branches missed."> if (token.getParentId() != null) {</span>
<span class="nc" id="L369"> mtasKwicItemResponseItemToken.add("parentMtasId",</span>
<span class="nc" id="L370"> token.getParentId());</span>
}
<span class="nc bnc" id="L372" title="All 2 branches missed."> if (token.getPayload() != null) {</span>
<span class="nc" id="L373"> mtasKwicItemResponseItemToken.add("payload", token.getPayload());</span>
}
<span class="nc bnc" id="L375" title="All 2 branches missed."> if (token.getOffsetStart() != null) {</span>
<span class="nc" id="L376"> mtasKwicItemResponseItemToken.add("offsetStart",</span>
<span class="nc" id="L377"> token.getOffsetStart());</span>
<span class="nc" id="L378"> mtasKwicItemResponseItemToken.add("offsetEnd",</span>
<span class="nc" id="L379"> token.getOffsetEnd());</span>
}
<span class="nc bnc" id="L381" title="All 2 branches missed."> if (token.getRealOffsetStart() != null) {</span>
<span class="nc" id="L382"> mtasKwicItemResponseItemToken.add("realOffsetStart",</span>
<span class="nc" id="L383"> token.getRealOffsetStart());</span>
<span class="nc" id="L384"> mtasKwicItemResponseItemToken.add("realOffsetEnd",</span>
<span class="nc" id="L385"> token.getRealOffsetEnd());</span>
}
<span class="nc" id="L387"> mtasKwicItemResponseItemTokens.add(mtasKwicItemResponseItemToken);</span>
<span class="nc" id="L388"> }</span>
<span class="nc" id="L389"> mtasKwicItemResponseItem.add("tokens",</span>
mtasKwicItemResponseItemTokens);
<span class="nc" id="L391"> mtasKwicItemResponseItems.add(mtasKwicItemResponseItem);</span>
<span class="nc" id="L392"> }</span>
<span class="nc" id="L393"> mtasKwicItemResponse.add("documentKey", kwic.uniqueKey.get(docId));</span>
<span class="nc" id="L394"> mtasKwicItemResponse.add("documentTotal", kwic.subTotal.get(docId));</span>
<span class="nc" id="L395"> mtasKwicItemResponse.add("documentMinPosition",</span>
<span class="nc" id="L396"> kwic.minPosition.get(docId));</span>
<span class="nc" id="L397"> mtasKwicItemResponse.add("documentMaxPosition",</span>
<span class="nc" id="L398"> kwic.maxPosition.get(docId));</span>
<span class="nc" id="L399"> mtasKwicItemResponse.add("list", mtasKwicItemResponseItems);</span>
<span class="nc" id="L400"> mtasKwicItemResponses.add(mtasKwicItemResponse);</span>
<span class="nc" id="L401"> }</span>
}
<span class="nc" id="L403"> mtasKwicResponse.add("list", mtasKwicItemResponses);</span>
<span class="nc" id="L404"> return mtasKwicResponse;</span>
}
/*
* (non-Javadoc)
*
* @see
* mtas.solr.handler.component.util.MtasSolrComponent#modifyRequest(org.apache
* .solr.handler.component.ResponseBuilder,
* org.apache.solr.handler.component.SearchComponent,
* org.apache.solr.handler.component.ShardRequest)
*/
public void modifyRequest(ResponseBuilder rb, SearchComponent who,
ShardRequest sreq) {
<span class="nc bnc" id="L418" title="All 2 branches missed."> if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) {</span>
<span class="nc bnc" id="L419" title="All 4 branches missed."> if (sreq.params.getBool(PARAM_MTAS_KWIC, false)</span>
&& (sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) != 0) {
// do nothing
} else {
<span class="nc" id="L423"> Set<String> keys = MtasSolrResultUtil</span>
<span class="nc" id="L424"> .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_KWIC);</span>
<span class="nc" id="L425"> sreq.params.remove(PARAM_MTAS_KWIC);</span>
<span class="nc bnc" id="L426" title="All 2 branches missed."> for (String key : keys) {</span>
<span class="nc" id="L427"> sreq.params</span>
<span class="nc" id="L428"> .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_FIELD);</span>
<span class="nc" id="L429"> sreq.params.remove(</span>
PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_TYPE);
<span class="nc" id="L431"> sreq.params.remove(</span>
PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_VALUE);
<span class="nc" id="L433"> sreq.params.remove(</span>
PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_PREFIX);
<span class="nc" id="L435"> sreq.params.remove(</span>
PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_IGNORE);
<span class="nc" id="L437"> sreq.params.remove(PARAM_MTAS_KWIC + "." + key + "."</span>
+ NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH);
<span class="nc" id="L439"> sreq.params</span>
<span class="nc" id="L440"> .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_KEY);</span>
<span class="nc" id="L441"> sreq.params.remove(</span>
PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_PREFIX);
<span class="nc" id="L443"> sreq.params.remove(</span>
PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_NUMBER);
<span class="nc" id="L445"> sreq.params</span>
<span class="nc" id="L446"> .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_LEFT);</span>
<span class="nc" id="L447"> sreq.params</span>
<span class="nc" id="L448"> .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_RIGHT);</span>
<span class="nc" id="L449"> sreq.params.remove(</span>
PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_OUTPUT);
<span class="nc" id="L451"> }</span>
}
}
<span class="nc" id="L454"> }</span>
/*
* (non-Javadoc)
*
* @see
* mtas.solr.handler.component.util.MtasSolrComponent#finishStage(org.apache.
* solr.handler.component.ResponseBuilder)
*/
public void finishStage(ResponseBuilder rb) {
<span class="nc bnc" id="L464" title="All 6 branches missed."> if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
&& rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY
&& rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {
<span class="nc bnc" id="L467" title="All 2 branches missed."> for (ShardRequest sreq : rb.finished) {</span>
<span class="nc bnc" id="L468" title="All 2 branches missed."> if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="nc bnc" id="L469" title="All 2 branches missed."> && sreq.params.getBool(PARAM_MTAS_KWIC, false)) {</span>
// nothing to do
}
<span class="nc" id="L472"> }</span>
}
<span class="nc" id="L474"> }</span>
/*
* (non-Javadoc)
*
* @see
* mtas.solr.handler.component.util.MtasSolrComponent#distributedProcess(org.
* apache.solr.handler.component.ResponseBuilder,
* mtas.codec.util.CodecComponent.ComponentFields)
*/
public void distributedProcess(ResponseBuilder rb, ComponentFields mtasFields)
throws IOException {
// nothing to do
<span class="nc" id="L487"> }</span>
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>