MtasSolrComponentStats.java.html 66.6 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 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
<?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>MtasSolrComponentStats.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">MtasSolrComponentStats.java</span></div><h1>MtasSolrComponentStats.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.HashSet;
import java.util.Iterator;
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.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.ComponentPosition;
import mtas.codec.util.CodecComponent.ComponentSpan;
import mtas.codec.util.CodecComponent.ComponentStats;
import mtas.codec.util.CodecComponent.ComponentToken;
import mtas.codec.util.CodecComponent.SubComponentFunction;
import mtas.codec.util.collector.MtasDataCollector;
import mtas.parser.function.ParseException;
import mtas.search.spans.util.MtasSpanQuery;
import mtas.solr.handler.component.MtasSolrSearchComponent;

/**
 * The Class MtasSolrComponentStats.
 */
public class MtasSolrComponentStats
    implements MtasSolrComponent&lt;ComponentStats&gt; {

  /** The Constant log. */
<span class="fc" id="L40">  private static final Log log = LogFactory.getLog(MtasSolrComponentStats.class);</span>

  /** The search component. */
  MtasSolrSearchComponent searchComponent;

  /** The Constant PARAM_MTAS_STATS. */
  public static final String PARAM_MTAS_STATS = MtasSolrSearchComponent.PARAM_MTAS
      + &quot;.stats&quot;;

  /** The Constant PARAM_MTAS_STATS_POSITIONS. */
  public static final String PARAM_MTAS_STATS_POSITIONS = PARAM_MTAS_STATS
      + &quot;.positions&quot;;

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

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

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

  /** The Constant NAME_MTAS_STATS_POSITIONS_MINIMUM. */
  public static final String NAME_MTAS_STATS_POSITIONS_MINIMUM = &quot;minimum&quot;;

  /** The Constant NAME_MTAS_STATS_POSITIONS_MAXIMUM. */
  public static final String NAME_MTAS_STATS_POSITIONS_MAXIMUM = &quot;maximum&quot;;

  /** The Constant PARAM_MTAS_STATS_TOKENS. */
  public static final String PARAM_MTAS_STATS_TOKENS = PARAM_MTAS_STATS
      + &quot;.tokens&quot;;

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

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

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

  /** The Constant NAME_MTAS_STATS_TOKENS_MINIMUM. */
  public static final String NAME_MTAS_STATS_TOKENS_MINIMUM = &quot;minimum&quot;;

  /** The Constant NAME_MTAS_STATS_TOKENS_MAXIMUM. */
  public static final String NAME_MTAS_STATS_TOKENS_MAXIMUM = &quot;maximum&quot;;

  /** The Constant PARAM_MTAS_STATS_SPANS. */
  public static final String PARAM_MTAS_STATS_SPANS = PARAM_MTAS_STATS
      + &quot;.spans&quot;;

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

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

  /** The Constant NAME_MTAS_STATS_SPANS_EXPAND. */
  public static final String NAME_MTAS_STATS_SPANS_EXPAND = &quot;expand&quot;;

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

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

  /** The Constant NAME_MTAS_STATS_SPANS_MINIMUM. */
  public static final String NAME_MTAS_STATS_SPANS_MINIMUM = &quot;minimum&quot;;

  /** The Constant NAME_MTAS_STATS_SPANS_MAXIMUM. */
  public static final String NAME_MTAS_STATS_SPANS_MAXIMUM = &quot;maximum&quot;;

  /** The Constant NAME_MTAS_STATS_SPANS_FUNCTION. */
  public static final String NAME_MTAS_STATS_SPANS_FUNCTION = &quot;function&quot;;

  /** The Constant SUBNAME_MTAS_STATS_SPANS_FUNCTION_EXPRESSION. */
  public static final String SUBNAME_MTAS_STATS_SPANS_FUNCTION_EXPRESSION = &quot;expression&quot;;

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

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

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

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

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

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

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

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

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

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

  /**
   * Instantiates a new mtas solr component stats.
   *
   * @param searchComponent the search component
   */
<span class="fc" id="L153">  public MtasSolrComponentStats(MtasSolrSearchComponent searchComponent) {</span>
<span class="fc" id="L154">    this.searchComponent = searchComponent;</span>
<span class="fc" id="L155">  }</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 bfc" id="L167" title="All 2 branches covered.">    if (rb.req.getParams().getBool(PARAM_MTAS_STATS_POSITIONS, false)) {</span>
<span class="fc" id="L168">      preparePositions(rb, mtasFields);</span>
    }
<span class="fc bfc" id="L170" title="All 2 branches covered.">    if (rb.req.getParams().getBool(PARAM_MTAS_STATS_TOKENS, false)) {</span>
<span class="fc" id="L171">      prepareTokens(rb, mtasFields);</span>
    }
<span class="fc bfc" id="L173" title="All 2 branches covered.">    if (rb.req.getParams().getBool(PARAM_MTAS_STATS_SPANS, false)) {</span>
<span class="fc" id="L174">      prepareSpans(rb, mtasFields);</span>
    }
<span class="fc" id="L176">  }</span>

  /**
   * Prepare positions.
   *
   * @param rb the rb
   * @param mtasFields the mtas fields
   * @throws IOException Signals that an I/O exception has occurred.
   */
  private void preparePositions(ResponseBuilder rb, ComponentFields mtasFields)
      throws IOException {
<span class="fc" id="L187">    Set&lt;String&gt; ids = MtasSolrResultUtil</span>
<span class="fc" id="L188">        .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_STATS_POSITIONS);</span>
<span class="pc bpc" id="L189" title="1 of 2 branches missed.">    if (!ids.isEmpty()) {</span>
<span class="fc" id="L190">      int tmpCounter = 0;</span>
<span class="fc" id="L191">      String[] fields = new String[ids.size()];</span>
<span class="fc" id="L192">      String[] keys = new String[ids.size()];</span>
<span class="fc" id="L193">      String[] minima = new String[ids.size()];</span>
<span class="fc" id="L194">      String[] maxima = new String[ids.size()];</span>
<span class="fc" id="L195">      String[] types = new String[ids.size()];</span>
<span class="fc bfc" id="L196" title="All 2 branches covered.">      for (String id : ids) {</span>
<span class="fc" id="L197">        fields[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_POSITIONS</span>
            + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_STATS_POSITIONS_FIELD, null);
<span class="fc" id="L199">        keys[tmpCounter] = rb.req.getParams()</span>
<span class="fc" id="L200">            .get(PARAM_MTAS_STATS_POSITIONS + &quot;.&quot; + id + &quot;.&quot;</span>
<span class="fc" id="L201">                + NAME_MTAS_STATS_POSITIONS_KEY, String.valueOf(tmpCounter))</span>
<span class="fc" id="L202">            .trim();</span>
<span class="fc" id="L203">        minima[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_POSITIONS</span>
            + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_STATS_POSITIONS_MINIMUM, null);
<span class="fc" id="L205">        maxima[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_POSITIONS</span>
            + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_STATS_POSITIONS_MAXIMUM, null);
<span class="fc" id="L207">        types[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_POSITIONS</span>
            + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_STATS_POSITIONS_TYPE, null);
<span class="fc" id="L209">        tmpCounter++;</span>
<span class="fc" id="L210">      }</span>
<span class="fc" id="L211">      String uniqueKeyField = rb.req.getSchema().getUniqueKeyField().getName();</span>
<span class="fc" id="L212">      mtasFields.doStats = true;</span>
<span class="fc" id="L213">      mtasFields.doStatsPositions = true;</span>
<span class="fc" id="L214">      rb.setNeedDocSet(true);</span>
<span class="fc bfc" id="L215" title="All 2 branches covered.">      for (String field : fields) {</span>
<span class="pc bpc" id="L216" title="2 of 4 branches missed.">        if (field == null || field.isEmpty()) {</span>
<span class="nc" id="L217">          throw new IOException(&quot;no (valid) field in mtas stats positions&quot;);</span>
<span class="pc bpc" id="L218" title="1 of 2 branches missed.">        } else if (!mtasFields.list.containsKey(field)) {</span>
<span class="fc" id="L219">          mtasFields.list.put(field, new ComponentField(uniqueKeyField));</span>
        }
      }
<span class="fc" id="L222">      MtasSolrResultUtil.compareAndCheck(keys, fields,</span>
<span class="fc" id="L223">          NAME_MTAS_STATS_POSITIONS_KEY, NAME_MTAS_STATS_POSITIONS_FIELD, true);</span>
<span class="fc" id="L224">      MtasSolrResultUtil.compareAndCheck(minima, fields,</span>
          NAME_MTAS_STATS_POSITIONS_MINIMUM, NAME_MTAS_STATS_POSITIONS_FIELD,
<span class="fc" id="L226">          false);</span>
<span class="fc" id="L227">      MtasSolrResultUtil.compareAndCheck(maxima, fields,</span>
          NAME_MTAS_STATS_POSITIONS_MAXIMUM, NAME_MTAS_STATS_POSITIONS_FIELD,
<span class="fc" id="L229">          false);</span>
<span class="fc" id="L230">      MtasSolrResultUtil.compareAndCheck(types, fields,</span>
          NAME_MTAS_STATS_POSITIONS_TYPE, NAME_MTAS_STATS_POSITIONS_FIELD,
<span class="fc" id="L232">          false);</span>
<span class="fc bfc" id="L233" title="All 2 branches covered.">      for (int i = 0; i &lt; fields.length; i++) {</span>
<span class="fc" id="L234">        String field = fields[i];</span>
<span class="fc" id="L235">        String key = keys[i];</span>
<span class="pc bpc" id="L236" title="2 of 4 branches missed.">        String type = (types[i] == null) || (types[i].isEmpty()) ? null</span>
<span class="fc" id="L237">            : types[i].trim();</span>
<span class="pc bpc" id="L238" title="3 of 4 branches missed.">        Double minimum = (minima[i] == null) || (minima[i].isEmpty()) ? null</span>
<span class="pc" id="L239">            : Double.parseDouble(minima[i]);</span>
<span class="pc bpc" id="L240" title="3 of 4 branches missed.">        Double maximum = (maxima[i] == null) || (maxima[i].isEmpty()) ? null</span>
<span class="pc" id="L241">            : Double.parseDouble(maxima[i]);</span>
        try {
<span class="fc" id="L243">          mtasFields.list.get(field).statsPositionList</span>
<span class="fc" id="L244">              .add(new ComponentPosition(key, minimum, maximum, type));</span>
<span class="nc" id="L245">        } catch (ParseException e) {</span>
<span class="nc" id="L246">          throw new IOException(e.getMessage());</span>
<span class="fc" id="L247">        }</span>
      }
    }
