MtasSolrComponentGroup.java.html
37.3 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
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
<?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>MtasSolrComponentGroup.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">MtasSolrComponentGroup.java</span></div><h1>MtasSolrComponentGroup.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.SortedSet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.solr.common.params.SolrParams;
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 org.apache.solr.handler.component.ShardResponse;
import mtas.codec.util.CodecComponent.ComponentField;
import mtas.codec.util.CodecComponent.ComponentFields;
import mtas.codec.util.CodecComponent.ComponentGroup;
import mtas.search.spans.util.MtasSpanQuery;
import mtas.solr.handler.component.MtasSolrSearchComponent;
/**
* The Class MtasSolrComponentGroup.
*/
public class MtasSolrComponentGroup
implements MtasSolrComponent<ComponentGroup> {
/** The Constant log. */
<span class="fc" id="L33"> private static final Log log = LogFactory</span>
<span class="fc" id="L34"> .getLog(MtasSolrComponentGroup.class);</span>
/** The search component. */
MtasSolrSearchComponent searchComponent;
/** The Constant PARAM_MTAS_GROUP. */
public static final String PARAM_MTAS_GROUP = MtasSolrSearchComponent.PARAM_MTAS
+ ".group";
/** The Constant NAME_MTAS_GROUP_FIELD. */
public static final String NAME_MTAS_GROUP_FIELD = "field";
/** The Constant NAME_MTAS_GROUP_QUERY_TYPE. */
public static final String NAME_MTAS_GROUP_QUERY_TYPE = "query.type";
/** The Constant NAME_MTAS_GROUP_QUERY_VALUE. */
public static final String NAME_MTAS_GROUP_QUERY_VALUE = "query.value";
/** The Constant NAME_MTAS_GROUP_QUERY_PREFIX. */
public static final String NAME_MTAS_GROUP_QUERY_PREFIX = "query.prefix";
/** The Constant NAME_MTAS_GROUP_QUERY_IGNORE. */
public static final String NAME_MTAS_GROUP_QUERY_IGNORE = "query.ignore";
/** The Constant NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH. */
public static final String NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH = "query.maximumIgnoreLength";
/** The Constant NAME_MTAS_GROUP_QUERY_VARIABLE. */
public static final String NAME_MTAS_GROUP_QUERY_VARIABLE = "query.variable";
/** The Constant SUBNAME_MTAS_GROUP_QUERY_VARIABLE_NAME. */
public static final String SUBNAME_MTAS_GROUP_QUERY_VARIABLE_NAME = "name";
/** The Constant SUBNAME_MTAS_GROUP_QUERY_VARIABLE_VALUE. */
public static final String SUBNAME_MTAS_GROUP_QUERY_VARIABLE_VALUE = "value";
/** The Constant NAME_MTAS_GROUP_KEY. */
public static final String NAME_MTAS_GROUP_KEY = "key";
/** The Constant NAME_MTAS_GROUP_NUMBER. */
public static final String NAME_MTAS_GROUP_NUMBER = "number";
/** The Constant NAME_MTAS_GROUP_START. */
public static final String NAME_MTAS_GROUP_START = "start";
/** The Constant NAME_MTAS_GROUP_GROUPING_LEFT. */
public static final String NAME_MTAS_GROUP_GROUPING_LEFT = "grouping.left";
/** The Constant NAME_MTAS_GROUP_GROUPING_RIGHT. */
public static final String NAME_MTAS_GROUP_GROUPING_RIGHT = "grouping.right";
/** The Constant NAME_MTAS_GROUP_GROUPING_HIT_INSIDE. */
public static final String NAME_MTAS_GROUP_GROUPING_HIT_INSIDE = "grouping.hit.inside";
/** The Constant NAME_MTAS_GROUP_GROUPING_HIT_LEFT. */
public static final String NAME_MTAS_GROUP_GROUPING_HIT_LEFT = "grouping.hit.left";
/** The Constant NAME_MTAS_GROUP_GROUPING_HIT_RIGHT. */
public static final String NAME_MTAS_GROUP_GROUPING_HIT_RIGHT = "grouping.hit.right";
/** The Constant NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT. */
public static final String NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT = "grouping.hit.insideLeft";
/** The Constant NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT. */
public static final String NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT = "grouping.hit.insideRight";
/** The Constant NAME_MTAS_GROUP_GROUPING_POSITION. */
public static final String NAME_MTAS_GROUP_GROUPING_POSITION = "position";
/** The Constant NAME_MTAS_GROUP_GROUPING_PREFIXES. */
public static final String NAME_MTAS_GROUP_GROUPING_PREFIXES = "prefixes";
/** The Constant DEFAULT_NUMBER. */
private static final int DEFAULT_NUMBER = 10;
/**
* Instantiates a new mtas solr component group.
*
* @param searchComponent
* the search component
*/
<span class="fc" id="L115"> public MtasSolrComponentGroup(MtasSolrSearchComponent searchComponent) {</span>
<span class="fc" id="L116"> this.searchComponent = searchComponent;</span>
<span class="fc" id="L117"> }</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="fc" id="L129"> Set<String> ids = MtasSolrResultUtil</span>
<span class="fc" id="L130"> .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_GROUP);</span>
<span class="pc bpc" id="L131" title="1 of 2 branches missed."> if (!ids.isEmpty()) {</span>
<span class="fc" id="L132"> int tmpCounter = 0;</span>
<span class="fc" id="L133"> String[] fields = new String[ids.size()];</span>
<span class="fc" id="L134"> String[] queryTypes = new String[ids.size()];</span>
<span class="fc" id="L135"> String[] queryValues = new String[ids.size()];</span>
<span class="fc" id="L136"> String[] queryPrefixes = new String[ids.size()];</span>
<span class="fc" id="L137"> String[] queryIgnores = new String[ids.size()];</span>
<span class="fc" id="L138"> String[] queryMaximumIgnoreLengths = new String[ids.size()];</span>
<span class="fc" id="L139"> HashMap<String, String[]>[] queryVariables = new HashMap[ids.size()];</span>
<span class="fc" id="L140"> String[] keys = new String[ids.size()];</span>
<span class="fc" id="L141"> String[] numbers = new String[ids.size()];</span>
<span class="fc" id="L142"> String[] starts = new String[ids.size()];</span>
<span class="fc" id="L143"> String[][] groupingLeftPosition = new String[ids.size()][];</span>
<span class="fc" id="L144"> String[][] groupingLeftPrefixes = new String[ids.size()][];</span>
<span class="fc" id="L145"> String[][] groupingRightPosition = new String[ids.size()][];</span>
<span class="fc" id="L146"> String[][] groupingRightPrefixes = new String[ids.size()][];</span>
<span class="fc" id="L147"> String[] groupingHitInsidePrefixes = new String[ids.size()];</span>
<span class="fc" id="L148"> String[][] groupingHitLeftPosition = new String[ids.size()][];</span>
<span class="fc" id="L149"> String[][] groupingHitLeftPrefixes = new String[ids.size()][];</span>
<span class="fc" id="L150"> String[][] groupingHitRightPosition = new String[ids.size()][];</span>
<span class="fc" id="L151"> String[][] groupingHitRightPrefixes = new String[ids.size()][];</span>
<span class="fc" id="L152"> String[][] groupingHitInsideLeftPosition = new String[ids.size()][];</span>
<span class="fc" id="L153"> String[][] groupingHitInsideLeftPrefixes = new String[ids.size()][];</span>
<span class="fc" id="L154"> String[][] groupingHitInsideRightPosition = new String[ids.size()][];</span>
<span class="fc" id="L155"> String[][] groupingHitInsideRightPrefixes = new String[ids.size()][];</span>
<span class="fc bfc" id="L156" title="All 2 branches covered."> for (String id : ids) {</span>
<span class="fc" id="L157"> fields[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_FIELD, null);
<span class="fc" id="L159"> keys[tmpCounter] = rb.req.getParams()</span>
<span class="fc" id="L160"> .get(PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_KEY,</span>
<span class="fc" id="L161"> String.valueOf(tmpCounter))</span>
<span class="fc" id="L162"> .trim();</span>
<span class="fc" id="L163"> numbers[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_NUMBER, null);
<span class="fc" id="L165"> starts[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_START, null);
<span class="fc" id="L167"> queryTypes[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_QUERY_TYPE,
null);
<span class="fc" id="L170"> queryValues[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_QUERY_VALUE,
null);
<span class="fc" id="L173"> queryPrefixes[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_QUERY_PREFIX,
null);
<span class="fc" id="L176"> queryIgnores[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_QUERY_IGNORE,
null);
<span class="fc" id="L179"> queryMaximumIgnoreLengths[tmpCounter] = rb.req.getParams()</span>
<span class="fc" id="L180"> .get(PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH, null);
<span class="fc" id="L182"> Set<String> vIds = MtasSolrResultUtil.getIdsFromParameters(</span>
<span class="fc" id="L183"> rb.req.getParams(),</span>
PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_QUERY_VARIABLE);
<span class="fc" id="L185"> queryVariables[tmpCounter] = new HashMap<>();</span>
<span class="pc bpc" id="L186" title="1 of 2 branches missed."> if (!vIds.isEmpty()) {</span>
<span class="nc" id="L187"> HashMap<String, ArrayList<String>> tmpVariables = new HashMap<>();</span>
<span class="nc bnc" id="L188" title="All 2 branches missed."> for (String vId : vIds) {</span>
<span class="nc" id="L189"> String name = rb.req.getParams()</span>
<span class="nc" id="L190"> .get(PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_QUERY_VARIABLE + "." + vId + "."
+ SUBNAME_MTAS_GROUP_QUERY_VARIABLE_NAME, null);
<span class="nc bnc" id="L193" title="All 2 branches missed."> if (name != null) {</span>
<span class="nc bnc" id="L194" title="All 2 branches missed."> if (!tmpVariables.containsKey(name)) {</span>
<span class="nc" id="L195"> tmpVariables.put(name, new ArrayList<String>());</span>
}
<span class="nc" id="L197"> String value = rb.req.getParams()</span>
<span class="nc" id="L198"> .get(PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_QUERY_VARIABLE + "." + vId + "."
+ SUBNAME_MTAS_GROUP_QUERY_VARIABLE_VALUE, null);
<span class="nc bnc" id="L201" title="All 2 branches missed."> if (value != null) {</span>
<span class="nc" id="L202"> ArrayList<String> list = new ArrayList<>();</span>
<span class="nc" id="L203"> String[] subList = value.split("(?<!\\\\),");</span>
<span class="nc bnc" id="L204" title="All 2 branches missed."> for (int i = 0; i < subList.length; i++) {</span>
<span class="nc" id="L205"> list.add(</span>
<span class="nc" id="L206"> subList[i].replace("\\,", ",").replace("\\\\", "\\"));</span>
}
<span class="nc" id="L208"> tmpVariables.get(name).addAll(list);</span>
}
}
<span class="nc" id="L211"> }</span>
<span class="nc bnc" id="L212" title="All 2 branches missed."> for (Entry<String, ArrayList<String>> entry : tmpVariables</span>
<span class="nc" id="L213"> .entrySet()) {</span>
<span class="nc" id="L214"> queryVariables[tmpCounter].put(entry.getKey(),</span>
<span class="nc" id="L215"> entry.getValue().toArray(new String[entry.getValue().size()]));</span>
<span class="nc" id="L216"> }</span>
}
<span class="fc" id="L218"> groupingHitInsidePrefixes[tmpCounter] = null;</span>
// collect
SortedSet<String> gids;
String tmpName;
// collect grouping inside
<span class="fc" id="L223"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE;
<span class="fc" id="L225"> groupingHitInsidePrefixes[tmpCounter] = rb.req.getParams()</span>
<span class="fc" id="L226"> .get(tmpName + "." + NAME_MTAS_GROUP_GROUPING_PREFIXES);</span>
// collect grouping left
<span class="fc" id="L228"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_GROUPING_LEFT;
<span class="fc" id="L230"> gids = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
tmpName);
<span class="fc" id="L232"> groupingLeftPosition[tmpCounter] = new String[gids.size()];</span>
<span class="fc" id="L233"> groupingLeftPrefixes[tmpCounter] = new String[gids.size()];</span>
<span class="fc" id="L234"> prepare(rb.req.getParams(), gids, tmpName,</span>
groupingLeftPosition[tmpCounter], groupingLeftPrefixes[tmpCounter]);
// collect grouping right
<span class="fc" id="L237"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_GROUPING_RIGHT;
<span class="fc" id="L239"> gids = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
tmpName);
<span class="fc" id="L241"> groupingRightPosition[tmpCounter] = new String[gids.size()];</span>
<span class="fc" id="L242"> groupingRightPrefixes[tmpCounter] = new String[gids.size()];</span>
<span class="fc" id="L243"> prepare(rb.req.getParams(), gids, tmpName,</span>
groupingRightPosition[tmpCounter],
groupingRightPrefixes[tmpCounter]);
// collect grouping hit left
<span class="fc" id="L247"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_GROUPING_HIT_LEFT;
<span class="fc" id="L249"> gids = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
tmpName);
<span class="fc" id="L251"> groupingHitLeftPosition[tmpCounter] = new String[gids.size()];</span>
<span class="fc" id="L252"> groupingHitLeftPrefixes[tmpCounter] = new String[gids.size()];</span>
<span class="fc" id="L253"> prepare(rb.req.getParams(), gids, tmpName,</span>
groupingHitLeftPosition[tmpCounter],
groupingHitLeftPrefixes[tmpCounter]);
// collect grouping hit right
<span class="fc" id="L257"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_GROUPING_HIT_RIGHT;
<span class="fc" id="L259"> gids = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
tmpName);
<span class="fc" id="L261"> groupingHitRightPosition[tmpCounter] = new String[gids.size()];</span>
<span class="fc" id="L262"> groupingHitRightPrefixes[tmpCounter] = new String[gids.size()];</span>
<span class="fc" id="L263"> prepare(rb.req.getParams(), gids, tmpName,</span>
groupingHitRightPosition[tmpCounter],
groupingHitRightPrefixes[tmpCounter]);
// collect grouping hit inside left
<span class="fc" id="L267"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT;
<span class="fc" id="L269"> gids = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
tmpName);
<span class="fc" id="L271"> groupingHitInsideLeftPosition[tmpCounter] = new String[gids.size()];</span>
<span class="fc" id="L272"> groupingHitInsideLeftPrefixes[tmpCounter] = new String[gids.size()];</span>
<span class="fc" id="L273"> prepare(rb.req.getParams(), gids, tmpName,</span>
groupingHitInsideLeftPosition[tmpCounter],
groupingHitInsideLeftPrefixes[tmpCounter]);
// collect grouping hit inside right
<span class="fc" id="L277"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT;
<span class="fc" id="L279"> gids = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
tmpName);
<span class="fc" id="L281"> groupingHitInsideRightPosition[tmpCounter] = new String[gids.size()];</span>
<span class="fc" id="L282"> groupingHitInsideRightPrefixes[tmpCounter] = new String[gids.size()];</span>
<span class="fc" id="L283"> prepare(rb.req.getParams(), gids, tmpName,</span>
groupingHitInsideRightPosition[tmpCounter],
groupingHitInsideRightPrefixes[tmpCounter]);
<span class="fc" id="L287"> tmpCounter++;</span>
<span class="fc" id="L288"> }</span>
<span class="fc" id="L289"> String uniqueKeyField = rb.req.getSchema().getUniqueKeyField().getName();</span>
<span class="fc" id="L290"> mtasFields.doGroup = true;</span>
<span class="fc" id="L291"> rb.setNeedDocSet(true);</span>
<span class="fc bfc" id="L292" title="All 2 branches covered."> for (String field : fields) {</span>
<span class="pc bpc" id="L293" title="2 of 4 branches missed."> if (field == null || field.isEmpty()) {</span>
<span class="nc" id="L294"> throw new IOException("no (valid) field in mtas group");</span>
<span class="pc bpc" id="L295" title="1 of 2 branches missed."> } else if (!mtasFields.list.containsKey(field)) {</span>
<span class="fc" id="L296"> mtasFields.list.put(field, new ComponentField(uniqueKeyField));</span>
}
}
<span class="fc" id="L299"> MtasSolrResultUtil.compareAndCheck(keys, fields, NAME_MTAS_GROUP_KEY,</span>
<span class="fc" id="L300"> NAME_MTAS_GROUP_FIELD, true);</span>
<span class="fc" id="L301"> MtasSolrResultUtil.compareAndCheck(queryValues, fields,</span>
<span class="fc" id="L302"> NAME_MTAS_GROUP_QUERY_VALUE, NAME_MTAS_GROUP_FIELD, false);</span>
<span class="fc" id="L303"> MtasSolrResultUtil.compareAndCheck(queryTypes, fields,</span>
<span class="fc" id="L304"> NAME_MTAS_GROUP_QUERY_TYPE, NAME_MTAS_GROUP_FIELD, false);</span>
<span class="fc bfc" id="L305" title="All 2 branches covered."> for (int i = 0; i < fields.length; i++) {</span>
<span class="fc" id="L306"> ComponentField cf = mtasFields.list.get(fields[i]);</span>
<span class="pc bpc" id="L307" title="1 of 2 branches missed."> Integer maximumIgnoreLength = (queryMaximumIgnoreLengths[i] == null)</span>
<span class="pc" id="L308"> ? null : Integer.parseInt(queryMaximumIgnoreLengths[i]);</span>
<span class="fc" id="L309"> MtasSpanQuery q = MtasSolrResultUtil.constructQuery(queryValues[i],</span>
queryTypes[i], queryPrefixes[i], queryVariables[i], fields[i],
queryIgnores[i], maximumIgnoreLength);
// minimize number of queries
<span class="pc bpc" id="L313" title="1 of 2 branches missed."> if (cf.spanQueryList.contains(q)) {</span>
<span class="nc" id="L314"> q = cf.spanQueryList.get(cf.spanQueryList.indexOf(q));</span>
} else {
<span class="fc" id="L316"> cf.spanQueryList.add(q);</span>
}
<span class="pc bpc" id="L318" title="2 of 4 branches missed."> String key = (keys[i] == null) || (keys[i].isEmpty())</span>
<span class="pc" id="L319"> ? String.valueOf(i) + ":" + fields[i] + ":" + queryValues[i]</span>
<span class="fc" id="L320"> : keys[i].trim();</span>
<span class="pc bpc" id="L321" title="2 of 4 branches missed."> int number = (numbers[i] == null) || (numbers[i].isEmpty())</span>
<span class="fc" id="L322"> ? DEFAULT_NUMBER : Integer.parseInt(numbers[i]);</span>
<span class="pc bpc" id="L323" title="3 of 4 branches missed."> int start = (starts[i] == null) || (starts[i].isEmpty()) ? 0</span>
<span class="pc" id="L324"> : Integer.parseInt(starts[i]);</span>
<span class="fc" id="L325"> mtasFields.list.get(fields[i]).groupList.add(new ComponentGroup(q, key,</span>
number, start, groupingHitInsidePrefixes[i],
groupingHitInsideLeftPosition[i], groupingHitInsideLeftPrefixes[i],
groupingHitInsideRightPosition[i],
groupingHitInsideRightPrefixes[i], groupingHitLeftPosition[i],
groupingHitLeftPrefixes[i], groupingHitRightPosition[i],
groupingHitRightPrefixes[i], groupingLeftPosition[i],
groupingLeftPrefixes[i], groupingRightPosition[i],
groupingRightPrefixes[i]));
}
}
<span class="fc" id="L336"> }</span>
/**
* Prepare.
*
* @param solrParams
* the solr params
* @param gids
* the gids
* @param name
* the name
* @param positions
* the positions
* @param prefixes
* the prefixes
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private void prepare(SolrParams solrParams, SortedSet<String> gids,
String name, String[] positions, String[] prefixes) throws IOException {
<span class="fc bfc" id="L356" title="All 2 branches covered."> if (!gids.isEmpty()) {</span>
<span class="fc" id="L357"> int tmpSubCounter = 0;</span>
<span class="fc bfc" id="L358" title="All 2 branches covered."> for (String gid : gids) {</span>
<span class="fc" id="L359"> positions[tmpSubCounter] = solrParams.get(</span>
name + "." + gid + "." + NAME_MTAS_GROUP_GROUPING_POSITION, null);
<span class="fc" id="L361"> prefixes[tmpSubCounter] = solrParams.get(</span>
name + "." + gid + "." + NAME_MTAS_GROUP_GROUPING_PREFIXES, null);
<span class="pc bpc" id="L363" title="1 of 2 branches missed."> if (positions[tmpSubCounter] == null) {</span>
<span class="nc" id="L364"> throw new IOException("no position for " + gid);</span>
<span class="pc bpc" id="L365" title="1 of 2 branches missed."> } else if (prefixes[tmpSubCounter] == null) {</span>
<span class="nc" id="L366"> throw new IOException("no prefix for " + gid);</span>
}
<span class="fc" id="L368"> tmpSubCounter++;</span>
<span class="fc" id="L369"> }</span>
}
<span class="fc" id="L371"> }</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="L384" title="All 2 branches missed."> if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="nc bnc" id="L385" title="All 2 branches missed."> && sreq.params.getBool(PARAM_MTAS_GROUP, false)) {</span>
<span class="nc bnc" id="L386" title="All 2 branches missed."> if ((sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) {</span>
//do nothing
// Set<String> keys = MtasSolrResultUtil
// .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_GROUP);
// for (String key : keys) {
// sreq.params.remove(
// PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_NUMBER);
// sreq.params.remove(
// PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_START);
// }
} else {
// remove prefix for other requests
<span class="nc" id="L398"> Set<String> keys = MtasSolrResultUtil</span>
<span class="nc" id="L399"> .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_GROUP);</span>
<span class="nc" id="L400"> sreq.params.remove(PARAM_MTAS_GROUP);</span>
Set<String> subKeys;
<span class="nc bnc" id="L402" title="All 2 branches missed."> for (String key : keys) {</span>
<span class="nc" id="L403"> sreq.params.remove(</span>
PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_FIELD);
<span class="nc" id="L405"> sreq.params</span>
<span class="nc" id="L406"> .remove(PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_KEY);</span>
<span class="nc" id="L407"> sreq.params.remove(</span>
PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_NUMBER);
<span class="nc" id="L409"> sreq.params.remove(</span>
PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_START);
<span class="nc" id="L411"> sreq.params.remove(</span>
PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_QUERY_TYPE);
<span class="nc" id="L413"> sreq.params.remove(</span>
PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_QUERY_VALUE);
<span class="nc" id="L415"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_QUERY_PREFIX);
<span class="nc" id="L417"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_QUERY_IGNORE);
<span class="nc" id="L419"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH);
<span class="nc" id="L421"> subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
PARAM_MTAS_GROUP + "." + key + "."
+ NAME_MTAS_GROUP_GROUPING_LEFT);
<span class="nc bnc" id="L424" title="All 2 branches missed."> for (String subKey : subKeys) {</span>
<span class="nc" id="L425"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_GROUPING_LEFT + "." + subKey + "."
+ NAME_MTAS_GROUP_GROUPING_POSITION);
<span class="nc" id="L428"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_GROUPING_LEFT + "." + subKey + "."
+ NAME_MTAS_GROUP_GROUPING_PREFIXES);
<span class="nc" id="L431"> }</span>
<span class="nc" id="L432"> subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
PARAM_MTAS_GROUP + "." + key + "."
+ NAME_MTAS_GROUP_GROUPING_RIGHT);
<span class="nc bnc" id="L435" title="All 2 branches missed."> for (String subKey : subKeys) {</span>
<span class="nc" id="L436"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_GROUPING_RIGHT + "." + subKey + "."
+ NAME_MTAS_GROUP_GROUPING_POSITION);
<span class="nc" id="L439"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_GROUPING_RIGHT + "." + subKey + "."
+ NAME_MTAS_GROUP_GROUPING_PREFIXES);
<span class="nc" id="L442"> }</span>
<span class="nc" id="L443"> subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
PARAM_MTAS_GROUP + "." + key + "."
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE);
<span class="nc bnc" id="L446" title="All 2 branches missed."> for (String subKey : subKeys) {</span>
<span class="nc" id="L447"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE + "." + subKey + "."
+ NAME_MTAS_GROUP_GROUPING_POSITION);
<span class="nc" id="L450"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE + "." + subKey + "."
+ NAME_MTAS_GROUP_GROUPING_PREFIXES);
<span class="nc" id="L453"> }</span>
<span class="nc" id="L454"> subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
PARAM_MTAS_GROUP + "." + key + "."
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT);
<span class="nc bnc" id="L457" title="All 2 branches missed."> for (String subKey : subKeys) {</span>
<span class="nc" id="L458"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT + "." + subKey + "."
+ NAME_MTAS_GROUP_GROUPING_POSITION);
<span class="nc" id="L461"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT + "." + subKey + "."
+ NAME_MTAS_GROUP_GROUPING_PREFIXES);
<span class="nc" id="L464"> }</span>
<span class="nc" id="L465"> subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
PARAM_MTAS_GROUP + "." + key + "."
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT);
<span class="nc bnc" id="L468" title="All 2 branches missed."> for (String subKey : subKeys) {</span>
<span class="nc" id="L469"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT + "." + subKey + "."
+ NAME_MTAS_GROUP_GROUPING_POSITION);
<span class="nc" id="L472"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT + "." + subKey + "."
+ NAME_MTAS_GROUP_GROUPING_PREFIXES);
<span class="nc" id="L475"> }</span>
<span class="nc" id="L476"> }</span>
}
}
<span class="nc" id="L479"> }</span>
/*
* (non-Javadoc)
*
* @see
* mtas.solr.handler.component.util.MtasSolrComponent#create(mtas.codec.util.
* CodecComponent.BasicComponent, java.lang.Boolean)
*/
@SuppressWarnings("unchecked")
public SimpleOrderedMap<Object> create(ComponentGroup group, Boolean encode)
throws IOException {
<span class="fc" id="L491"> SimpleOrderedMap<Object> mtasGroupResponse = new SimpleOrderedMap<>();</span>
<span class="fc" id="L492"> mtasGroupResponse.add("key", group.key);</span>
<span class="fc" id="L493"> MtasSolrMtasResult data = new MtasSolrMtasResult(group.dataCollector,</span>
new String[] { group.dataType }, new String[] { group.statsType },
new SortedSet[] { group.statsItems }, new List[] {null}, new String[] { group.sortType },
new String[] { group.sortDirection }, new Integer[] { group.start },
new Integer[] { group.number }, null);
<span class="pc bpc" id="L498" title="1 of 2 branches missed."> if (encode) {</span>
<span class="nc" id="L499"> mtasGroupResponse.add("_encoded_list", MtasSolrResultUtil.encode(data));</span>
} else {
<span class="fc" id="L501"> mtasGroupResponse.add("list", data);</span>
<span class="fc" id="L502"> MtasSolrResultUtil.rewrite(mtasGroupResponse, searchComponent);</span>
}
<span class="fc" id="L504"> return mtasGroupResponse;</span>
}
/*
* (non-Javadoc)
*
* @see
* mtas.solr.handler.component.util.MtasSolrComponent#finishStage(org.apache.
* solr.handler.component.ResponseBuilder)
*/
@SuppressWarnings("unchecked")
public void finishStage(ResponseBuilder rb) {
<span class="nc bnc" id="L516" 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) {
//decode finished results
<span class="nc bnc" id="L520" title="All 2 branches missed."> for (ShardRequest sreq : rb.finished) {</span>
<span class="nc bnc" id="L521" title="All 2 branches missed."> if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="nc bnc" id="L522" title="All 2 branches missed."> && sreq.params.getBool(PARAM_MTAS_GROUP, false)) {</span>
<span class="nc bnc" id="L523" title="All 2 branches missed."> for (ShardResponse shardResponse : sreq.responses) {</span>
<span class="nc" id="L524"> NamedList<Object> response = shardResponse.getSolrResponse()</span>
<span class="nc" id="L525"> .getResponse();</span>
try {
<span class="nc" id="L527"> ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response</span>
<span class="nc" id="L528"> .findRecursive("mtas", "group");</span>
<span class="nc bnc" id="L529" title="All 2 branches missed."> if (data != null) {</span>
<span class="nc" id="L530"> MtasSolrResultUtil.decode(data);</span>
}
<span class="nc" id="L532"> } catch (ClassCastException e) {</span>
<span class="nc" id="L533"> log.debug(e);</span>
// shouldn't happen
<span class="nc" id="L535"> }</span>
<span class="nc" id="L536"> }</span>
}
<span class="nc" id="L538"> }</span>
}
<span class="nc" id="L540"> }</span>
/*
* (non-Javadoc)
*
* @see
* mtas.solr.handler.component.util.MtasSolrComponent#distributedProcess(org.
* apache.solr.handler.component.ResponseBuilder,
* mtas.codec.util.CodecComponent.ComponentFields)
*/
@SuppressWarnings("unchecked")
public void distributedProcess(ResponseBuilder rb, ComponentFields mtasFields)
throws IOException {
// rewrite
<span class="nc" id="L554"> NamedList<Object> mtasResponse = null;</span>
try {
<span class="nc" id="L556"> mtasResponse = (NamedList<Object>) rb.rsp.getValues().get("mtas");</span>
<span class="nc" id="L557"> } catch (ClassCastException e) {</span>
<span class="nc" id="L558"> log.debug(e);</span>
<span class="nc" id="L559"> mtasResponse = null;</span>
<span class="nc" id="L560"> }</span>
<span class="nc bnc" id="L561" title="All 2 branches missed."> if (mtasResponse != null) {</span>
ArrayList<Object> mtasResponseGroup;
try {
<span class="nc" id="L564"> mtasResponseGroup = (ArrayList<Object>) mtasResponse.get("group");</span>
<span class="nc bnc" id="L565" title="All 2 branches missed."> if (mtasResponseGroup != null) {</span>
<span class="nc" id="L566"> MtasSolrResultUtil.rewrite(mtasResponseGroup, searchComponent);</span>
}
<span class="nc" id="L568"> } catch (ClassCastException e) {</span>
<span class="nc" id="L569"> log.debug(e);</span>
<span class="nc" id="L570"> mtasResponse.remove("group");</span>
<span class="nc" id="L571"> }</span>
}
<span class="nc" id="L573"> }</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>