MtasSolrComponentGroup.java.html
35.8 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
<?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.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="L32"> private static final Log log = LogFactory</span>
<span class="fc" id="L33"> .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_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="L110"> public MtasSolrComponentGroup(MtasSolrSearchComponent searchComponent) {</span>
<span class="fc" id="L111"> this.searchComponent = searchComponent;</span>
<span class="fc" id="L112"> }</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="L124"> Set<String> ids = MtasSolrResultUtil</span>
<span class="nc" id="L125"> .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_GROUP);</span>
<span class="nc bnc" id="L126" title="All 2 branches missed."> if (!ids.isEmpty()) {</span>
<span class="nc" id="L127"> int tmpCounter = 0;</span>
<span class="nc" id="L128"> String[] fields = new String[ids.size()];</span>
<span class="nc" id="L129"> String[] queryTypes = new String[ids.size()];</span>
<span class="nc" id="L130"> String[] queryValues = new String[ids.size()];</span>
<span class="nc" id="L131"> String[] queryPrefixes = new String[ids.size()];</span>
<span class="nc" id="L132"> String[] queryIgnores = new String[ids.size()];</span>
<span class="nc" id="L133"> String[] queryMaximumIgnoreLengths = new String[ids.size()];</span>
<span class="nc" id="L134"> HashMap<String, String[]>[] queryVariables = new HashMap[ids.size()];</span>
<span class="nc" id="L135"> String[] keys = new String[ids.size()];</span>
<span class="nc" id="L136"> String[] numbers = new String[ids.size()];</span>
<span class="nc" id="L137"> String[][] groupingLeftPosition = new String[ids.size()][];</span>
<span class="nc" id="L138"> String[][] groupingLeftPrefixes = new String[ids.size()][];</span>
<span class="nc" id="L139"> String[][] groupingRightPosition = new String[ids.size()][];</span>
<span class="nc" id="L140"> String[][] groupingRightPrefixes = new String[ids.size()][];</span>
<span class="nc" id="L141"> String[] groupingHitInsidePrefixes = new String[ids.size()];</span>
<span class="nc" id="L142"> String[][] groupingHitLeftPosition = new String[ids.size()][];</span>
<span class="nc" id="L143"> String[][] groupingHitLeftPrefixes = new String[ids.size()][];</span>
<span class="nc" id="L144"> String[][] groupingHitRightPosition = new String[ids.size()][];</span>
<span class="nc" id="L145"> String[][] groupingHitRightPrefixes = new String[ids.size()][];</span>
<span class="nc" id="L146"> String[][] groupingHitInsideLeftPosition = new String[ids.size()][];</span>
<span class="nc" id="L147"> String[][] groupingHitInsideLeftPrefixes = new String[ids.size()][];</span>
<span class="nc" id="L148"> String[][] groupingHitInsideRightPosition = new String[ids.size()][];</span>
<span class="nc" id="L149"> String[][] groupingHitInsideRightPrefixes = new String[ids.size()][];</span>
<span class="nc bnc" id="L150" title="All 2 branches missed."> for (String id : ids) {</span>
<span class="nc" id="L151"> fields[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_FIELD, null);
<span class="nc" id="L153"> keys[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L154"> .get(PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_KEY,</span>
<span class="nc" id="L155"> String.valueOf(tmpCounter))</span>
<span class="nc" id="L156"> .trim();</span>
<span class="nc" id="L157"> numbers[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_NUMBER, null);
<span class="nc" id="L159"> queryTypes[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_QUERY_TYPE,
null);
<span class="nc" id="L162"> queryValues[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_QUERY_VALUE,
null);
<span class="nc" id="L165"> queryPrefixes[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_QUERY_PREFIX,
null);
<span class="nc" id="L168"> queryIgnores[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_QUERY_IGNORE,
null);
<span class="nc" id="L171"> queryMaximumIgnoreLengths[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L172"> .get(PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH, null);
<span class="nc" id="L174"> Set<String> vIds = MtasSolrResultUtil.getIdsFromParameters(</span>
<span class="nc" id="L175"> rb.req.getParams(),</span>
PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_QUERY_VARIABLE);
<span class="nc" id="L177"> queryVariables[tmpCounter] = new HashMap<>();</span>
<span class="nc bnc" id="L178" title="All 2 branches missed."> if (!vIds.isEmpty()) {</span>
<span class="nc" id="L179"> HashMap<String, ArrayList<String>> tmpVariables = new HashMap<>();</span>
<span class="nc bnc" id="L180" title="All 2 branches missed."> for (String vId : vIds) {</span>
<span class="nc" id="L181"> String name = rb.req.getParams()</span>
<span class="nc" id="L182"> .get(PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_QUERY_VARIABLE + "." + vId + "."
+ SUBNAME_MTAS_GROUP_QUERY_VARIABLE_NAME, null);
<span class="nc bnc" id="L185" title="All 2 branches missed."> if (name != null) {</span>
<span class="nc bnc" id="L186" title="All 2 branches missed."> if (!tmpVariables.containsKey(name)) {</span>
<span class="nc" id="L187"> tmpVariables.put(name, new ArrayList<String>());</span>
}
<span class="nc" id="L189"> String value = 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_VALUE, null);
<span class="nc bnc" id="L193" title="All 2 branches missed."> if (value != null) {</span>
<span class="nc" id="L194"> ArrayList<String> list = new ArrayList<>();</span>
<span class="nc" id="L195"> String[] subList = value.split("(?<!\\\\),");</span>
<span class="nc bnc" id="L196" title="All 2 branches missed."> for (int i = 0; i < subList.length; i++) {</span>
<span class="nc" id="L197"> list.add(</span>
<span class="nc" id="L198"> subList[i].replace("\\,", ",").replace("\\\\", "\\"));</span>
}
<span class="nc" id="L200"> tmpVariables.get(name).addAll(list);</span>
}
}
<span class="nc" id="L203"> }</span>
<span class="nc bnc" id="L204" title="All 2 branches missed."> for (Entry<String, ArrayList<String>> entry : tmpVariables</span>
<span class="nc" id="L205"> .entrySet()) {</span>
<span class="nc" id="L206"> queryVariables[tmpCounter].put(entry.getKey(),</span>
<span class="nc" id="L207"> entry.getValue().toArray(new String[entry.getValue().size()]));</span>
<span class="nc" id="L208"> }</span>
}
<span class="nc" id="L210"> groupingHitInsidePrefixes[tmpCounter] = null;</span>
// collect
SortedSet<String> gids;
String tmpName;
// collect grouping inside
<span class="nc" id="L215"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE;
<span class="nc" id="L217"> groupingHitInsidePrefixes[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L218"> .get(tmpName + "." + NAME_MTAS_GROUP_GROUPING_PREFIXES);</span>
// collect grouping left
<span class="nc" id="L220"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_GROUPING_LEFT;
<span class="nc" id="L222"> gids = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
tmpName);
<span class="nc" id="L224"> groupingLeftPosition[tmpCounter] = new String[gids.size()];</span>
<span class="nc" id="L225"> groupingLeftPrefixes[tmpCounter] = new String[gids.size()];</span>
<span class="nc" id="L226"> prepare(rb.req.getParams(), gids, tmpName,</span>
groupingLeftPosition[tmpCounter], groupingLeftPrefixes[tmpCounter]);
// collect grouping right
<span class="nc" id="L229"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_GROUPING_RIGHT;
<span class="nc" id="L231"> gids = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
tmpName);
<span class="nc" id="L233"> groupingRightPosition[tmpCounter] = new String[gids.size()];</span>
<span class="nc" id="L234"> groupingRightPrefixes[tmpCounter] = new String[gids.size()];</span>
<span class="nc" id="L235"> prepare(rb.req.getParams(), gids, tmpName,</span>
groupingRightPosition[tmpCounter],
groupingRightPrefixes[tmpCounter]);
// collect grouping hit left
<span class="nc" id="L239"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_GROUPING_HIT_LEFT;
<span class="nc" id="L241"> gids = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
tmpName);
<span class="nc" id="L243"> groupingHitLeftPosition[tmpCounter] = new String[gids.size()];</span>
<span class="nc" id="L244"> groupingHitLeftPrefixes[tmpCounter] = new String[gids.size()];</span>
<span class="nc" id="L245"> prepare(rb.req.getParams(), gids, tmpName,</span>
groupingHitLeftPosition[tmpCounter],
groupingHitLeftPrefixes[tmpCounter]);
// collect grouping hit right
<span class="nc" id="L249"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_GROUPING_HIT_RIGHT;
<span class="nc" id="L251"> gids = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
tmpName);
<span class="nc" id="L253"> groupingHitRightPosition[tmpCounter] = new String[gids.size()];</span>
<span class="nc" id="L254"> groupingHitRightPrefixes[tmpCounter] = new String[gids.size()];</span>
<span class="nc" id="L255"> prepare(rb.req.getParams(), gids, tmpName,</span>
groupingHitRightPosition[tmpCounter],
groupingHitRightPrefixes[tmpCounter]);
// collect grouping hit inside left
<span class="nc" id="L259"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT;
<span class="nc" id="L261"> gids = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
tmpName);
<span class="nc" id="L263"> groupingHitInsideLeftPosition[tmpCounter] = new String[gids.size()];</span>
<span class="nc" id="L264"> groupingHitInsideLeftPrefixes[tmpCounter] = new String[gids.size()];</span>
<span class="nc" id="L265"> prepare(rb.req.getParams(), gids, tmpName,</span>
groupingHitInsideLeftPosition[tmpCounter],
groupingHitInsideLeftPrefixes[tmpCounter]);
// collect grouping hit inside right
<span class="nc" id="L269"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span>
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT;
<span class="nc" id="L271"> gids = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
tmpName);
<span class="nc" id="L273"> groupingHitInsideRightPosition[tmpCounter] = new String[gids.size()];</span>
<span class="nc" id="L274"> groupingHitInsideRightPrefixes[tmpCounter] = new String[gids.size()];</span>
<span class="nc" id="L275"> prepare(rb.req.getParams(), gids, tmpName,</span>
groupingHitInsideRightPosition[tmpCounter],
groupingHitInsideRightPrefixes[tmpCounter]);
<span class="nc" id="L279"> tmpCounter++;</span>
<span class="nc" id="L280"> }</span>
<span class="nc" id="L281"> String uniqueKeyField = rb.req.getSchema().getUniqueKeyField().getName();</span>
<span class="nc" id="L282"> mtasFields.doGroup = true;</span>
<span class="nc" id="L283"> rb.setNeedDocSet(true);</span>
<span class="nc bnc" id="L284" title="All 2 branches missed."> for (String field : fields) {</span>
<span class="nc bnc" id="L285" title="All 4 branches missed."> if (field == null || field.isEmpty()) {</span>
<span class="nc" id="L286"> throw new IOException("no (valid) field in mtas group");</span>
<span class="nc bnc" id="L287" title="All 2 branches missed."> } else if (!mtasFields.list.containsKey(field)) {</span>
<span class="nc" id="L288"> mtasFields.list.put(field, new ComponentField(uniqueKeyField));</span>
}
}
<span class="nc" id="L291"> MtasSolrResultUtil.compareAndCheck(keys, fields, NAME_MTAS_GROUP_KEY,</span>
<span class="nc" id="L292"> NAME_MTAS_GROUP_FIELD, true);</span>
<span class="nc" id="L293"> MtasSolrResultUtil.compareAndCheck(queryValues, fields,</span>
<span class="nc" id="L294"> NAME_MTAS_GROUP_QUERY_VALUE, NAME_MTAS_GROUP_FIELD, false);</span>
<span class="nc" id="L295"> MtasSolrResultUtil.compareAndCheck(queryTypes, fields,</span>
<span class="nc" id="L296"> NAME_MTAS_GROUP_QUERY_TYPE, NAME_MTAS_GROUP_FIELD, false);</span>
<span class="nc bnc" id="L297" title="All 2 branches missed."> for (int i = 0; i < fields.length; i++) {</span>
<span class="nc" id="L298"> ComponentField cf = mtasFields.list.get(fields[i]);</span>
<span class="nc bnc" id="L299" title="All 2 branches missed."> Integer maximumIgnoreLength = (queryMaximumIgnoreLengths[i] == null)</span>
<span class="nc" id="L300"> ? null : Integer.parseInt(queryMaximumIgnoreLengths[i]);</span>
<span class="nc" id="L301"> 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="L305" title="All 2 branches missed."> if (cf.spanQueryList.contains(q)) {</span>
<span class="nc" id="L306"> q = cf.spanQueryList.get(cf.spanQueryList.indexOf(q));</span>
} else {
<span class="nc" id="L308"> cf.spanQueryList.add(q);</span>
}
<span class="nc bnc" id="L310" title="All 4 branches missed."> String key = (keys[i] == null) || (keys[i].isEmpty())</span>
<span class="nc" id="L311"> ? String.valueOf(i) + ":" + fields[i] + ":" + queryValues[i]</span>
<span class="nc" id="L312"> : keys[i].trim();</span>
<span class="nc bnc" id="L313" title="All 4 branches missed."> int number = (numbers[i] == null) || (numbers[i].isEmpty())</span>
<span class="nc" id="L314"> ? DEFAULT_NUMBER : Integer.parseInt(numbers[i]);</span>
<span class="nc" id="L315"> mtasFields.list.get(fields[i]).groupList.add(new ComponentGroup(q, key,</span>
number, 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="nc" id="L326"> }</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="nc bnc" id="L340" title="All 2 branches missed."> if (!gids.isEmpty()) {</span>
<span class="nc" id="L341"> int tmpSubCounter = 0;</span>
<span class="nc bnc" id="L342" title="All 2 branches missed."> for (String gid : gids) {</span>
<span class="nc" id="L343"> positions[tmpSubCounter] = solrParams.get(</span>
name + "." + gid + "." + NAME_MTAS_GROUP_GROUPING_POSITION, null);
<span class="nc" id="L345"> prefixes[tmpSubCounter] = solrParams.get(</span>
name + "." + gid + "." + NAME_MTAS_GROUP_GROUPING_PREFIXES, null);
<span class="nc bnc" id="L347" title="All 2 branches missed."> if (positions[tmpSubCounter] == null) {</span>
<span class="nc" id="L348"> throw new IOException("no position for " + gid);</span>
<span class="nc bnc" id="L349" title="All 2 branches missed."> } else if (prefixes[tmpSubCounter] == null) {</span>
<span class="nc" id="L350"> throw new IOException("no prefix for " + gid);</span>
}
<span class="nc" id="L352"> tmpSubCounter++;</span>
<span class="nc" id="L353"> }</span>
}
<span class="nc" id="L355"> }</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="L368" title="All 2 branches missed."> if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="nc bnc" id="L369" title="All 2 branches missed."> && sreq.params.getBool(PARAM_MTAS_GROUP, false)) {</span>
<span class="nc bnc" id="L370" title="All 2 branches missed."> if ((sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) {</span>
// do nothing
} else {
// remove prefix for other requests
<span class="nc" id="L374"> Set<String> keys = MtasSolrResultUtil</span>
<span class="nc" id="L375"> .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_GROUP);</span>
<span class="nc" id="L376"> sreq.params.remove(PARAM_MTAS_GROUP);</span>
Set<String> subKeys;
<span class="nc bnc" id="L378" title="All 2 branches missed."> for (String key : keys) {</span>
<span class="nc" id="L379"> sreq.params.remove(</span>
PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_FIELD);
<span class="nc" id="L381"> sreq.params</span>
<span class="nc" id="L382"> .remove(PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_KEY);</span>
<span class="nc" id="L383"> sreq.params.remove(</span>
PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_QUERY_TYPE);
<span class="nc" id="L385"> sreq.params.remove(</span>
PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_QUERY_VALUE);
<span class="nc" id="L387"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_QUERY_PREFIX);
<span class="nc" id="L389"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_QUERY_IGNORE);
<span class="nc" id="L391"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH);
<span class="nc" id="L393"> subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
PARAM_MTAS_GROUP + "." + key + "."
+ NAME_MTAS_GROUP_GROUPING_LEFT);
<span class="nc bnc" id="L396" title="All 2 branches missed."> for (String subKey : subKeys) {</span>
<span class="nc" id="L397"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_GROUPING_LEFT + "." + subKey + "."
+ NAME_MTAS_GROUP_GROUPING_POSITION);
<span class="nc" id="L400"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_GROUPING_LEFT + "." + subKey + "."
+ NAME_MTAS_GROUP_GROUPING_PREFIXES);
<span class="nc" id="L403"> }</span>
<span class="nc" id="L404"> subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
PARAM_MTAS_GROUP + "." + key + "."
+ NAME_MTAS_GROUP_GROUPING_RIGHT);
<span class="nc bnc" id="L407" title="All 2 branches missed."> for (String subKey : subKeys) {</span>
<span class="nc" id="L408"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_GROUPING_RIGHT + "." + subKey + "."
+ NAME_MTAS_GROUP_GROUPING_POSITION);
<span class="nc" id="L411"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_GROUPING_RIGHT + "." + subKey + "."
+ NAME_MTAS_GROUP_GROUPING_PREFIXES);
<span class="nc" id="L414"> }</span>
<span class="nc" id="L415"> subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
PARAM_MTAS_GROUP + "." + key + "."
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE);
<span class="nc bnc" id="L418" title="All 2 branches missed."> for (String subKey : subKeys) {</span>
<span class="nc" id="L419"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE + "." + subKey + "."
+ NAME_MTAS_GROUP_GROUPING_POSITION);
<span class="nc" id="L422"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span>
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE + "." + subKey + "."
+ NAME_MTAS_GROUP_GROUPING_PREFIXES);
<span class="nc" id="L425"> }</span>
<span class="nc" id="L426"> subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
PARAM_MTAS_GROUP + "." + key + "."
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT);
<span class="nc bnc" id="L429" title="All 2 branches missed."> for (String subKey : subKeys) {</span>
<span class="nc" id="L430"> 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="L433"> 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="L436"> }</span>
<span class="nc" id="L437"> subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
PARAM_MTAS_GROUP + "." + key + "."
+ NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT);
<span class="nc bnc" id="L440" title="All 2 branches missed."> for (String subKey : subKeys) {</span>
<span class="nc" id="L441"> 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="L444"> 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="L447"> }</span>
<span class="nc" id="L448"> }</span>
}
}
<span class="nc" id="L451"> }</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="nc" id="L463"> SimpleOrderedMap<Object> mtasGroupResponse = new SimpleOrderedMap<>();</span>
<span class="nc" id="L464"> mtasGroupResponse.add("key", group.key);</span>
<span class="nc" id="L465"> MtasSolrMtasResult data = new MtasSolrMtasResult(group.dataCollector,</span>
new String[] { group.dataType }, new String[] { group.statsType },
new SortedSet[] { group.statsItems }, new String[] { group.sortType },
new String[] { group.sortDirection }, new Integer[] { group.start },
new Integer[] { group.number }, null);
<span class="nc bnc" id="L470" title="All 2 branches missed."> if (encode) {</span>
<span class="nc" id="L471"> mtasGroupResponse.add("_encoded_list", MtasSolrResultUtil.encode(data));</span>
} else {
<span class="nc" id="L473"> mtasGroupResponse.add("list", data);</span>
<span class="nc" id="L474"> MtasSolrResultUtil.rewrite(mtasGroupResponse, searchComponent);</span>
}
<span class="nc" id="L476"> 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="L488" 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="L491" title="All 2 branches missed."> for (ShardRequest sreq : rb.finished) {</span>
<span class="nc bnc" id="L492" title="All 2 branches missed."> if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="nc bnc" id="L493" title="All 2 branches missed."> && sreq.params.getBool(PARAM_MTAS_GROUP, false)) {</span>
<span class="nc bnc" id="L494" title="All 2 branches missed."> for (ShardResponse shardResponse : sreq.responses) {</span>
<span class="nc" id="L495"> NamedList<Object> response = shardResponse.getSolrResponse()</span>
<span class="nc" id="L496"> .getResponse();</span>
try {
<span class="nc" id="L498"> ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response</span>
<span class="nc" id="L499"> .findRecursive("mtas", "group");</span>
<span class="nc bnc" id="L500" title="All 2 branches missed."> if (data != null) {</span>
<span class="nc" id="L501"> MtasSolrResultUtil.decode(data);</span>
}
<span class="nc" id="L503"> } catch (ClassCastException e) {</span>
<span class="nc" id="L504"> log.debug(e);</span>
// shouldn't happen
<span class="nc" id="L506"> }</span>
<span class="nc" id="L507"> }</span>
}
<span class="nc" id="L509"> }</span>
}
<span class="nc" id="L511"> }</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="L525"> NamedList<Object> mtasResponse = null;</span>
try {
<span class="nc" id="L527"> mtasResponse = (NamedList<Object>) rb.rsp.getValues().get("mtas");</span>
<span class="nc" id="L528"> } catch (ClassCastException e) {</span>
<span class="nc" id="L529"> log.debug(e);</span>
<span class="nc" id="L530"> mtasResponse = null;</span>
<span class="nc" id="L531"> }</span>
<span class="nc bnc" id="L532" title="All 2 branches missed."> if (mtasResponse != null) {</span>
ArrayList<Object> mtasResponseGroup;
try {
<span class="nc" id="L535"> mtasResponseGroup = (ArrayList<Object>) mtasResponse.get("group");</span>
<span class="nc bnc" id="L536" title="All 2 branches missed."> if (mtasResponseGroup != null) {</span>
<span class="nc" id="L537"> MtasSolrResultUtil.rewrite(mtasResponseGroup, searchComponent);</span>
}
<span class="nc" id="L539"> } catch (ClassCastException e) {</span>
<span class="nc" id="L540"> log.debug(e);</span>
<span class="nc" id="L541"> mtasResponse.remove("group");</span>
<span class="nc" id="L542"> }</span>
}
<span class="nc" id="L544"> }</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>