<span class="fc" id="L250">  }</span>

  /**
   * Prepare tokens.
   *
   * @param rb the rb
   * @param mtasFields the mtas fields
   * @throws IOException Signals that an I/O exception has occurred.
   */
  private void prepareTokens(ResponseBuilder rb, ComponentFields mtasFields)
      throws IOException {
<span class="fc" id="L261">    Set&lt;String&gt; ids = MtasSolrResultUtil</span>
<span class="fc" id="L262">        .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_STATS_TOKENS);</span>
<span class="pc bpc" id="L263" title="1 of 2 branches missed.">    if (!ids.isEmpty()) {</span>
<span class="fc" id="L264">      int tmpCounter = 0;</span>
<span class="fc" id="L265">      String[] fields = new String[ids.size()];</span>
<span class="fc" id="L266">      String[] keys = new String[ids.size()];</span>
<span class="fc" id="L267">      String[] minima = new String[ids.size()];</span>
<span class="fc" id="L268">      String[] maxima = new String[ids.size()];</span>
<span class="fc" id="L269">      String[] types = new String[ids.size()];</span>
<span class="fc bfc" id="L270" title="All 2 branches covered.">      for (String id : ids) {</span>
<span class="fc" id="L271">        fields[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_TOKENS</span>
            + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_STATS_TOKENS_FIELD, null);
<span class="fc" id="L273">        keys[tmpCounter] = rb.req.getParams()</span>
<span class="fc" id="L274">            .get(PARAM_MTAS_STATS_TOKENS + &quot;.&quot; + id + &quot;.&quot;</span>
<span class="fc" id="L275">                + NAME_MTAS_STATS_TOKENS_KEY, String.valueOf(tmpCounter))</span>
<span class="fc" id="L276">            .trim();</span>
<span class="fc" id="L277">        minima[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_TOKENS</span>
            + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_STATS_TOKENS_MINIMUM, null);
<span class="fc" id="L279">        maxima[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_TOKENS</span>
            + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_STATS_TOKENS_MAXIMUM, null);
<span class="fc" id="L281">        types[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_TOKENS + &quot;.&quot;</span>
            + id + &quot;.&quot; + NAME_MTAS_STATS_TOKENS_TYPE, null);
<span class="fc" id="L283">        tmpCounter++;</span>
<span class="fc" id="L284">      }</span>
<span class="fc" id="L285">      String uniqueKeyField = rb.req.getSchema().getUniqueKeyField().getName();</span>
<span class="fc" id="L286">      mtasFields.doStats = true;</span>
<span class="fc" id="L287">      mtasFields.doStatsTokens = true;</span>
<span class="fc" id="L288">      rb.setNeedDocSet(true);</span>
<span class="fc bfc" id="L289" title="All 2 branches covered.">      for (String field : fields) {</span>
<span class="pc bpc" id="L290" title="2 of 4 branches missed.">        if (field == null || field.isEmpty()) {</span>
<span class="nc" id="L291">          throw new IOException(&quot;no (valid) field in mtas stats tokens&quot;);</span>
<span class="fc bfc" id="L292" title="All 2 branches covered.">        } else if (!mtasFields.list.containsKey(field)) {</span>
<span class="fc" id="L293">          mtasFields.list.put(field, new ComponentField(uniqueKeyField));</span>
        }
      }
<span class="fc" id="L296">      MtasSolrResultUtil.compareAndCheck(keys, fields,</span>
<span class="fc" id="L297">          NAME_MTAS_STATS_TOKENS_KEY, NAME_MTAS_STATS_TOKENS_FIELD, true);</span>
<span class="fc" id="L298">      MtasSolrResultUtil.compareAndCheck(minima, fields,</span>
<span class="fc" id="L299">          NAME_MTAS_STATS_TOKENS_MINIMUM, NAME_MTAS_STATS_TOKENS_FIELD, false);</span>
<span class="fc" id="L300">      MtasSolrResultUtil.compareAndCheck(maxima, fields,</span>
<span class="fc" id="L301">          NAME_MTAS_STATS_TOKENS_MAXIMUM, NAME_MTAS_STATS_TOKENS_FIELD, false);</span>
<span class="fc" id="L302">      MtasSolrResultUtil.compareAndCheck(types, fields,</span>
<span class="fc" id="L303">          NAME_MTAS_STATS_TOKENS_TYPE, NAME_MTAS_STATS_TOKENS_FIELD, false);</span>
<span class="fc bfc" id="L304" title="All 2 branches covered.">      for (int i = 0; i &lt; fields.length; i++) {</span>
<span class="fc" id="L305">        String field = fields[i];</span>
<span class="fc" id="L306">        String key = keys[i];</span>
<span class="pc bpc" id="L307" title="2 of 4 branches missed.">        String type = (types[i] == null) || (types[i].isEmpty()) ? null</span>
<span class="fc" id="L308">            : types[i].trim();</span>
<span class="pc bpc" id="L309" title="3 of 4 branches missed.">        Double minimum = (minima[i] == null) || (minima[i].isEmpty()) ? null</span>
<span class="pc" id="L310">            : Double.parseDouble(minima[i]);</span>
<span class="pc bpc" id="L311" title="3 of 4 branches missed.">        Double maximum = (maxima[i] == null) || (maxima[i].isEmpty()) ? null</span>
<span class="pc" id="L312">            : Double.parseDouble(maxima[i]);</span>
        try {
<span class="fc" id="L314">          mtasFields.list.get(field).statsTokenList</span>
<span class="fc" id="L315">              .add(new ComponentToken(key, minimum, maximum, type));</span>
<span class="nc" id="L316">        } catch (ParseException e) {</span>
<span class="nc" id="L317">          throw new IOException(e.getMessage());</span>
<span class="fc" id="L318">        }</span>
      }
    }
