MtasSolrComponentKwic.java.html
35 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
491
<?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.Arrays;
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="L91"> public MtasSolrComponentKwic(MtasSolrSearchComponent searchComponent) {</span>
<span class="fc" id="L92"> }</span>
/**
* Gets the positive integer.
*
* @param number the number
* @return the positive integer
*/
private int getPositiveInteger(String number) {
try {
<span class="nc" id="L102"> return Math.max(0, Integer.parseInt(number));</span>
<span class="nc" id="L103"> } catch (NumberFormatException e) {</span>
<span class="nc" id="L104"> 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="L118"> Set<String> ids = MtasSolrResultUtil</span>
<span class="nc" id="L119"> .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_KWIC);</span>
<span class="nc bnc" id="L120" title="All 2 branches missed."> if (!ids.isEmpty()) {</span>
<span class="nc" id="L121"> int tmpCounter = 0;</span>
<span class="nc" id="L122"> String[] fields = new String[ids.size()];</span>
<span class="nc" id="L123"> String[] queryTypes = new String[ids.size()];</span>
<span class="nc" id="L124"> String[] queryValues = new String[ids.size()];</span>
<span class="nc" id="L125"> String[] queryPrefixes = new String[ids.size()];</span>
<span class="nc" id="L126"> String[] queryIgnores = new String[ids.size()];</span>
<span class="nc" id="L127"> String[] queryMaximumIgnoreLengths = new String[ids.size()];</span>
<span class="nc" id="L128"> HashMap<String, String[]>[] queryVariables = new HashMap[ids.size()];</span>
<span class="nc" id="L129"> String[] keys = new String[ids.size()];</span>
<span class="nc" id="L130"> String[] prefixes = new String[ids.size()];</span>
<span class="nc" id="L131"> String[] numbers = new String[ids.size()];</span>
<span class="nc" id="L132"> String[] starts = new String[ids.size()];</span>
<span class="nc" id="L133"> String[] lefts = new String[ids.size()];</span>
<span class="nc" id="L134"> String[] rights = new String[ids.size()];</span>
<span class="nc" id="L135"> String[] outputs = new String[ids.size()];</span>
<span class="nc bnc" id="L136" title="All 2 branches missed."> for (String id : ids) {</span>
<span class="nc" id="L137"> fields[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L138"> .get(PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_FIELD, null);</span>
<span class="nc" id="L139"> queryTypes[tmpCounter] = rb.req.getParams().get(</span>
<span class="nc" id="L140"> PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_QUERY_TYPE, null);</span>
<span class="nc" id="L141"> queryValues[tmpCounter] = rb.req.getParams().get(</span>
<span class="nc" id="L142"> PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_QUERY_VALUE,</span>
<span class="nc" id="L143"> null);</span>
<span class="nc" id="L144"> queryPrefixes[tmpCounter] = rb.req.getParams().get(</span>
<span class="nc" id="L145"> PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_QUERY_PREFIX,</span>
<span class="nc" id="L146"> null);</span>
<span class="nc" id="L147"> queryIgnores[tmpCounter] = rb.req.getParams().get(</span>
<span class="nc" id="L148"> PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_QUERY_IGNORE,</span>
<span class="nc" id="L149"> null);</span>
<span class="nc" id="L150"> queryMaximumIgnoreLengths[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L151"> .get(PARAM_MTAS_KWIC + "." + id + "."</span>
<span class="nc" id="L152"> + NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH, null);</span>
<span class="nc" id="L153"> Set<String> vIds = MtasSolrResultUtil.getIdsFromParameters(</span>
<span class="nc" id="L154"> rb.req.getParams(),</span>
<span class="nc" id="L155"> PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_QUERY_VARIABLE);</span>
<span class="nc" id="L156"> queryVariables[tmpCounter] = new HashMap<>();</span>
<span class="nc bnc" id="L157" title="All 2 branches missed."> if (!vIds.isEmpty()) {</span>
<span class="nc" id="L158"> HashMap<String, ArrayList<String>> tmpVariables = new HashMap<>();</span>
<span class="nc bnc" id="L159" title="All 2 branches missed."> for (String vId : vIds) {</span>
<span class="nc" id="L160"> String name = rb.req.getParams().get(</span>
<span class="nc" id="L161"> PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_QUERY_VARIABLE</span>
<span class="nc" id="L162"> + "." + vId + "." + SUBNAME_MTAS_KWIC_QUERY_VARIABLE_NAME,</span>
<span class="nc" id="L163"> null);</span>
<span class="nc bnc" id="L164" title="All 2 branches missed."> if (name != null) {</span>
<span class="nc bnc" id="L165" title="All 2 branches missed."> if (!tmpVariables.containsKey(name)) {</span>
<span class="nc" id="L166"> tmpVariables.put(name, new ArrayList<String>());</span>
}
<span class="nc" id="L168"> String value = rb.req.getParams()</span>
<span class="nc" id="L169"> .get(PARAM_MTAS_KWIC + "." + id + "."</span>
<span class="nc" id="L170"> + NAME_MTAS_KWIC_QUERY_VARIABLE + "." + vId + "."</span>
<span class="nc" id="L171"> + SUBNAME_MTAS_KWIC_QUERY_VARIABLE_VALUE, null);</span>
<span class="nc bnc" id="L172" title="All 2 branches missed."> if (value != null) {</span>
<span class="nc" id="L173"> ArrayList<String> list = new ArrayList<>();</span>
<span class="nc" id="L174"> String[] subList = value.split("(?<!\\\\),");</span>
<span class="nc bnc" id="L175" title="All 2 branches missed."> for (int i = 0; i < subList.length; i++) {</span>
<span class="nc" id="L176"> list.add(</span>
<span class="nc" id="L177"> subList[i].replace("\\,", ",").replace("\\\\", "\\"));</span>
}
<span class="nc" id="L179"> tmpVariables.get(name).addAll(list);</span>
}
}
}
<span class="nc bnc" id="L183" title="All 2 branches missed."> for (Entry<String, ArrayList<String>> entry : tmpVariables</span>
<span class="nc" id="L184"> .entrySet()) {</span>
<span class="nc" id="L185"> queryVariables[tmpCounter].put(entry.getKey(),</span>
<span class="nc" id="L186"> entry.getValue().toArray(new String[entry.getValue().size()]));</span>
}
}
<span class="nc" id="L189"> keys[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L190"> .get(PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_KEY,</span>
<span class="nc" id="L191"> String.valueOf(tmpCounter))</span>
<span class="nc" id="L192"> .trim();</span>
<span class="nc" id="L193"> prefixes[tmpCounter] = rb.req.getParams().get(</span>
<span class="nc" id="L194"> PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_PREFIX, null);</span>
<span class="nc" id="L195"> numbers[tmpCounter] = rb.req.getParams().get(</span>
<span class="nc" id="L196"> PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_NUMBER, null);</span>
<span class="nc" id="L197"> starts[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L198"> .get(PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_START, null);</span>
<span class="nc" id="L199"> lefts[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L200"> .get(PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_LEFT, null);</span>
<span class="nc" id="L201"> rights[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L202"> .get(PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_RIGHT, null);</span>
<span class="nc" id="L203"> starts[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L204"> .get(PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_START, null);</span>
<span class="nc" id="L205"> outputs[tmpCounter] = rb.req.getParams().get(</span>
<span class="nc" id="L206"> PARAM_MTAS_KWIC + "." + id + "." + NAME_MTAS_KWIC_OUTPUT, null);</span>
<span class="nc" id="L207"> tmpCounter++;</span>
}
<span class="nc" id="L209"> String uniqueKeyField = rb.req.getSchema().getUniqueKeyField().getName();</span>
<span class="nc" id="L210"> mtasFields.doKwic = true;</span>
<span class="nc" id="L211"> rb.setNeedDocList(true);</span>
<span class="nc bnc" id="L212" title="All 2 branches missed."> for (String field : fields) {</span>
<span class="nc bnc" id="L213" title="All 4 branches missed."> if (field == null || field.isEmpty()) {</span>
<span class="nc" id="L214"> throw new IOException("no (valid) field in mtas kwic");</span>
<span class="nc bnc" id="L215" title="All 2 branches missed."> } else if (!mtasFields.list.containsKey(field)) {</span>
<span class="nc" id="L216"> mtasFields.list.put(field, new ComponentField(uniqueKeyField));</span>
}
}
<span class="nc" id="L219"> MtasSolrResultUtil.compareAndCheck(keys, fields, NAME_MTAS_KWIC_KEY,</span>
<span class="nc" id="L220"> NAME_MTAS_KWIC_FIELD, true);</span>
<span class="nc" id="L221"> MtasSolrResultUtil.compareAndCheck(queryValues, fields,</span>
<span class="nc" id="L222"> NAME_MTAS_KWIC_QUERY_VALUE, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L223"> MtasSolrResultUtil.compareAndCheck(queryTypes, fields,</span>
<span class="nc" id="L224"> NAME_MTAS_KWIC_QUERY_TYPE, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L225"> MtasSolrResultUtil.compareAndCheck(queryPrefixes, fields,</span>
<span class="nc" id="L226"> NAME_MTAS_KWIC_QUERY_PREFIX, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L227"> MtasSolrResultUtil.compareAndCheck(queryIgnores, fields,</span>
<span class="nc" id="L228"> NAME_MTAS_KWIC_QUERY_IGNORE, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L229"> MtasSolrResultUtil.compareAndCheck(queryMaximumIgnoreLengths, fields,</span>
<span class="nc" id="L230"> NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH, NAME_MTAS_KWIC_FIELD,</span>
<span class="nc" id="L231"> false);</span>
<span class="nc" id="L232"> MtasSolrResultUtil.compareAndCheck(prefixes, fields,</span>
<span class="nc" id="L233"> NAME_MTAS_KWIC_PREFIX, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L234"> MtasSolrResultUtil.compareAndCheck(numbers, fields, NAME_MTAS_KWIC_NUMBER,</span>
<span class="nc" id="L235"> NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L236"> MtasSolrResultUtil.compareAndCheck(starts, fields, NAME_MTAS_KWIC_START,</span>
<span class="nc" id="L237"> NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L238"> MtasSolrResultUtil.compareAndCheck(lefts, fields, NAME_MTAS_KWIC_LEFT,</span>
<span class="nc" id="L239"> NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L240"> MtasSolrResultUtil.compareAndCheck(rights, fields, NAME_MTAS_KWIC_RIGHT,</span>
<span class="nc" id="L241"> NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L242"> MtasSolrResultUtil.compareAndCheck(outputs, fields, NAME_MTAS_KWIC_OUTPUT,</span>
<span class="nc" id="L243"> NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc bnc" id="L244" title="All 2 branches missed."> for (int i = 0; i < fields.length; i++) {</span>
<span class="nc" id="L245"> ComponentField cf = mtasFields.list.get(fields[i]);</span>
<span class="nc bnc" id="L246" title="All 2 branches missed."> Integer maximumIgnoreLength = (queryMaximumIgnoreLengths[i] == null)</span>
<span class="nc" id="L247"> ? null : Integer.parseInt(queryMaximumIgnoreLengths[i]);</span>
<span class="nc" id="L248"> MtasSpanQuery q = MtasSolrResultUtil.constructQuery(queryValues[i],</span>
<span class="nc" id="L249"> queryTypes[i], queryPrefixes[i], queryVariables[i], fields[i],</span>
<span class="nc" id="L250"> queryIgnores[i], maximumIgnoreLength);</span>
// minimize number of queries
<span class="nc bnc" id="L252" title="All 2 branches missed."> if (cf.spanQueryList.contains(q)) {</span>
<span class="nc" id="L253"> q = cf.spanQueryList.get(cf.spanQueryList.indexOf(q));</span>
<span class="nc" id="L254"> } else {</span>
<span class="nc" id="L255"> cf.spanQueryList.add(q);</span>
}
<span class="nc bnc" id="L257" title="All 4 branches missed."> String key = (keys[i] == null) || (keys[i].isEmpty())</span>
<span class="nc" id="L258"> ? String.valueOf(i) + ":" + fields[i] + ":" + queryValues[i]</span>
<span class="nc" id="L259"> : keys[i].trim();</span>
<span class="nc" id="L260"> String prefix = prefixes[i];</span>
<span class="nc bnc" id="L261" title="All 2 branches missed."> Integer number = (numbers[i] != null) ? getPositiveInteger(numbers[i])</span>
<span class="nc" id="L262"> : null;</span>
<span class="nc" id="L263"> int start = getPositiveInteger(starts[i]);</span>
<span class="nc" id="L264"> int left = getPositiveInteger(lefts[i]);</span>
<span class="nc" id="L265"> int right = getPositiveInteger(rights[i]);</span>
<span class="nc" id="L266"> String output = outputs[i];</span>
<span class="nc" id="L267"> mtasFields.list.get(fields[i]).kwicList.add(new ComponentKwic(q, key,</span>
<span class="nc" id="L268"> prefix, number, start, left, right, output));</span>
}
}
<span class="nc" id="L271"> }</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="L281"> SimpleOrderedMap<Object> mtasKwicResponse = new SimpleOrderedMap<>();</span>
<span class="nc" id="L282"> mtasKwicResponse.add("key", kwic.key);</span>
<span class="nc" id="L283"> ArrayList<NamedList<Object>> mtasKwicItemResponses = new ArrayList<>();</span>
<span class="nc bnc" id="L284" title="All 2 branches missed."> if (kwic.output.equals(ComponentKwic.KWIC_OUTPUT_HIT)) {</span>
<span class="nc bnc" id="L285" title="All 2 branches missed."> for (int docId : kwic.hits.keySet()) {</span>
<span class="nc" id="L286"> NamedList<Object> mtasKwicItemResponse = new SimpleOrderedMap<>();</span>
<span class="nc" id="L287"> List<KwicHit> list = kwic.hits.get(docId);</span>
<span class="nc" id="L288"> List<NamedList<Object>> mtasKwicItemResponseItems = new ArrayList<>();</span>
<span class="nc bnc" id="L289" title="All 2 branches missed."> for (KwicHit h : list) {</span>
<span class="nc" id="L290"> NamedList<Object> mtasKwicItemResponseItem = new SimpleOrderedMap<>();</span>
<span class="nc" id="L291"> SortedMap<Integer, List<List<String>>> hitData = new TreeMap<>();</span>
<span class="nc" id="L292"> SortedMap<Integer, List<List<String>>> leftData = null;</span>
<span class="nc" id="L293"> SortedMap<Integer, List<List<String>>> rightData = null;</span>
<span class="nc bnc" id="L294" title="All 2 branches missed."> if (kwic.left > 0) {</span>
<span class="nc" id="L295"> leftData = new TreeMap<>();</span>
}
<span class="nc bnc" id="L297" title="All 2 branches missed."> if (kwic.right > 0) {</span>
<span class="nc" id="L298"> rightData = new TreeMap<>();</span>
}
<span class="nc bnc" id="L300" title="All 2 branches missed."> for (int position = Math.max(0,</span>
<span class="nc" id="L301"> h.startPosition - kwic.left); position <= (h.endPosition</span>
<span class="nc" id="L302"> + kwic.right); position++) {</span>
<span class="nc bnc" id="L303" title="All 2 branches missed."> if (h.hits.containsKey(position)) {</span>
<span class="nc" id="L304"> List<List<String>> hitDataItem = new ArrayList<>();</span>
<span class="nc bnc" id="L305" title="All 2 branches missed."> for (String term : h.hits.get(position)) {</span>
<span class="nc" id="L306"> List<String> hitDataSubItem = new ArrayList<>();</span>
<span class="nc" id="L307"> hitDataSubItem.add(CodecUtil.termPrefix(term));</span>
<span class="nc" id="L308"> hitDataSubItem.add(CodecUtil.termValue(term));</span>
<span class="nc" id="L309"> hitDataItem.add(hitDataSubItem);</span>
}
<span class="nc bnc" id="L311" title="All 2 branches missed."> if (position < h.startPosition) {</span>
<span class="nc bnc" id="L312" title="All 2 branches missed."> if (leftData != null) {</span>
<span class="nc" id="L313"> leftData.put(position, hitDataItem);</span>
}
<span class="nc bnc" id="L315" title="All 2 branches missed."> } else if (position > h.endPosition) {</span>
<span class="nc bnc" id="L316" title="All 2 branches missed."> if (rightData != null) {</span>
<span class="nc" id="L317"> rightData.put(position, hitDataItem);</span>
}
<span class="nc" id="L319"> } else {</span>
<span class="nc" id="L320"> hitData.put(position, hitDataItem);</span>
}
}
}
<span class="nc bnc" id="L324" title="All 2 branches missed."> if (kwic.left > 0) {</span>
<span class="nc" id="L325"> mtasKwicItemResponseItem.add("left", leftData);</span>
}
<span class="nc" id="L327"> mtasKwicItemResponseItem.add("hit", hitData);</span>
<span class="nc bnc" id="L328" title="All 2 branches missed."> if (kwic.right > 0) {</span>
<span class="nc" id="L329"> mtasKwicItemResponseItem.add("right", rightData);</span>
}
<span class="nc" id="L331"> mtasKwicItemResponseItems.add(mtasKwicItemResponseItem);</span>
}
<span class="nc" id="L333"> mtasKwicItemResponse.add("documentKey", kwic.uniqueKey.get(docId));</span>
<span class="nc" id="L334"> mtasKwicItemResponse.add("documentTotal", kwic.subTotal.get(docId));</span>
<span class="nc" id="L335"> mtasKwicItemResponse.add("documentMinPosition",</span>
<span class="nc" id="L336"> kwic.minPosition.get(docId));</span>
<span class="nc" id="L337"> mtasKwicItemResponse.add("documentMaxPosition",</span>
<span class="nc" id="L338"> kwic.maxPosition.get(docId));</span>
<span class="nc" id="L339"> mtasKwicItemResponse.add("list", mtasKwicItemResponseItems);</span>
<span class="nc" id="L340"> mtasKwicItemResponses.add(mtasKwicItemResponse);</span>
}
<span class="nc bnc" id="L342" title="All 2 branches missed."> } else if (kwic.output.equals(ComponentKwic.KWIC_OUTPUT_TOKEN)) {</span>
<span class="nc bnc" id="L343" title="All 2 branches missed."> for (int docId : kwic.tokens.keySet()) {</span>
<span class="nc" id="L344"> NamedList<Object> mtasKwicItemResponse = new SimpleOrderedMap<>();</span>
<span class="nc" id="L345"> List<KwicToken> list = kwic.tokens.get(docId);</span>
<span class="nc" id="L346"> List<NamedList<Object>> mtasKwicItemResponseItems = new ArrayList<>();</span>
<span class="nc bnc" id="L347" title="All 2 branches missed."> for (KwicToken k : list) {</span>
<span class="nc" id="L348"> NamedList<Object> mtasKwicItemResponseItem = new SimpleOrderedMap<>();</span>
<span class="nc" id="L349"> mtasKwicItemResponseItem.add("startPosition", k.startPosition);</span>
<span class="nc" id="L350"> mtasKwicItemResponseItem.add("endPosition", k.endPosition);</span>
<span class="nc" id="L351"> ArrayList<NamedList<Object>> mtasKwicItemResponseItemTokens = new ArrayList<>();</span>
<span class="nc bnc" id="L352" title="All 2 branches missed."> for (MtasToken token : k.tokens) {</span>
<span class="nc" id="L353"> NamedList<Object> mtasKwicItemResponseItemToken = new SimpleOrderedMap<>();</span>
<span class="nc bnc" id="L354" title="All 2 branches missed."> if (token.getId() != null) {</span>
<span class="nc" id="L355"> mtasKwicItemResponseItemToken.add("mtasId", token.getId());</span>
}
<span class="nc" id="L357"> mtasKwicItemResponseItemToken.add("prefix", token.getPrefix());</span>
<span class="nc" id="L358"> mtasKwicItemResponseItemToken.add("value", token.getPostfix());</span>
<span class="nc bnc" id="L359" title="All 2 branches missed."> if (token.getPositionStart() != null) {</span>
<span class="nc" id="L360"> mtasKwicItemResponseItemToken.add("positionStart",</span>
<span class="nc" id="L361"> token.getPositionStart());</span>
<span class="nc" id="L362"> mtasKwicItemResponseItemToken.add("positionEnd",</span>
<span class="nc" id="L363"> token.getPositionEnd());</span>
}
<span class="nc bnc" id="L365" title="All 2 branches missed."> if (token.getPositions() != null) {</span>
<span class="nc" id="L366"> mtasKwicItemResponseItemToken.add("positions",</span>
<span class="nc" id="L367"> Arrays.toString(token.getPositions()));</span>
}
<span class="nc bnc" id="L369" title="All 2 branches missed."> if (token.getParentId() != null) {</span>
<span class="nc" id="L370"> mtasKwicItemResponseItemToken.add("parentMtasId",</span>
<span class="nc" id="L371"> token.getParentId());</span>
}
<span class="nc bnc" id="L373" title="All 2 branches missed."> if (token.getPayload() != null) {</span>
<span class="nc" id="L374"> mtasKwicItemResponseItemToken.add("payload", token.getPayload());</span>
}
<span class="nc bnc" id="L376" title="All 2 branches missed."> if (token.getOffsetStart() != null) {</span>
<span class="nc" id="L377"> mtasKwicItemResponseItemToken.add("offsetStart",</span>
<span class="nc" id="L378"> token.getOffsetStart());</span>
<span class="nc" id="L379"> mtasKwicItemResponseItemToken.add("offsetEnd",</span>
<span class="nc" id="L380"> token.getOffsetEnd());</span>
}
<span class="nc bnc" id="L382" title="All 2 branches missed."> if (token.getRealOffsetStart() != null) {</span>
<span class="nc" id="L383"> mtasKwicItemResponseItemToken.add("realOffsetStart",</span>
<span class="nc" id="L384"> token.getRealOffsetStart());</span>
<span class="nc" id="L385"> mtasKwicItemResponseItemToken.add("realOffsetEnd",</span>
<span class="nc" id="L386"> token.getRealOffsetEnd());</span>
}
<span class="nc" id="L388"> mtasKwicItemResponseItemTokens.add(mtasKwicItemResponseItemToken);</span>
}
<span class="nc" id="L390"> mtasKwicItemResponseItem.add("tokens",</span>
<span class="nc" id="L391"> mtasKwicItemResponseItemTokens);</span>
<span class="nc" id="L392"> mtasKwicItemResponseItems.add(mtasKwicItemResponseItem);</span>
}
<span class="nc" id="L394"> mtasKwicItemResponse.add("documentKey", kwic.uniqueKey.get(docId));</span>
<span class="nc" id="L395"> mtasKwicItemResponse.add("documentTotal", kwic.subTotal.get(docId));</span>
<span class="nc" id="L396"> mtasKwicItemResponse.add("documentMinPosition",</span>
<span class="nc" id="L397"> kwic.minPosition.get(docId));</span>
<span class="nc" id="L398"> mtasKwicItemResponse.add("documentMaxPosition",</span>
<span class="nc" id="L399"> kwic.maxPosition.get(docId));</span>
<span class="nc" id="L400"> mtasKwicItemResponse.add("list", mtasKwicItemResponseItems);</span>
<span class="nc" id="L401"> mtasKwicItemResponses.add(mtasKwicItemResponse);</span>
}
}
<span class="nc" id="L404"> mtasKwicResponse.add("list", mtasKwicItemResponses);</span>
<span class="nc" id="L405"> 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="L419" title="All 2 branches missed."> if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) {</span>
<span class="nc bnc" id="L420" title="All 2 branches missed."> if (sreq.params.getBool(PARAM_MTAS_KWIC, false)</span>
<span class="nc bnc" id="L421" title="All 2 branches missed."> && (sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) != 0) {</span>
// do nothing
} else {
<span class="nc" id="L424"> Set<String> keys = MtasSolrResultUtil</span>
<span class="nc" id="L425"> .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_KWIC);</span>
<span class="nc" id="L426"> sreq.params.remove(PARAM_MTAS_KWIC);</span>
<span class="nc bnc" id="L427" title="All 2 branches missed."> for (String key : keys) {</span>
<span class="nc" id="L428"> sreq.params</span>
<span class="nc" id="L429"> .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_FIELD);</span>
<span class="nc" id="L430"> sreq.params.remove(</span>
<span class="nc" id="L431"> PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_TYPE);</span>
<span class="nc" id="L432"> sreq.params.remove(</span>
<span class="nc" id="L433"> PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_VALUE);</span>
<span class="nc" id="L434"> sreq.params.remove(</span>
<span class="nc" id="L435"> PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_PREFIX);</span>
<span class="nc" id="L436"> sreq.params.remove(</span>
<span class="nc" id="L437"> PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_QUERY_IGNORE);</span>
<span class="nc" id="L438"> sreq.params.remove(PARAM_MTAS_KWIC + "." + key + "."</span>
<span class="nc" id="L439"> + NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH);</span>
<span class="nc" id="L440"> sreq.params</span>
<span class="nc" id="L441"> .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_KEY);</span>
<span class="nc" id="L442"> sreq.params.remove(</span>
<span class="nc" id="L443"> PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_PREFIX);</span>
<span class="nc" id="L444"> sreq.params.remove(</span>
<span class="nc" id="L445"> PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_NUMBER);</span>
<span class="nc" id="L446"> sreq.params</span>
<span class="nc" id="L447"> .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_LEFT);</span>
<span class="nc" id="L448"> sreq.params</span>
<span class="nc" id="L449"> .remove(PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_RIGHT);</span>
<span class="nc" id="L450"> sreq.params.remove(</span>
<span class="nc" id="L451"> PARAM_MTAS_KWIC + "." + key + "." + NAME_MTAS_KWIC_OUTPUT);</span>
}
}
}
<span class="nc" id="L455"> }</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="L465" title="All 2 branches missed."> if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="nc bnc" id="L466" title="All 2 branches missed."> && rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY</span>
<span class="nc bnc" id="L467" title="All 2 branches missed."> && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {</span>
<span class="nc bnc" id="L468" title="All 2 branches missed."> for (ShardRequest sreq : rb.finished) {</span>
<span class="nc bnc" id="L469" title="All 2 branches missed."> if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="nc" id="L470"> && sreq.params.getBool(PARAM_MTAS_KWIC, false)) {</span>
// nothing to do
}
}
}
<span class="nc" id="L475"> }</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="L488"> }</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>