MtasSolrComponentGroup.java.html 35.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
<?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> &gt; <a href="index.source.html" class="el_package">mtas.solr.handler.component.util</a> &gt; <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&lt;ComponentGroup&gt; {

  /** 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
      + &quot;.group&quot;;

  /** The Constant NAME_MTAS_GROUP_FIELD. */
  public static final String NAME_MTAS_GROUP_FIELD = &quot;field&quot;;

  /** The Constant NAME_MTAS_GROUP_QUERY_TYPE. */
  public static final String NAME_MTAS_GROUP_QUERY_TYPE = &quot;query.type&quot;;

  /** The Constant NAME_MTAS_GROUP_QUERY_VALUE. */
  public static final String NAME_MTAS_GROUP_QUERY_VALUE = &quot;query.value&quot;;

  /** The Constant NAME_MTAS_GROUP_QUERY_PREFIX. */
  public static final String NAME_MTAS_GROUP_QUERY_PREFIX = &quot;query.prefix&quot;;

  /** The Constant NAME_MTAS_GROUP_QUERY_IGNORE. */
  public static final String NAME_MTAS_GROUP_QUERY_IGNORE = &quot;query.ignore&quot;;

  /** The Constant NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH. */
  public static final String NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH = &quot;query.maximumIgnoreLength&quot;;

  /** The Constant NAME_MTAS_GROUP_QUERY_VARIABLE. */
  public static final String NAME_MTAS_GROUP_QUERY_VARIABLE = &quot;query.variable&quot;;

  /** The Constant SUBNAME_MTAS_GROUP_QUERY_VARIABLE_NAME. */
  public static final String SUBNAME_MTAS_GROUP_QUERY_VARIABLE_NAME = &quot;name&quot;;

  /** The Constant SUBNAME_MTAS_GROUP_QUERY_VARIABLE_VALUE. */
  public static final String SUBNAME_MTAS_GROUP_QUERY_VARIABLE_VALUE = &quot;value&quot;;

  /** The Constant NAME_MTAS_GROUP_KEY. */
  public static final String NAME_MTAS_GROUP_KEY = &quot;key&quot;;

  /** The Constant NAME_MTAS_GROUP_NUMBER. */
  public static final String NAME_MTAS_GROUP_NUMBER = &quot;number&quot;;

  /** The Constant NAME_MTAS_GROUP_GROUPING_LEFT. */
  public static final String NAME_MTAS_GROUP_GROUPING_LEFT = &quot;grouping.left&quot;;

  /** The Constant NAME_MTAS_GROUP_GROUPING_RIGHT. */
  public static final String NAME_MTAS_GROUP_GROUPING_RIGHT = &quot;grouping.right&quot;;

  /** The Constant NAME_MTAS_GROUP_GROUPING_HIT_INSIDE. */
  public static final String NAME_MTAS_GROUP_GROUPING_HIT_INSIDE = &quot;grouping.hit.inside&quot;;

  /** The Constant NAME_MTAS_GROUP_GROUPING_HIT_LEFT. */
  public static final String NAME_MTAS_GROUP_GROUPING_HIT_LEFT = &quot;grouping.hit.left&quot;;

  /** The Constant NAME_MTAS_GROUP_GROUPING_HIT_RIGHT. */
  public static final String NAME_MTAS_GROUP_GROUPING_HIT_RIGHT = &quot;grouping.hit.right&quot;;

  /** The Constant NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT. */
  public static final String NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT = &quot;grouping.hit.insideLeft&quot;;

  /** The Constant NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT. */
  public static final String NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT = &quot;grouping.hit.insideRight&quot;;

  /** The Constant NAME_MTAS_GROUP_GROUPING_POSITION. */
  public static final String NAME_MTAS_GROUP_GROUPING_POSITION = &quot;position&quot;;

  /** The Constant NAME_MTAS_GROUP_GROUPING_PREFIXES. */
  public static final String NAME_MTAS_GROUP_GROUPING_PREFIXES = &quot;prefixes&quot;;

  /** 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&lt;String&gt; 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&lt;String, String[]&gt;[] 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 + &quot;.&quot; + id + &quot;.&quot; + 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 + &quot;.&quot; + id + &quot;.&quot; + 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 + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_GROUP_NUMBER, null);
<span class="nc" id="L159">        queryTypes[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_GROUP + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_GROUP_QUERY_TYPE,
            null);
<span class="nc" id="L162">        queryValues[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_GROUP + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_GROUP_QUERY_VALUE,
            null);
<span class="nc" id="L165">        queryPrefixes[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_GROUP + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_GROUP_QUERY_PREFIX,
            null);
<span class="nc" id="L168">        queryIgnores[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_GROUP + &quot;.&quot; + id + &quot;.&quot; + 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 + &quot;.&quot; + id + &quot;.&quot;</span>
                + NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH, null);
<span class="nc" id="L174">        Set&lt;String&gt; vIds = MtasSolrResultUtil.getIdsFromParameters(</span>
<span class="nc" id="L175">            rb.req.getParams(),</span>
            PARAM_MTAS_GROUP + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_GROUP_QUERY_VARIABLE);
<span class="nc" id="L177">        queryVariables[tmpCounter] = new HashMap&lt;&gt;();</span>
<span class="nc bnc" id="L178" title="All 2 branches missed.">        if (!vIds.isEmpty()) {</span>
<span class="nc" id="L179">          HashMap&lt;String, ArrayList&lt;String&gt;&gt; tmpVariables = new HashMap&lt;&gt;();</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 + &quot;.&quot; + id + &quot;.&quot;</span>
                    + NAME_MTAS_GROUP_QUERY_VARIABLE + &quot;.&quot; + vId + &quot;.&quot;
                    + 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&lt;String&gt;());</span>
              }
<span class="nc" id="L189">              String value = rb.req.getParams()</span>
<span class="nc" id="L190">                  .get(PARAM_MTAS_GROUP + &quot;.&quot; + id + &quot;.&quot;</span>
                      + NAME_MTAS_GROUP_QUERY_VARIABLE + &quot;.&quot; + vId + &quot;.&quot;
                      + 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&lt;String&gt; list = new ArrayList&lt;&gt;();</span>
<span class="nc" id="L195">                String[] subList = value.split(&quot;(?&lt;!\\\\),&quot;);</span>
<span class="nc bnc" id="L196" title="All 2 branches missed.">                for (int i = 0; i &lt; subList.length; i++) {</span>
<span class="nc" id="L197">                  list.add(</span>
<span class="nc" id="L198">                      subList[i].replace(&quot;\\,&quot;, &quot;,&quot;).replace(&quot;\\\\&quot;, &quot;\\&quot;));</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&lt;String, ArrayList&lt;String&gt;&gt; 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&lt;String&gt; gids;
        String tmpName;
        // collect grouping inside
<span class="nc" id="L215">        tmpName = PARAM_MTAS_GROUP + &quot;.&quot; + id + &quot;.&quot;</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 + &quot;.&quot; + NAME_MTAS_GROUP_GROUPING_PREFIXES);</span>
        // collect grouping left
<span class="nc" id="L220">        tmpName = PARAM_MTAS_GROUP + &quot;.&quot; + id + &quot;.&quot;</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 + &quot;.&quot; + id + &quot;.&quot;</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 + &quot;.&quot; + id + &quot;.&quot;</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 + &quot;.&quot; + id + &quot;.&quot;</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 + &quot;.&quot; + id + &quot;.&quot;</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 + &quot;.&quot; + id + &quot;.&quot;</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(&quot;no (valid) field in mtas group&quot;);</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 &lt; 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) + &quot;:&quot; + fields[i] + &quot;:&quot; + 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
   */
  private void prepare(SolrParams solrParams, SortedSet&lt;String&gt; gids,
      String name, String[] positions, String[] prefixes) {
<span class="nc bnc" id="L339" title="All 2 branches missed.">    if (!gids.isEmpty()) {</span>
<span class="nc" id="L340">      int tmpSubCounter = 0;</span>
<span class="nc bnc" id="L341" title="All 2 branches missed.">      for (String gid : gids) {</span>
<span class="nc" id="L342">        positions[tmpSubCounter] = solrParams.get(</span>
            name + &quot;.&quot; + gid + &quot;.&quot; + NAME_MTAS_GROUP_GROUPING_POSITION, null);
<span class="nc" id="L344">        prefixes[tmpSubCounter] = solrParams.get(</span>
            name + &quot;.&quot; + gid + &quot;.&quot; + NAME_MTAS_GROUP_GROUPING_PREFIXES, null);
<span class="nc" id="L346">        tmpSubCounter++;</span>
<span class="nc" id="L347">      }</span>
    }
<span class="nc" id="L349">  }</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="L362" title="All 2 branches missed.">    if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="nc bnc" id="L363" title="All 2 branches missed.">        &amp;&amp; sreq.params.getBool(PARAM_MTAS_GROUP, false)) {</span>
<span class="nc bnc" id="L364" title="All 2 branches missed.">      if ((sreq.purpose &amp; ShardRequest.PURPOSE_GET_TOP_IDS) != 0) {</span>
        // do nothing
      } else {
        // remove prefix for other requests
<span class="nc" id="L368">        Set&lt;String&gt; keys = MtasSolrResultUtil</span>
<span class="nc" id="L369">            .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_GROUP);</span>
<span class="nc" id="L370">        sreq.params.remove(PARAM_MTAS_GROUP);</span>
        Set&lt;String&gt; subKeys;
<span class="nc bnc" id="L372" title="All 2 branches missed.">        for (String key : keys) {</span>
<span class="nc" id="L373">          sreq.params.remove(</span>
              PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_GROUP_FIELD);
<span class="nc" id="L375">          sreq.params</span>
<span class="nc" id="L376">              .remove(PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_GROUP_KEY);</span>
<span class="nc" id="L377">          sreq.params.remove(</span>
              PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_GROUP_QUERY_TYPE);
<span class="nc" id="L379">          sreq.params.remove(</span>
              PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_GROUP_QUERY_VALUE);
<span class="nc" id="L381">          sreq.params.remove(PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_GROUP_QUERY_PREFIX);
<span class="nc" id="L383">          sreq.params.remove(PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_GROUP_QUERY_IGNORE);
<span class="nc" id="L385">          sreq.params.remove(PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH);
<span class="nc" id="L387">          subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
              PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot;
                  + NAME_MTAS_GROUP_GROUPING_LEFT);
<span class="nc bnc" id="L390" title="All 2 branches missed.">          for (String subKey : subKeys) {</span>
<span class="nc" id="L391">            sreq.params.remove(PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot;</span>
                + NAME_MTAS_GROUP_GROUPING_LEFT + &quot;.&quot; + subKey + &quot;.&quot;
                + NAME_MTAS_GROUP_GROUPING_POSITION);
<span class="nc" id="L394">            sreq.params.remove(PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot;</span>
                + NAME_MTAS_GROUP_GROUPING_LEFT + &quot;.&quot; + subKey + &quot;.&quot;
                + NAME_MTAS_GROUP_GROUPING_PREFIXES);
<span class="nc" id="L397">          }</span>
<span class="nc" id="L398">          subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
              PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot;
                  + NAME_MTAS_GROUP_GROUPING_RIGHT);