<span class="fc" id="L321">  }</span>

  /**
   * Prepare spans.
   *
   * @param rb the rb
   * @param mtasFields the mtas fields
   * @throws IOException Signals that an I/O exception has occurred.
   */
  private void prepareSpans(ResponseBuilder rb, ComponentFields mtasFields)
      throws IOException {
<span class="fc" id="L332">    SortedSet&lt;String&gt; ids = MtasSolrResultUtil</span>
<span class="fc" id="L333">        .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_STATS_SPANS);</span>
<span class="pc bpc" id="L334" title="1 of 2 branches missed.">    if (!ids.isEmpty()) {</span>
<span class="fc" id="L335">      int tmpCounter = 0;</span>
<span class="fc" id="L336">      String[] fields = new String[ids.size()];</span>
<span class="fc" id="L337">      String[] keys = new String[ids.size()];</span>
<span class="fc" id="L338">      String[] minima = new String[ids.size()];</span>
<span class="fc" id="L339">      String[] maxima = new String[ids.size()];</span>
<span class="fc" id="L340">      String[] types = new String[ids.size()];</span>
<span class="fc" id="L341">      String[][] functionExpressions = new String[ids.size()][];</span>
<span class="fc" id="L342">      String[][] functionKeys = new String[ids.size()][];</span>
<span class="fc" id="L343">      String[][] functionTypes = new String[ids.size()][];</span>
<span class="fc" id="L344">      String[][] queryTypes = new String[ids.size()][];</span>
<span class="fc" id="L345">      String[][] queryValues = new String[ids.size()][];</span>
<span class="fc" id="L346">      String[][] queryIgnores = new String[ids.size()][];</span>
<span class="fc" id="L347">      String[][] queryMaximumIgnoreLengths = new String[ids.size()][];</span>
<span class="fc" id="L348">      String[][] queryPrefixes = new String[ids.size()][];</span>
<span class="fc" id="L349">      HashMap&lt;String, String[]&gt;[][] queryVariables = new HashMap[ids.size()][];</span>
<span class="fc" id="L350">      Boolean[] expand = new Boolean[ids.size()];</span>
<span class="fc bfc" id="L351" title="All 2 branches covered.">      for (String id : ids) {</span>
<span class="fc" id="L352">        fields[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_SPANS + &quot;.&quot;</span>
            + id + &quot;.&quot; + NAME_MTAS_STATS_SPANS_FIELD, null);
<span class="fc" id="L354">        keys[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_STATS_SPANS + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_STATS_SPANS_KEY,
<span class="fc" id="L356">            String.valueOf(tmpCounter)).trim();</span>
<span class="fc" id="L357">        minima[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_SPANS + &quot;.&quot;</span>
            + id + &quot;.&quot; + NAME_MTAS_STATS_SPANS_MINIMUM, null);
<span class="fc" id="L359">        maxima[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_SPANS + &quot;.&quot;</span>
            + id + &quot;.&quot; + NAME_MTAS_STATS_SPANS_MAXIMUM, null);
<span class="fc" id="L361">        types[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_SPANS + &quot;.&quot;</span>
            + id + &quot;.&quot; + NAME_MTAS_STATS_SPANS_TYPE, null);
<span class="fc" id="L363">        Set&lt;String&gt; functionIds = MtasSolrResultUtil</span>
<span class="fc" id="L364">            .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_STATS_SPANS</span>
                + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_STATS_SPANS_FUNCTION);
<span class="fc" id="L366">        functionExpressions[tmpCounter] = new String[functionIds.size()];</span>
<span class="fc" id="L367">        functionKeys[tmpCounter] = new String[functionIds.size()];</span>
<span class="fc" id="L368">        functionTypes[tmpCounter] = new String[functionIds.size()];</span>
<span class="fc" id="L369">        int tmpSubCounter = 0;</span>
<span class="pc bpc" id="L370" title="1 of 2 branches missed.">        for (String functionId : functionIds) {</span>
<span class="nc" id="L371">          functionKeys[tmpCounter][tmpSubCounter] = rb.req.getParams()</span>
<span class="nc" id="L372">              .get(</span>
                  PARAM_MTAS_STATS_SPANS + &quot;.&quot; + id + &quot;.&quot;
                      + NAME_MTAS_STATS_SPANS_FUNCTION + &quot;.&quot; + functionId + &quot;.&quot;
                      + SUBNAME_MTAS_STATS_SPANS_FUNCTION_KEY,
<span class="nc" id="L376">                  String.valueOf(tmpSubCounter))</span>
<span class="nc" id="L377">              .trim();</span>
<span class="nc" id="L378">          functionExpressions[tmpCounter][tmpSubCounter] = rb.req.getParams()</span>
<span class="nc" id="L379">              .get(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + id + &quot;.&quot;</span>
                  + NAME_MTAS_STATS_SPANS_FUNCTION + &quot;.&quot; + functionId + &quot;.&quot;
                  + SUBNAME_MTAS_STATS_SPANS_FUNCTION_EXPRESSION, null);
<span class="nc" id="L382">          functionTypes[tmpCounter][tmpSubCounter] = rb.req.getParams()</span>
<span class="nc" id="L383">              .get(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + id + &quot;.&quot;</span>
                  + NAME_MTAS_STATS_SPANS_FUNCTION + &quot;.&quot; + functionId + &quot;.&quot;
                  + SUBNAME_MTAS_STATS_SPANS_FUNCTION_TYPE, null);
<span class="nc" id="L386">          tmpSubCounter++;</span>
<span class="nc" id="L387">        }</span>

<span class="fc" id="L389">        Set&lt;String&gt; qIds = MtasSolrResultUtil</span>
<span class="fc" id="L390">            .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_STATS_SPANS</span>
                + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_STATS_SPANS_QUERY);