<span class="nc bnc" id="L401" title="All 2 branches missed.">          for (String subKey : subKeys) {</span>
<span class="nc" id="L402">            sreq.params.remove(PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot;</span>
                + NAME_MTAS_GROUP_GROUPING_RIGHT + &quot;.&quot; + subKey + &quot;.&quot;
                + NAME_MTAS_GROUP_GROUPING_POSITION);
<span class="nc" id="L405">            sreq.params.remove(PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot;</span>
                + NAME_MTAS_GROUP_GROUPING_RIGHT + &quot;.&quot; + subKey + &quot;.&quot;
                + NAME_MTAS_GROUP_GROUPING_PREFIXES);
<span class="nc" id="L408">          }</span>
<span class="nc" id="L409">          subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
              PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot;
                  + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE);
<span class="nc bnc" id="L412" title="All 2 branches missed.">          for (String subKey : subKeys) {</span>
<span class="nc" id="L413">            sreq.params.remove(PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot;</span>
                + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE + &quot;.&quot; + subKey + &quot;.&quot;
                + NAME_MTAS_GROUP_GROUPING_POSITION);
<span class="nc" id="L416">            sreq.params.remove(PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot;</span>
                + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE + &quot;.&quot; + subKey + &quot;.&quot;
                + NAME_MTAS_GROUP_GROUPING_PREFIXES);
<span class="nc" id="L419">          }</span>
<span class="nc" id="L420">          subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
              PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot;
                  + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT);
<span class="nc bnc" id="L423" title="All 2 branches missed.">          for (String subKey : subKeys) {</span>
<span class="nc" id="L424">            sreq.params.remove(PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot;</span>
                + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT + &quot;.&quot; + subKey + &quot;.&quot;
                + NAME_MTAS_GROUP_GROUPING_POSITION);
<span class="nc" id="L427">            sreq.params.remove(PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot;</span>
                + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT + &quot;.&quot; + subKey + &quot;.&quot;
                + NAME_MTAS_GROUP_GROUPING_PREFIXES);
<span class="nc" id="L430">          }</span>
<span class="nc" id="L431">          subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
              PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot;
                  + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT);
<span class="nc bnc" id="L434" title="All 2 branches missed.">          for (String subKey : subKeys) {</span>
<span class="nc" id="L435">            sreq.params.remove(PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot;</span>
                + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT + &quot;.&quot; + subKey + &quot;.&quot;
                + NAME_MTAS_GROUP_GROUPING_POSITION);
<span class="nc" id="L438">            sreq.params.remove(PARAM_MTAS_GROUP + &quot;.&quot; + key + &quot;.&quot;</span>
                + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT + &quot;.&quot; + subKey + &quot;.&quot;
                + NAME_MTAS_GROUP_GROUPING_PREFIXES);
<span class="nc" id="L441">          }</span>
<span class="nc" id="L442">        }</span>
      }
    }