<span class="pc bpc" id="L392" title="1 of 2 branches missed.">        if (!qIds.isEmpty()) {</span>
<span class="fc" id="L393">          int tmpQCounter = 0;</span>
<span class="fc" id="L394">          queryTypes[tmpCounter] = new String[qIds.size()];</span>
<span class="fc" id="L395">          queryValues[tmpCounter] = new String[qIds.size()];</span>
<span class="fc" id="L396">          queryIgnores[tmpCounter] = new String[qIds.size()];</span>
<span class="fc" id="L397">          queryMaximumIgnoreLengths[tmpCounter] = new String[qIds.size()];</span>
<span class="fc" id="L398">          queryPrefixes[tmpCounter] = new String[qIds.size()];</span>
<span class="fc" id="L399">          queryVariables[tmpCounter] = new HashMap[qIds.size()];</span>
<span class="fc bfc" id="L400" title="All 2 branches covered.">          for (String qId : qIds) {</span>
<span class="fc" id="L401">            queryTypes[tmpCounter][tmpQCounter] = rb.req.getParams()</span>
<span class="fc" id="L402">                .get(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + id + &quot;.&quot;</span>
                    + NAME_MTAS_STATS_SPANS_QUERY + &quot;.&quot; + qId + &quot;.&quot;
                    + SUBNAME_MTAS_STATS_SPANS_QUERY_TYPE, null);
<span class="fc" id="L405">            queryValues[tmpCounter][tmpQCounter] = rb.req.getParams()</span>
<span class="fc" id="L406">                .get(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + id + &quot;.&quot;</span>
                    + NAME_MTAS_STATS_SPANS_QUERY + &quot;.&quot; + qId + &quot;.&quot;
                    + SUBNAME_MTAS_STATS_SPANS_QUERY_VALUE, null);
<span class="fc" id="L409">            queryIgnores[tmpCounter][tmpQCounter] = rb.req.getParams()</span>
<span class="fc" id="L410">                .get(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + id + &quot;.&quot;</span>
                    + NAME_MTAS_STATS_SPANS_QUERY + &quot;.&quot; + qId + &quot;.&quot;
                    + SUBNAME_MTAS_STATS_SPANS_QUERY_IGNORE, null);
<span class="fc" id="L413">            queryMaximumIgnoreLengths[tmpCounter][tmpQCounter] = rb.req</span>
<span class="fc" id="L414">                .getParams().get(</span>
                    PARAM_MTAS_STATS_SPANS + &quot;.&quot; + id + &quot;.&quot;
                        + NAME_MTAS_STATS_SPANS_QUERY + &quot;.&quot; + qId + &quot;.&quot;
                        + SUBNAME_MTAS_STATS_SPANS_QUERY_MAXIMUM_IGNORE_LENGTH,
                    null);
<span class="fc" id="L419">            queryPrefixes[tmpCounter][tmpQCounter] = rb.req.getParams()</span>
<span class="fc" id="L420">                .get(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + id + &quot;.&quot;</span>
                    + NAME_MTAS_STATS_SPANS_QUERY + &quot;.&quot; + qId + &quot;.&quot;
                    + SUBNAME_MTAS_STATS_SPANS_QUERY_PREFIX, null);
<span class="fc" id="L423">            Set&lt;String&gt; vIds = MtasSolrResultUtil.getIdsFromParameters(</span>
<span class="fc" id="L424">                rb.req.getParams(),</span>
                PARAM_MTAS_STATS_SPANS + &quot;.&quot; + id + &quot;.&quot;
                    + NAME_MTAS_STATS_SPANS_QUERY + &quot;.&quot; + qId + &quot;.&quot;
                    + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE);
<span class="fc" id="L428">            queryVariables[tmpCounter][tmpQCounter] = new HashMap&lt;&gt;();</span>
<span class="fc bfc" id="L429" title="All 2 branches covered.">            if (!vIds.isEmpty()) {</span>
<span class="fc" id="L430">              HashMap&lt;String, ArrayList&lt;String&gt;&gt; tmpVariables = new HashMap&lt;&gt;();</span>
<span class="fc bfc" id="L431" title="All 2 branches covered.">              for (String vId : vIds) {</span>
<span class="fc" id="L432">                String name = rb.req.getParams()</span>
<span class="fc" id="L433">                    .get(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + id + &quot;.&quot;</span>
                        + NAME_MTAS_STATS_SPANS_QUERY + &quot;.&quot; + qId + &quot;.&quot;
                        + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE + &quot;.&quot; + vId
                        + &quot;.&quot; + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE_NAME,
                        null);
<span class="pc bpc" id="L438" title="1 of 2 branches missed.">                if (name != null) {</span>
<span class="pc bpc" id="L439" title="1 of 2 branches missed.">                  if (!tmpVariables.containsKey(name)) {</span>
<span class="fc" id="L440">                    tmpVariables.put(name, new ArrayList&lt;String&gt;());</span>
                  }
<span class="fc" id="L442">                  String value = rb.req.getParams()</span>
<span class="fc" id="L443">                      .get(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + id + &quot;.&quot;</span>
                          + NAME_MTAS_STATS_SPANS_QUERY + &quot;.&quot; + qId + &quot;.&quot;
                          + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE + &quot;.&quot; + vId
                          + &quot;.&quot; + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE_VALUE,
                          null);
<span class="pc bpc" id="L448" title="1 of 2 branches missed.">                  if (value != null) {</span>
<span class="fc" id="L449">                    ArrayList&lt;String&gt; list = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L450">                    String[] subList = value.split(&quot;(?&lt;!\\\\),&quot;);</span>
<span class="fc bfc" id="L451" title="All 2 branches covered.">                    for (int i = 0; i &lt; subList.length; i++) {</span>
<span class="fc" id="L452">                      list.add(</span>
<span class="fc" id="L453">                          subList[i].replace(&quot;\\,&quot;, &quot;,&quot;).replace(&quot;\\\\&quot;, &quot;\\&quot;));</span>
                    }
<span class="fc" id="L455">                    tmpVariables.get(name).addAll(list);</span>
                  }
                }
<span class="fc" id="L458">              }</span>
<span class="fc bfc" id="L459" title="All 2 branches covered.">              for (Entry&lt;String, ArrayList&lt;String&gt;&gt; entry : tmpVariables</span>
<span class="fc" id="L460">                  .entrySet()) {</span>
<span class="fc" id="L461">                queryVariables[tmpCounter][tmpQCounter].put(entry.getKey(),</span>
<span class="fc" id="L462">                    entry.getValue()</span>
<span class="fc" id="L463">                        .toArray(new String[entry.getValue().size()]));</span>
<span class="fc" id="L464">              }</span>
            }
<span class="fc" id="L466">            tmpQCounter++;</span>
<span class="fc" id="L467">          }</span>
<span class="fc" id="L468">        } else {</span>
<span class="nc" id="L469">          throw new IOException(&quot;no &quot; + NAME_MTAS_STATS_SPANS_QUERY</span>
              + &quot; for mtas stats span &quot; + id);
        }
<span class="pc bpc" id="L472" title="1 of 2 branches missed.">        if (rb.req.getParams().getBool(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + id + &quot;.&quot;</span>
            + NAME_MTAS_STATS_SPANS_EXPAND, false)) {
<span class="nc" id="L474">          expand[tmpCounter] = true;</span>
        } else {
<span class="fc" id="L476">          expand[tmpCounter] = false;</span>
        }
<span class="fc" id="L478">        tmpCounter++;</span>
<span class="fc" id="L479">      }</span>
<span class="fc" id="L480">      String uniqueKeyField = rb.req.getSchema().getUniqueKeyField().getName();</span>
<span class="fc" id="L481">      mtasFields.doStats = true;</span>
<span class="fc" id="L482">      mtasFields.doStatsSpans = true;</span>
<span class="fc" id="L483">      rb.setNeedDocSet(true);</span>
<span class="fc bfc" id="L484" title="All 2 branches covered.">      for (String field : fields) {</span>
<span class="pc bpc" id="L485" title="2 of 4 branches missed.">        if (field == null || field.isEmpty()) {</span>
<span class="nc" id="L486">          throw new IOException(&quot;no (valid) field in mtas stats spans&quot;);</span>
<span class="fc bfc" id="L487" title="All 2 branches covered.">        } else if (!mtasFields.list.containsKey(field)) {</span>
<span class="fc" id="L488">          mtasFields.list.put(field, new ComponentField(uniqueKeyField));</span>
        }
      }
<span class="fc" id="L491">      MtasSolrResultUtil.compareAndCheck(keys, fields,</span>
<span class="fc" id="L492">          NAME_MTAS_STATS_SPANS_KEY, NAME_MTAS_STATS_SPANS_FIELD, true);</span>
<span class="fc" id="L493">      MtasSolrResultUtil.compareAndCheck(minima, fields,</span>
<span class="fc" id="L494">          NAME_MTAS_STATS_SPANS_MINIMUM, NAME_MTAS_STATS_SPANS_FIELD, false);</span>
<span class="fc" id="L495">      MtasSolrResultUtil.compareAndCheck(maxima, fields,</span>
<span class="fc" id="L496">          NAME_MTAS_STATS_SPANS_MAXIMUM, NAME_MTAS_STATS_SPANS_FIELD, false);</span>
<span class="fc" id="L497">      MtasSolrResultUtil.compareAndCheck(types, fields,</span>
<span class="fc" id="L498">          NAME_MTAS_STATS_SPANS_TYPE, NAME_MTAS_STATS_SPANS_FIELD, false);</span>
<span class="fc" id="L499">      MtasSolrResultUtil.compareAndCheck(types, fields,</span>
<span class="fc" id="L500">          NAME_MTAS_STATS_SPANS_FUNCTION, NAME_MTAS_STATS_SPANS_FIELD, false);</span>