<span class="nc" id="L445">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see
   * mtas.solr.handler.component.util.MtasSolrComponent#create(mtas.codec.util.
   * CodecComponent.BasicComponent, java.lang.Boolean)
   */
  @SuppressWarnings(&quot;unchecked&quot;)
  public SimpleOrderedMap&lt;Object&gt; create(ComponentGroup group, Boolean encode)
      throws IOException {
<span class="nc" id="L457">    SimpleOrderedMap&lt;Object&gt; mtasGroupResponse = new SimpleOrderedMap&lt;&gt;();</span>
<span class="nc" id="L458">    mtasGroupResponse.add(&quot;key&quot;, group.key);</span>
<span class="nc" id="L459">    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="L464" title="All 2 branches missed.">    if (encode) {</span>
<span class="nc" id="L465">      mtasGroupResponse.add(&quot;_encoded_list&quot;, MtasSolrResultUtil.encode(data));</span>
    } else {
<span class="nc" id="L467">      mtasGroupResponse.add(&quot;list&quot;, data);</span>
<span class="nc" id="L468">      MtasSolrResultUtil.rewrite(mtasGroupResponse);</span>
    }
<span class="nc" id="L470">    return mtasGroupResponse;</span>
  }

  /*
   * (non-Javadoc)
   * 
   * @see
   * mtas.solr.handler.component.util.MtasSolrComponent#finishStage(org.apache.
   * solr.handler.component.ResponseBuilder)
   */
  @SuppressWarnings(&quot;unchecked&quot;)
  public void finishStage(ResponseBuilder rb) {
<span class="nc bnc" id="L482" title="All 6 branches missed.">    if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
        &amp;&amp; rb.stage &gt;= ResponseBuilder.STAGE_EXECUTE_QUERY
        &amp;&amp; rb.stage &lt; ResponseBuilder.STAGE_GET_FIELDS) {
<span class="nc bnc" id="L485" title="All 2 branches missed.">      for (ShardRequest sreq : rb.finished) {</span>
<span class="nc bnc" id="L486" title="All 2 branches missed.">        if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="nc bnc" id="L487" title="All 2 branches missed.">            &amp;&amp; sreq.params.getBool(PARAM_MTAS_GROUP, false)) {</span>
<span class="nc bnc" id="L488" title="All 2 branches missed.">          for (ShardResponse shardResponse : sreq.responses) {</span>
<span class="nc" id="L489">            NamedList&lt;Object&gt; response = shardResponse.getSolrResponse()</span>
<span class="nc" id="L490">                .getResponse();</span>
            try {
<span class="nc" id="L492">              ArrayList&lt;NamedList&lt;Object&gt;&gt; data = (ArrayList&lt;NamedList&lt;Object&gt;&gt;) response</span>
<span class="nc" id="L493">                  .findRecursive(&quot;mtas&quot;, &quot;group&quot;);</span>
<span class="nc bnc" id="L494" title="All 2 branches missed.">              if (data != null) {</span>
<span class="nc" id="L495">                MtasSolrResultUtil.decode(data);</span>
              }
<span class="nc" id="L497">            } catch (ClassCastException e) {</span>
<span class="nc" id="L498">              log.debug(e);</span>
              // shouldn't happen
<span class="nc" id="L500">            }</span>
<span class="nc" id="L501">          }</span>
        }
<span class="nc" id="L503">      }</span>
    }