<span class="fc bfc" id="L502" title="All 2 branches covered.">      for (int i = 0; i &lt; fields.length; i++) {</span>
<span class="fc" id="L503">        ComponentField cf = mtasFields.list.get(fields[i]);</span>
<span class="fc" id="L504">        int queryNumber = queryValues[i].length;</span>
<span class="fc" id="L505">        MtasSpanQuery[] ql = new MtasSpanQuery[queryNumber];</span>
<span class="fc bfc" id="L506" title="All 2 branches covered.">        for (int j = 0; j &lt; queryNumber; j++) {</span>
<span class="pc bpc" id="L507" title="1 of 2 branches missed.">          Integer maximumIgnoreLength = (queryMaximumIgnoreLengths[i][j] == null)</span>
<span class="pc" id="L508">              ? null : Integer.parseInt(queryMaximumIgnoreLengths[i][j]);</span>
<span class="fc" id="L509">          MtasSpanQuery q = MtasSolrResultUtil.constructQuery(queryValues[i][j],</span>
              queryTypes[i][j], queryPrefixes[i][j], queryVariables[i][j],
              fields[i], queryIgnores[i][j], maximumIgnoreLength);
          // minimize number of queries
<span class="fc bfc" id="L513" title="All 2 branches covered.">          if (cf.spanQueryList.contains(q)) {</span>
<span class="fc" id="L514">            q = cf.spanQueryList.get(cf.spanQueryList.indexOf(q));</span>
          } else {
<span class="fc" id="L516">            cf.spanQueryList.add(q);</span>
          }
<span class="fc" id="L518">          ql[j] = q;</span>
        }
<span class="pc bpc" id="L520" title="1 of 4 branches missed.">        Double minimum = (minima[i] == null) || (minima[i].isEmpty()) ? null</span>
<span class="fc" id="L521">            : Double.parseDouble(minima[i]);</span>
<span class="pc bpc" id="L522" title="3 of 4 branches missed.">        Double maximum = (maxima[i] == null) || (maxima[i].isEmpty()) ? null</span>
<span class="pc" id="L523">            : Double.parseDouble(maxima[i]);</span>
<span class="pc bpc" id="L524" title="2 of 4 branches missed.">        String key = (keys[i] == null) || (keys[i].isEmpty())</span>
<span class="pc" id="L525">            ? String.valueOf(i) + &quot;:&quot; + fields[i] + &quot;:&quot; + queryNumber</span>
<span class="fc" id="L526">            : keys[i].trim();</span>
<span class="pc bpc" id="L527" title="2 of 4 branches missed.">        String type = (types[i] == null) || (types[i].isEmpty()) ? null</span>
<span class="fc" id="L528">            : types[i].trim();</span>
<span class="fc" id="L529">        String[] functionKey = functionKeys[i];</span>
<span class="fc" id="L530">        String[] functionExpression = functionExpressions[i];</span>
<span class="fc" id="L531">        String[] functionType = functionTypes[i];</span>
        try {
<span class="fc" id="L533">          mtasFields.list.get(fields[i]).statsSpanList</span>
<span class="fc" id="L534">              .add(new ComponentSpan(ql, key, minimum, maximum, type,</span>
                  functionKey, functionExpression, functionType));
<span class="nc" id="L536">        } catch (ParseException e) {</span>
<span class="nc" id="L537">          throw new IOException(e.getMessage());</span>
<span class="fc" id="L538">        }</span>
<span class="pc bpc" id="L539" title="1 of 2 branches missed.">        if (expand[i]) {</span>
<span class="nc" id="L540">          HashMap&lt;String, String[]&gt;[][] expandedQueryVariables = expandedQueryVariables(</span>
              queryVariables[i]);
<span class="nc bnc" id="L542" title="All 2 branches missed.">          for (int e = 0; e &lt; expandedQueryVariables.length; e++) {</span>
<span class="nc" id="L543">            MtasSpanQuery[] eql = new MtasSpanQuery[queryNumber];</span>
<span class="nc bnc" id="L544" title="All 2 branches missed.">            for (int j = 0; j &lt; queryNumber; j++) {</span>
<span class="nc bnc" id="L545" title="All 2 branches missed.">              Integer maximumIgnoreLength = (queryMaximumIgnoreLengths[i][j] == null)</span>
<span class="nc" id="L546">                  ? null : Integer.parseInt(queryMaximumIgnoreLengths[i][j]);</span>
<span class="nc" id="L547">              MtasSpanQuery q = MtasSolrResultUtil.constructQuery(</span>
                  queryValues[i][j], queryTypes[i][j], queryPrefixes[i][j],
                  expandedQueryVariables[e][j], fields[i], queryIgnores[i][j],
                  maximumIgnoreLength);
              // minimize number of queries
<span class="nc bnc" id="L552" title="All 2 branches missed.">              if (cf.spanQueryList.contains(q)) {</span>
<span class="nc" id="L553">                q = cf.spanQueryList.get(cf.spanQueryList.indexOf(q));</span>
              } else {
<span class="nc" id="L555">                cf.spanQueryList.add(q);</span>
              }
<span class="nc" id="L557">              eql[j] = q;</span>
            }
<span class="nc" id="L559">            String newKey = generateKey(key + &quot; (&quot; + e + &quot;)&quot;,</span>
                expandedQueryVariables[e]);
            try {
<span class="nc" id="L562">              mtasFields.list.get(fields[i]).statsSpanList</span>
<span class="nc" id="L563">                  .add(new ComponentSpan(eql, newKey, minimum, maximum, type,</span>
                      functionKey, functionExpression, functionType));
<span class="nc" id="L565">            } catch (ParseException ee) {</span>
<span class="nc" id="L566">              throw new IOException(ee.getMessage());</span>
<span class="nc" id="L567">            }</span>
          }
        }
      }
<span class="fc" id="L571">    } else {</span>
<span class="nc" id="L572">      throw new IOException(&quot;missing parameters stats spans&quot;);</span>
    }
<span class="fc" id="L574">  }</span>

  /**
   * Generate key.
   *
   * @param key the key
   * @param queryVariables the query variables
   * @return the string
   */
  private String generateKey(String key,
      HashMap&lt;String, String[]&gt;[] queryVariables) {
<span class="nc" id="L585">    StringBuilder newKey = new StringBuilder(key);</span>
<span class="nc" id="L586">    newKey.append(&quot; -&quot;);</span>
<span class="nc bnc" id="L587" title="All 2 branches missed.">    for (int q = 0; q &lt; queryVariables.length; q++) {</span>
<span class="nc bnc" id="L588" title="All 4 branches missed.">      if (queryVariables[q] != null &amp;&amp; queryVariables[q].size() &gt; 0) {</span>
<span class="nc bnc" id="L589" title="All 2 branches missed.">        for (String name : queryVariables[q].keySet()) {</span>
<span class="nc" id="L590">          newKey.append(&quot; q&quot; + q + &quot;:$&quot; + name + &quot;=&quot;);</span>
<span class="nc bnc" id="L591" title="All 2 branches missed.">          if (queryVariables[q].get(name) != null</span>
<span class="nc bnc" id="L592" title="All 2 branches missed.">              &amp;&amp; queryVariables[q].get(name).length == 1) {</span>
<span class="nc" id="L593">            newKey.append(&quot;'&quot; + queryVariables[q].get(name)[0]</span>
<span class="nc" id="L594">                .replace(&quot;\\&quot;, &quot;\\\\&quot;).replace(&quot;,&quot;, &quot;\\,&quot;) + &quot;'&quot;);</span>
          } else {
<span class="nc" id="L596">            newKey.append(&quot;-&quot;);</span>
          }
<span class="nc" id="L598">        }</span>
      }
    }
<span class="nc" id="L601">    return newKey.toString();</span>
  }

  /**
   * Expanded query variables.
   *
   * @param queryVariables the query variables
   * @return the hash map[][]
   */
  private HashMap&lt;String, String[]&gt;[][] expandedQueryVariables(
      HashMap&lt;String, String[]&gt;[] queryVariables) {
<span class="nc" id="L612">    HashMap&lt;String, String[]&gt;[][] subResult = new HashMap[queryVariables.length][];</span>
<span class="nc bnc" id="L613" title="All 2 branches missed.">    for (int q = 0; q &lt; queryVariables.length; q++) {</span>
<span class="nc" id="L614">      subResult[q] = expandedQueryVariables(queryVariables[q]);</span>
    }
<span class="nc" id="L616">    ArrayList&lt;HashMap&lt;String, String[]&gt;[]&gt; result = new ArrayList&lt;&gt;();</span>
<span class="nc" id="L617">    generatePermutations(result, 0, subResult);</span>
<span class="nc" id="L618">    return result.toArray(new HashMap[result.size()][]);</span>
  }

  /**
   * Generate permutations.
   *
   * @param result the result
   * @param index the index
   * @param subResult the sub result
   */
  private void generatePermutations(
      ArrayList&lt;HashMap&lt;String, String[]&gt;[]&gt; result, int index,
      HashMap&lt;String, String[]&gt;[][] subResult) {
<span class="nc" id="L631">    int localIndex = index;</span>
<span class="nc" id="L632">    HashMap&lt;String, String[]&gt;[] value = subResult[localIndex];</span>
<span class="nc bnc" id="L633" title="All 2 branches missed.">    if (localIndex == 0) {</span>
<span class="nc bnc" id="L634" title="All 2 branches missed.">      for (int i = 0; i &lt; value.length; i++) {</span>
<span class="nc" id="L635">        HashMap&lt;String, String[]&gt;[] resultItem = new HashMap[subResult.length];</span>
<span class="nc" id="L636">        resultItem[localIndex] = value[i];</span>
<span class="nc" id="L637">        result.add(resultItem);</span>
      }
    } else {
<span class="nc" id="L640">      ArrayList&lt;HashMap&lt;String, String[]&gt;[]&gt; newResult = new ArrayList&lt;&gt;();</span>
<span class="nc bnc" id="L641" title="All 2 branches missed.">      for (int e = 0; e &lt; result.size(); e++) {</span>
<span class="nc bnc" id="L642" title="All 2 branches missed.">        for (int i = 0; i &lt; value.length; i++) {</span>
<span class="nc" id="L643">          HashMap&lt;String, String[]&gt;[] resultItem = result.get(e);</span>
<span class="nc" id="L644">          resultItem[localIndex] = value[i];</span>
<span class="nc" id="L645">          newResult.add(resultItem);</span>
        }
      }
<span class="nc" id="L648">      result.clear();</span>
<span class="nc" id="L649">      result.addAll(newResult);</span>
    }
<span class="nc" id="L651">    localIndex++;</span>
<span class="nc bnc" id="L652" title="All 2 branches missed.">    if (localIndex &lt; subResult.length) {</span>
<span class="nc" id="L653">      generatePermutations(result, localIndex, subResult);</span>
    }
<span class="nc" id="L655">  }</span>

  /**
   * Expanded query variables.
   *
   * @param queryVariables the query variables
   * @return the hash map[]
   */
  private HashMap&lt;String, String[]&gt;[] expandedQueryVariables(
      HashMap&lt;String, String[]&gt; queryVariables) {
<span class="nc" id="L665">    ArrayList&lt;HashMap&lt;String, String[]&gt;&gt; result = new ArrayList&lt;&gt;();</span>
<span class="nc" id="L666">    Set&lt;String&gt; keys = queryVariables.keySet();</span>
<span class="nc" id="L667">    generatePermutationsQueryVariables(result, keys, queryVariables);</span>
<span class="nc" id="L668">    return result.toArray(new HashMap[result.size()]);</span>
  }

  /**
   * Generate permutations query variables.
   *
   * @param result the result
   * @param keys the keys
   * @param queryVariables the query variables
   */
  private void generatePermutationsQueryVariables(
      ArrayList&lt;HashMap&lt;String, String[]&gt;&gt; result, Set&lt;String&gt; keys,
      HashMap&lt;String, String[]&gt; queryVariables) {
<span class="nc bnc" id="L681" title="All 4 branches missed.">    if (keys != null &amp;&amp; !keys.isEmpty()) {</span>
<span class="nc" id="L682">      Set&lt;String&gt; newKeys = new HashSet&lt;&gt;();</span>
<span class="nc" id="L683">      Iterator&lt;String&gt; it = keys.iterator();</span>
<span class="nc" id="L684">      String key = it.next();</span>
<span class="nc" id="L685">      String[] value = queryVariables.get(key);</span>
<span class="nc bnc" id="L686" title="All 2 branches missed.">      if (result.isEmpty()) {</span>
        HashMap&lt;String, String[]&gt; newItem;
<span class="nc bnc" id="L688" title="All 4 branches missed.">        if (value == null || value.length == 0) {</span>
<span class="nc" id="L689">          newItem = new HashMap&lt;&gt;();</span>
<span class="nc" id="L690">          newItem.put(key, value);</span>
<span class="nc" id="L691">          result.add(newItem);</span>
        } else {
<span class="nc bnc" id="L693" title="All 2 branches missed.">          for (int j = 0; j &lt; value.length; j++) {</span>
<span class="nc" id="L694">            newItem = new HashMap&lt;&gt;();</span>
<span class="nc" id="L695">            newItem.put(key, new String[] { value[j] });</span>
<span class="nc" id="L696">            result.add(newItem);</span>
          }
        }
      } else {
<span class="nc" id="L700">        ArrayList&lt;HashMap&lt;String, String[]&gt;&gt; newResult = new ArrayList&lt;&gt;();</span>
<span class="nc bnc" id="L701" title="All 2 branches missed.">        for (int i = 0; i &lt; result.size(); i++) {</span>
          HashMap&lt;String, String[]&gt; newItem;
<span class="nc bnc" id="L703" title="All 4 branches missed.">          if (value == null || value.length == 0) {</span>
<span class="nc" id="L704">            newItem = (HashMap&lt;String, String[]&gt;) result.get(i).clone();</span>
<span class="nc" id="L705">            newItem.put(key, value);</span>
<span class="nc" id="L706">            newResult.add(newItem);</span>
          } else {
<span class="nc bnc" id="L708" title="All 2 branches missed.">            for (int j = 0; j &lt; value.length; j++) {</span>
<span class="nc" id="L709">              newItem = (HashMap&lt;String, String[]&gt;) result.get(i).clone();</span>
<span class="nc" id="L710">              newItem.put(key, new String[] { value[j] });</span>
<span class="nc" id="L711">              newResult.add(newItem);</span>
            }
          }
        }
<span class="nc" id="L715">        result.clear();</span>
<span class="nc" id="L716">        result.addAll(newResult);</span>
      }
<span class="nc bnc" id="L718" title="All 2 branches missed.">      while (it.hasNext()) {</span>
<span class="nc" id="L719">        newKeys.add(it.next());</span>
      }
<span class="nc" id="L721">      generatePermutationsQueryVariables(result, newKeys, queryVariables);</span>
    }
<span class="nc" id="L723">  }</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="fc bfc" id="L736" title="All 2 branches covered.">    if ((sreq.purpose &amp; ShardRequest.PURPOSE_GET_TOP_IDS) != 0) {</span>
      // do nothing
    } else {
      // remove stats for other requests
<span class="fc" id="L740">      sreq.params.remove(PARAM_MTAS_STATS);</span>
<span class="fc" id="L741">      sreq.params.remove(PARAM_MTAS_STATS_POSITIONS);</span>
<span class="fc" id="L742">      Set&lt;String&gt; keys = MtasSolrResultUtil</span>
<span class="fc" id="L743">          .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_STATS_POSITIONS);</span>
<span class="fc bfc" id="L744" title="All 2 branches covered.">      for (String key : keys) {</span>
<span class="fc" id="L745">        sreq.params.remove(</span>
            PARAM_MTAS_STATS + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_STATS_POSITIONS_KEY);
<span class="fc" id="L747">        sreq.params.remove(PARAM_MTAS_STATS + &quot;.&quot; + key + &quot;.&quot;</span>
            + NAME_MTAS_STATS_POSITIONS_FIELD);
<span class="fc" id="L749">        sreq.params.remove(PARAM_MTAS_STATS + &quot;.&quot; + key + &quot;.&quot;</span>
            + NAME_MTAS_STATS_POSITIONS_TYPE);
<span class="fc" id="L751">        sreq.params.remove(PARAM_MTAS_STATS + &quot;.&quot; + key + &quot;.&quot;</span>
            + NAME_MTAS_STATS_POSITIONS_MAXIMUM);
<span class="fc" id="L753">        sreq.params.remove(PARAM_MTAS_STATS + &quot;.&quot; + key + &quot;.&quot;</span>
            + NAME_MTAS_STATS_POSITIONS_MINIMUM);
<span class="fc" id="L755">      }</span>
<span class="fc" id="L756">      sreq.params.remove(PARAM_MTAS_STATS_TOKENS);</span>
<span class="fc" id="L757">      keys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
          PARAM_MTAS_STATS_TOKENS);