<span class="nc" id="L505">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see
   * mtas.solr.handler.component.util.MtasSolrComponent#distributedProcess(org.
   * apache.solr.handler.component.ResponseBuilder,
   * mtas.codec.util.CodecComponent.ComponentFields)
   */
  @SuppressWarnings(&quot;unchecked&quot;)
  public void distributedProcess(ResponseBuilder rb, ComponentFields mtasFields)
      throws IOException {
    // rewrite
<span class="nc" id="L519">    NamedList&lt;Object&gt; mtasResponse = null;</span>
    try {
<span class="nc" id="L521">      mtasResponse = (NamedList&lt;Object&gt;) rb.rsp.getValues().get(&quot;mtas&quot;);</span>
<span class="nc" id="L522">    } catch (ClassCastException e) {</span>
<span class="nc" id="L523">      log.debug(e);</span>
<span class="nc" id="L524">      mtasResponse = null;</span>
<span class="nc" id="L525">    }</span>
<span class="nc bnc" id="L526" title="All 2 branches missed.">    if (mtasResponse != null) {</span>
      ArrayList&lt;Object&gt; mtasResponseGroup;
      try {
<span class="nc" id="L529">        mtasResponseGroup = (ArrayList&lt;Object&gt;) mtasResponse.get(&quot;group&quot;);</span>
<span class="nc bnc" id="L530" title="All 2 branches missed.">        if (mtasResponseGroup != null) {</span>
<span class="nc" id="L531">          MtasSolrResultUtil.rewrite(mtasResponseGroup);</span>
        }
<span class="nc" id="L533">      } catch (ClassCastException e) {</span>
<span class="nc" id="L534">        log.debug(e);</span>
<span class="nc" id="L535">        mtasResponse.remove(&quot;group&quot;);</span>
<span class="nc" id="L536">      }</span>
    }
<span class="nc" id="L538">  }</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>