<span class="fc bfc" id="L759" title="All 2 branches covered.">      for (String key : keys) {</span>
<span class="fc" id="L760">        sreq.params.remove(</span>
            PARAM_MTAS_STATS + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_STATS_TOKENS_KEY);
<span class="fc" id="L762">        sreq.params.remove(</span>
            PARAM_MTAS_STATS + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_STATS_TOKENS_FIELD);
<span class="fc" id="L764">        sreq.params.remove(</span>
            PARAM_MTAS_STATS + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_STATS_TOKENS_TYPE);
<span class="fc" id="L766">        sreq.params.remove(PARAM_MTAS_STATS + &quot;.&quot; + key + &quot;.&quot;</span>
            + NAME_MTAS_STATS_TOKENS_MAXIMUM);
<span class="fc" id="L768">        sreq.params.remove(PARAM_MTAS_STATS + &quot;.&quot; + key + &quot;.&quot;</span>
            + NAME_MTAS_STATS_TOKENS_MINIMUM);
<span class="fc" id="L770">      }</span>
<span class="fc" id="L771">      sreq.params.remove(PARAM_MTAS_STATS_SPANS);</span>
<span class="fc" id="L772">      keys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
          PARAM_MTAS_STATS_SPANS);
<span class="fc bfc" id="L774" title="All 2 branches covered.">      for (String key : keys) {</span>
<span class="fc" id="L775">        sreq.params.remove(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + key + &quot;.&quot;</span>
            + NAME_MTAS_STATS_SPANS_KEY);
<span class="fc" id="L777">        sreq.params.remove(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + key + &quot;.&quot;</span>
            + NAME_MTAS_STATS_SPANS_FIELD);
<span class="fc" id="L779">        sreq.params.remove(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + key + &quot;.&quot;</span>
            + NAME_MTAS_STATS_SPANS_TYPE);
<span class="fc" id="L781">        sreq.params.remove(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + key + &quot;.&quot;</span>
            + NAME_MTAS_STATS_SPANS_MAXIMUM);
<span class="fc" id="L783">        sreq.params.remove(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + key + &quot;.&quot;</span>
            + NAME_MTAS_STATS_SPANS_MINIMUM);
<span class="fc" id="L785">        Set&lt;String&gt; subKeys = MtasSolrResultUtil</span>
<span class="fc" id="L786">            .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_STATS_SPANS</span>
                + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_STATS_SPANS_FUNCTION);
<span class="pc bpc" id="L788" title="1 of 2 branches missed.">        for (String subKey : subKeys) {</span>
<span class="nc" id="L789">          sreq.params.remove(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_STATS_SPANS_FUNCTION + &quot;.&quot; + subKey + &quot;.&quot;
              + SUBNAME_MTAS_STATS_SPANS_FUNCTION_EXPRESSION);
<span class="nc" id="L792">          sreq.params.remove(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_STATS_SPANS_FUNCTION + &quot;.&quot; + subKey + &quot;.&quot;
              + SUBNAME_MTAS_STATS_SPANS_FUNCTION_KEY);
<span class="nc" id="L795">          sreq.params.remove(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_STATS_SPANS_FUNCTION + &quot;.&quot; + subKey + &quot;.&quot;
              + SUBNAME_MTAS_STATS_SPANS_FUNCTION_TYPE);
<span class="nc" id="L798">        }</span>
<span class="fc" id="L799">        subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
            PARAM_MTAS_STATS_SPANS + &quot;.&quot; + key + &quot;.&quot;
                + NAME_MTAS_STATS_SPANS_QUERY);
<span class="fc bfc" id="L802" title="All 2 branches covered.">        for (String subKey : subKeys) {</span>
<span class="fc" id="L803">          sreq.params.remove(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_STATS_SPANS_QUERY + &quot;.&quot; + subKey + &quot;.&quot;
              + SUBNAME_MTAS_STATS_SPANS_QUERY_IGNORE);
<span class="fc" id="L806">          sreq.params.remove(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_STATS_SPANS_QUERY + &quot;.&quot; + subKey + &quot;.&quot;
              + SUBNAME_MTAS_STATS_SPANS_QUERY_MAXIMUM_IGNORE_LENGTH);
<span class="fc" id="L809">          sreq.params.remove(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_STATS_SPANS_QUERY + &quot;.&quot; + subKey + &quot;.&quot;
              + SUBNAME_MTAS_STATS_SPANS_QUERY_PREFIX);
<span class="fc" id="L812">          sreq.params.remove(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_STATS_SPANS_QUERY + &quot;.&quot; + subKey + &quot;.&quot;
              + SUBNAME_MTAS_STATS_SPANS_QUERY_TYPE);
<span class="fc" id="L815">          sreq.params.remove(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_STATS_SPANS_QUERY + &quot;.&quot; + subKey + &quot;.&quot;
              + SUBNAME_MTAS_STATS_SPANS_QUERY_VALUE);
<span class="fc" id="L818">          Set&lt;String&gt; subSubKeys = MtasSolrResultUtil.getIdsFromParameters(</span>
<span class="fc" id="L819">              rb.req.getParams(),</span>
              PARAM_MTAS_STATS_SPANS + &quot;.&quot; + key + &quot;.&quot;
                  + NAME_MTAS_STATS_SPANS_QUERY + &quot;.&quot; + subKey + &quot;.&quot;
                  + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE);
<span class="fc bfc" id="L823" title="All 2 branches covered.">          for (String subSubKey : subSubKeys) {</span>
<span class="fc" id="L824">            sreq.params.remove(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + key + &quot;.&quot;</span>
                + NAME_MTAS_STATS_SPANS_QUERY + &quot;.&quot; + subKey + &quot;.&quot;
                + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE + &quot;.&quot; + subSubKey
                + &quot;.&quot; + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE_NAME);
<span class="fc" id="L828">            sreq.params.remove(PARAM_MTAS_STATS_SPANS + &quot;.&quot; + key + &quot;.&quot;</span>
                + NAME_MTAS_STATS_SPANS_QUERY + &quot;.&quot; + subKey + &quot;.&quot;
                + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE + &quot;.&quot; + subSubKey
                + &quot;.&quot; + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE_VALUE);
<span class="fc" id="L832">          }</span>
<span class="fc" id="L833">        }</span>
<span class="fc" id="L834">      }</span>
    }
<span class="fc" id="L836">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see
   * mtas.solr.handler.component.util.MtasSolrComponent#create(mtas.codec.util.
   * CodecComponent.BasicComponent, java.lang.Boolean)
   */
  @Override
  public SimpleOrderedMap&lt;Object&gt; create(ComponentStats response,
      Boolean encode) throws IOException {
<span class="fc bfc" id="L848" title="All 2 branches covered.">    if (response instanceof ComponentPosition) {</span>
<span class="fc" id="L849">      return createPosition((ComponentPosition) response, encode);</span>
<span class="fc bfc" id="L850" title="All 2 branches covered.">    } else if (response instanceof ComponentToken) {</span>
<span class="fc" id="L851">      return createToken((ComponentToken) response, encode);</span>
<span class="pc bpc" id="L852" title="1 of 2 branches missed.">    } else if (response instanceof ComponentSpan) {</span>
<span class="fc" id="L853">      return createSpan((ComponentSpan) response, encode);</span>
    } else {
<span class="nc" id="L855">      throw new IOException(&quot;incorrect type &quot; + response.getClass());</span>
    }
  }

  /**
   * Creates the position.
   *
   * @param position the position
   * @param encode the encode
   * @return the simple ordered map
   * @throws IOException Signals that an I/O exception has occurred.
   */
  private SimpleOrderedMap&lt;Object&gt; createPosition(ComponentPosition position,
      Boolean encode) throws IOException {
    // System.out.println(&quot;Create stats position &quot; + position.dataType + &quot; &quot;
    // + position.statsType + &quot; &quot; + position.statsItems + &quot; --- &quot; + encode);
<span class="fc" id="L871">    SimpleOrderedMap&lt;Object&gt; mtasPositionResponse = new SimpleOrderedMap&lt;&gt;();</span>
<span class="fc" id="L872">    mtasPositionResponse.add(&quot;key&quot;, position.key);</span>
<span class="fc" id="L873">    MtasSolrMtasResult data = new MtasSolrMtasResult(position.dataCollector,</span>
        position.dataType, position.statsType, position.statsItems, null);
<span class="fc bfc" id="L875" title="All 2 branches covered.">    if (encode) {</span>
<span class="fc" id="L876">      mtasPositionResponse.add(&quot;_encoded_data&quot;,</span>
<span class="fc" id="L877">          MtasSolrResultUtil.encode(data));</span>
    } else {
<span class="fc" id="L879">      mtasPositionResponse.add(position.dataCollector.getCollectorType(), data);</span>
<span class="fc" id="L880">      MtasSolrResultUtil.rewrite(mtasPositionResponse);</span>
    }
<span class="fc" id="L882">    return mtasPositionResponse;</span>
  }

  /**
   * Creates the token.
   *
   * @param token the token
   * @param encode the encode
   * @return the simple ordered map
   * @throws IOException Signals that an I/O exception has occurred.
   */
  private SimpleOrderedMap&lt;Object&gt; createToken(ComponentToken token,
      Boolean encode) throws IOException {
    // System.out.println(&quot;Create stats position &quot; + position.dataType + &quot; &quot;
    // + position.statsType + &quot; &quot; + position.statsItems + &quot; --- &quot; + encode);
<span class="fc" id="L897">    SimpleOrderedMap&lt;Object&gt; mtasTokenResponse = new SimpleOrderedMap&lt;&gt;();</span>
<span class="fc" id="L898">    mtasTokenResponse.add(&quot;key&quot;, token.key);</span>
<span class="fc" id="L899">    MtasSolrMtasResult data = new MtasSolrMtasResult(token.dataCollector,</span>
        token.dataType, token.statsType, token.statsItems, null);
<span class="fc bfc" id="L901" title="All 2 branches covered.">    if (encode) {</span>
<span class="fc" id="L902">      mtasTokenResponse.add(&quot;_encoded_data&quot;, MtasSolrResultUtil.encode(data));</span>
    } else {
<span class="fc" id="L904">      mtasTokenResponse.add(token.dataCollector.getCollectorType(), data);</span>
<span class="fc" id="L905">      MtasSolrResultUtil.rewrite(mtasTokenResponse);</span>
    }
<span class="fc" id="L907">    return mtasTokenResponse;</span>
  }

  /**
   * Creates the span.
   *
   * @param span the span
   * @param encode the encode
   * @return the simple ordered map
   * @throws IOException Signals that an I/O exception has occurred.
   */
  @SuppressWarnings(&quot;unchecked&quot;)
  private SimpleOrderedMap&lt;Object&gt; createSpan(ComponentSpan span,
      Boolean encode) throws IOException {
    // System.out.println(&quot;Create stats span &quot; + span.dataType + &quot; &quot;
    // + span.statsType + &quot; &quot; + span.statsItems + &quot; --- &quot; + encode);
<span class="fc" id="L923">    SimpleOrderedMap&lt;Object&gt; mtasSpanResponse = new SimpleOrderedMap&lt;&gt;();</span>
<span class="fc" id="L924">    mtasSpanResponse.add(&quot;key&quot;, span.key);</span>
<span class="fc" id="L925">    HashMap&lt;MtasDataCollector&lt;?, ?&gt;, HashMap&lt;String, MtasSolrMtasResult&gt;&gt; functionData = new HashMap&lt;&gt;();</span>
<span class="fc" id="L926">    HashMap&lt;String, MtasSolrMtasResult&gt; functionDataItem = new HashMap&lt;&gt;();</span>
<span class="fc" id="L927">    functionData.put(span.dataCollector, functionDataItem);</span>
<span class="pc bpc" id="L928" title="1 of 2 branches missed.">    if (span.functions != null) {</span>
<span class="pc bpc" id="L929" title="1 of 2 branches missed.">      for (SubComponentFunction function : span.functions) {</span>
<span class="nc" id="L930">        function.dataCollector.close();</span>
<span class="nc" id="L931">        functionDataItem.put(function.key,</span>
            new MtasSolrMtasResult(function.dataCollector,
                new String[] { function.dataType },
                new String[] { function.statsType },
                new SortedSet[] { function.statsItems }, new String[] { null },
<span class="nc" id="L936">                new String[] { null }, new Integer[] { 0 },</span>
<span class="nc" id="L937">                new Integer[] { Integer.MAX_VALUE }, null));</span>
<span class="nc" id="L938">      }</span>
    }
<span class="fc" id="L940">    MtasSolrMtasResult data = new MtasSolrMtasResult(span.dataCollector,</span>
        span.dataType, span.statsType, span.statsItems, functionData);
<span class="fc bfc" id="L942" title="All 2 branches covered.">    if (encode) {</span>
<span class="fc" id="L943">      mtasSpanResponse.add(&quot;_encoded_data&quot;, MtasSolrResultUtil.encode(data));</span>
    } else {
<span class="fc" id="L945">      mtasSpanResponse.add(span.dataCollector.getCollectorType(), data);</span>
<span class="fc" id="L946">      MtasSolrResultUtil.rewrite(mtasSpanResponse);</span>
    }
<span class="fc" id="L948">    return mtasSpanResponse;</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="pc bpc" id="L960" title="1 of 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="fc bfc" id="L963" title="All 2 branches covered.">      for (ShardRequest sreq : rb.finished) {</span>
<span class="pc bpc" id="L964" title="1 of 2 branches missed.">        if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="pc bpc" id="L965" title="1 of 2 branches missed.">            &amp;&amp; sreq.params.getBool(PARAM_MTAS_STATS, false)) {</span>
<span class="fc bfc" id="L966" title="All 2 branches covered.">          for (ShardResponse shardResponse : sreq.responses) {</span>
<span class="fc" id="L967">            NamedList&lt;Object&gt; response = shardResponse.getSolrResponse()</span>
<span class="fc" id="L968">                .getResponse();</span>
            try {
<span class="fc" id="L970">              ArrayList&lt;NamedList&lt;Object&gt;&gt; data = (ArrayList&lt;NamedList&lt;Object&gt;&gt;) response</span>
<span class="nc" id="L971">                  .findRecursive(&quot;mtas&quot;, &quot;stats&quot;);</span>
<span class="nc bnc" id="L972" title="All 2 branches missed.">              if (data != null) {</span>
<span class="nc" id="L973">                MtasSolrResultUtil.decode(data);</span>
              }
<span class="fc" id="L975">            } catch (ClassCastException e) {</span>
<span class="fc" id="L976">              log.debug(e);</span>
              // shouldnt happen
<span class="nc" id="L978">            }</span>
<span class="fc" id="L979">          }</span>
        }
<span class="fc" id="L981">      }</span>
    }
<span class="fc" id="L983">  }</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="fc" id="L997">    NamedList&lt;Object&gt; mtasResponse = null;</span>
    try {
<span class="fc" id="L999">      mtasResponse = (NamedList&lt;Object&gt;) rb.rsp.getValues().get(&quot;mtas&quot;);</span>
<span class="nc" id="L1000">    } catch (ClassCastException e) {</span>
<span class="nc" id="L1001">      log.debug(e);</span>
<span class="nc" id="L1002">      mtasResponse = null;</span>
<span class="fc" id="L1003">    }</span>
<span class="pc bpc" id="L1004" title="1 of 2 branches missed.">    if (mtasResponse != null) {</span>
      NamedList&lt;Object&gt; mtasResponseStats;
      try {
<span class="fc" id="L1007">        mtasResponseStats = (NamedList&lt;Object&gt;) mtasResponse.get(&quot;stats&quot;);</span>
<span class="pc bpc" id="L1008" title="1 of 2 branches missed.">        if (mtasResponseStats != null) {</span>
<span class="fc" id="L1009">          MtasSolrResultUtil.rewrite(mtasResponseStats);</span>
        }
<span class="nc" id="L1011">      } catch (ClassCastException e) {</span>
<span class="nc" id="L1012">        log.debug(e);</span>
<span class="nc" id="L1013">        mtasResponse.remove(&quot;stats&quot;);</span>
<span class="fc" id="L1014">      }</span>
    }
<span class="fc" id="L1016">  }</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>