MtasSolrComponentKwic.java.html 34 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
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>MtasSolrComponentKwic.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">MTAS</a> &gt; <a href="index.source.html" class="el_package">mtas.solr.handler.component.util</a> &gt; <span class="el_source">MtasSolrComponentKwic.java</span></div><h1>MtasSolrComponentKwic.java</h1><pre class="source lang-java linenums">package mtas.solr.handler.component.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.handler.component.SearchComponent;
import org.apache.solr.handler.component.ShardRequest;

import mtas.analysis.token.MtasToken;
import mtas.codec.util.CodecUtil;
import mtas.search.spans.util.MtasSpanQuery;
import mtas.codec.util.CodecComponent.ComponentField;
import mtas.codec.util.CodecComponent.ComponentFields;
import mtas.codec.util.CodecComponent.ComponentKwic;
import mtas.codec.util.CodecComponent.KwicHit;
import mtas.codec.util.CodecComponent.KwicToken;
import mtas.solr.handler.component.MtasSolrSearchComponent;

/**
 * The Class MtasSolrComponentKwic.
 */
public class MtasSolrComponentKwic implements MtasSolrComponent&lt;ComponentKwic&gt; {

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

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

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

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

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

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

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

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

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

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

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

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

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

  /** The Constant NAME_MTAS_KWIC_START. */
  public static final String NAME_MTAS_KWIC_START = &quot;start&quot;;

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

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

  /** The Constant NAME_MTAS_KWIC_OUTPUT. */
  public static final String NAME_MTAS_KWIC_OUTPUT = &quot;output&quot;;

  /**
   * Instantiates a new mtas solr component kwic.
   *
   * @param searchComponent the search component
   */
<span class="fc" id="L90">  public MtasSolrComponentKwic(MtasSolrSearchComponent searchComponent) {</span>
<span class="fc" id="L91">  }</span>

  /**
   * Gets the positive integer.
   *
   * @param number the number
   * @return the positive integer
   */
  private int getPositiveInteger(String number) {
    try {
<span class="nc" id="L101">      return Math.max(0, Integer.parseInt(number));</span>
<span class="nc" id="L102">    } catch (NumberFormatException e) {</span>
<span class="nc" id="L103">      return 0;</span>
    }
  }

  /* (non-Javadoc)
   * @see mtas.solr.handler.component.util.MtasSolrComponent#prepare(org.apache.solr.handler.component.ResponseBuilder, mtas.codec.util.CodecComponent.ComponentFields)
   */
  public void prepare(ResponseBuilder rb, ComponentFields mtasFields)
      throws IOException {
<span class="nc" id="L112">    Set&lt;String&gt; ids = MtasSolrResultUtil</span>
<span class="nc" id="L113">        .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_KWIC);</span>
<span class="nc bnc" id="L114" title="All 2 branches missed.">    if (!ids.isEmpty()) {</span>
<span class="nc" id="L115">      int tmpCounter = 0;</span>
<span class="nc" id="L116">      String[] fields = new String[ids.size()];</span>
<span class="nc" id="L117">      String[] queryTypes = new String[ids.size()];</span>
<span class="nc" id="L118">      String[] queryValues = new String[ids.size()];</span>
<span class="nc" id="L119">      String[] queryPrefixes = new String[ids.size()];</span>
<span class="nc" id="L120">      String[] queryIgnores = new String[ids.size()];</span>
<span class="nc" id="L121">      String[] queryMaximumIgnoreLengths = new String[ids.size()];</span>
<span class="nc" id="L122">      HashMap&lt;String, String[]&gt;[] queryVariables = new HashMap[ids.size()];</span>
<span class="nc" id="L123">      String[] keys = new String[ids.size()];</span>
<span class="nc" id="L124">      String[] prefixes = new String[ids.size()];</span>
<span class="nc" id="L125">      String[] numbers = new String[ids.size()];</span>
<span class="nc" id="L126">      String[] starts = new String[ids.size()];</span>
<span class="nc" id="L127">      String[] lefts = new String[ids.size()];</span>
<span class="nc" id="L128">      String[] rights = new String[ids.size()];</span>
<span class="nc" id="L129">      String[] outputs = new String[ids.size()];</span>
<span class="nc bnc" id="L130" title="All 2 branches missed.">      for (String id : ids) {</span>
<span class="nc" id="L131">        fields[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L132">            .get(PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_FIELD, null);</span>
<span class="nc" id="L133">        queryTypes[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_TYPE, null);
<span class="nc" id="L135">        queryValues[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_VALUE,
            null);
<span class="nc" id="L138">        queryPrefixes[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_PREFIX,
            null);
<span class="nc" id="L141">        queryIgnores[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_IGNORE,
            null);
<span class="nc" id="L144">        queryMaximumIgnoreLengths[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L145">            .get(PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot;</span>
                + NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH, null);
<span class="nc" id="L147">        Set&lt;String&gt; vIds = MtasSolrResultUtil.getIdsFromParameters(</span>
<span class="nc" id="L148">            rb.req.getParams(),</span>
            PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_VARIABLE);
<span class="nc" id="L150">        queryVariables[tmpCounter] = new HashMap&lt;&gt;();</span>
<span class="nc bnc" id="L151" title="All 2 branches missed.">        if (!vIds.isEmpty()) {</span>
<span class="nc" id="L152">          HashMap&lt;String, ArrayList&lt;String&gt;&gt; tmpVariables = new HashMap&lt;&gt;();</span>
<span class="nc bnc" id="L153" title="All 2 branches missed.">          for (String vId : vIds) {</span>
<span class="nc" id="L154">            String name = rb.req.getParams().get(</span>
                PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_VARIABLE
                    + &quot;.&quot; + vId + &quot;.&quot; + SUBNAME_MTAS_KWIC_QUERY_VARIABLE_NAME,
                null);
<span class="nc bnc" id="L158" title="All 2 branches missed.">            if (name != null) {</span>
<span class="nc bnc" id="L159" title="All 2 branches missed.">              if (!tmpVariables.containsKey(name)) {</span>
<span class="nc" id="L160">                tmpVariables.put(name, new ArrayList&lt;String&gt;());</span>
              }
<span class="nc" id="L162">              String value = rb.req.getParams()</span>
<span class="nc" id="L163">                  .get(PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot;</span>
                      + NAME_MTAS_KWIC_QUERY_VARIABLE + &quot;.&quot; + vId + &quot;.&quot;
                      + SUBNAME_MTAS_KWIC_QUERY_VARIABLE_VALUE, null);
<span class="nc bnc" id="L166" title="All 2 branches missed.">              if (value != null) {</span>
<span class="nc" id="L167">                ArrayList&lt;String&gt; list = new ArrayList&lt;&gt;();</span>
<span class="nc" id="L168">                String[] subList = value.split(&quot;(?&lt;!\\\\),&quot;);</span>
<span class="nc bnc" id="L169" title="All 2 branches missed.">                for (int i = 0; i &lt; subList.length; i++) {</span>
<span class="nc" id="L170">                  list.add(</span>
<span class="nc" id="L171">                      subList[i].replace(&quot;\\,&quot;, &quot;,&quot;).replace(&quot;\\\\&quot;, &quot;\\&quot;));</span>
                }
<span class="nc" id="L173">                tmpVariables.get(name).addAll(list);</span>
              }
            }
<span class="nc" id="L176">          }</span>
<span class="nc bnc" id="L177" title="All 2 branches missed.">          for (Entry&lt;String, ArrayList&lt;String&gt;&gt; entry : tmpVariables</span>
<span class="nc" id="L178">              .entrySet()) {</span>
<span class="nc" id="L179">            queryVariables[tmpCounter].put(entry.getKey(),</span>
<span class="nc" id="L180">                entry.getValue().toArray(new String[entry.getValue().size()]));</span>
<span class="nc" id="L181">          }</span>
        }
<span class="nc" id="L183">        keys[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L184">            .get(PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_KEY,</span>
<span class="nc" id="L185">                String.valueOf(tmpCounter))</span>
<span class="nc" id="L186">            .trim();</span>
<span class="nc" id="L187">        prefixes[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_PREFIX, null);
<span class="nc" id="L189">        numbers[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_NUMBER, null);
<span class="nc" id="L191">        starts[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L192">            .get(PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_START, null);</span>
<span class="nc" id="L193">        lefts[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L194">            .get(PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_LEFT, null);</span>
<span class="nc" id="L195">        rights[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L196">            .get(PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_RIGHT, null);</span>
<span class="nc" id="L197">        starts[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L198">            .get(PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_START, null);</span>
<span class="nc" id="L199">        outputs[tmpCounter] = rb.req.getParams().get(</span>
            PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_OUTPUT, null);
<span class="nc" id="L201">        tmpCounter++;</span>
<span class="nc" id="L202">      }</span>
<span class="nc" id="L203">      String uniqueKeyField = rb.req.getSchema().getUniqueKeyField().getName();</span>
<span class="nc" id="L204">      mtasFields.doKwic = true;</span>
<span class="nc" id="L205">      rb.setNeedDocList(true);</span>
<span class="nc bnc" id="L206" title="All 2 branches missed.">      for (String field : fields) {</span>
<span class="nc bnc" id="L207" title="All 4 branches missed.">        if (field == null || field.isEmpty()) {</span>
<span class="nc" id="L208">          throw new IOException(&quot;no (valid) field in mtas kwic&quot;);</span>
<span class="nc bnc" id="L209" title="All 2 branches missed.">        } else if (!mtasFields.list.containsKey(field)) {</span>
<span class="nc" id="L210">          mtasFields.list.put(field, new ComponentField(uniqueKeyField));</span>
        }
      }
<span class="nc" id="L213">      MtasSolrResultUtil.compareAndCheck(keys, fields, NAME_MTAS_KWIC_KEY,</span>
<span class="nc" id="L214">          NAME_MTAS_KWIC_FIELD, true);</span>
<span class="nc" id="L215">      MtasSolrResultUtil.compareAndCheck(queryValues, fields,</span>
<span class="nc" id="L216">          NAME_MTAS_KWIC_QUERY_VALUE, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L217">      MtasSolrResultUtil.compareAndCheck(queryTypes, fields,</span>
<span class="nc" id="L218">          NAME_MTAS_KWIC_QUERY_TYPE, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L219">      MtasSolrResultUtil.compareAndCheck(queryPrefixes, fields,</span>
<span class="nc" id="L220">          NAME_MTAS_KWIC_QUERY_PREFIX, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L221">      MtasSolrResultUtil.compareAndCheck(queryIgnores, fields,</span>
<span class="nc" id="L222">          NAME_MTAS_KWIC_QUERY_IGNORE, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L223">      MtasSolrResultUtil.compareAndCheck(queryMaximumIgnoreLengths, fields,</span>
          NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH, NAME_MTAS_KWIC_FIELD,
<span class="nc" id="L225">          false);</span>
<span class="nc" id="L226">      MtasSolrResultUtil.compareAndCheck(prefixes, fields,</span>
<span class="nc" id="L227">          NAME_MTAS_KWIC_PREFIX, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L228">      MtasSolrResultUtil.compareAndCheck(numbers, fields, NAME_MTAS_KWIC_NUMBER,</span>
<span class="nc" id="L229">          NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L230">      MtasSolrResultUtil.compareAndCheck(starts, fields, NAME_MTAS_KWIC_START,</span>
<span class="nc" id="L231">          NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L232">      MtasSolrResultUtil.compareAndCheck(lefts, fields, NAME_MTAS_KWIC_LEFT,</span>
<span class="nc" id="L233">          NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L234">      MtasSolrResultUtil.compareAndCheck(rights, fields, NAME_MTAS_KWIC_RIGHT,</span>
<span class="nc" id="L235">          NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L236">      MtasSolrResultUtil.compareAndCheck(outputs, fields, NAME_MTAS_KWIC_OUTPUT,</span>
<span class="nc" id="L237">          NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc bnc" id="L238" title="All 2 branches missed.">      for (int i = 0; i &lt; fields.length; i++) {</span>
<span class="nc" id="L239">        ComponentField cf = mtasFields.list.get(fields[i]);</span>
<span class="nc bnc" id="L240" title="All 2 branches missed.">        Integer maximumIgnoreLength = (queryMaximumIgnoreLengths[i] == null)</span>
<span class="nc" id="L241">            ? null : Integer.parseInt(queryMaximumIgnoreLengths[i]);</span>
<span class="nc" id="L242">        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="L246" title="All 2 branches missed.">        if (cf.spanQueryList.contains(q)) {</span>
<span class="nc" id="L247">          q = cf.spanQueryList.get(cf.spanQueryList.indexOf(q));</span>
        } else {
<span class="nc" id="L249">          cf.spanQueryList.add(q);</span>
        }
<span class="nc bnc" id="L251" title="All 4 branches missed.">        String key = (keys[i] == null) || (keys[i].isEmpty())</span>
<span class="nc" id="L252">            ? String.valueOf(i) + &quot;:&quot; + fields[i] + &quot;:&quot; + queryValues[i]</span>
<span class="nc" id="L253">            : keys[i].trim();</span>
<span class="nc" id="L254">        String prefix = prefixes[i];</span>
<span class="nc bnc" id="L255" title="All 2 branches missed.">        Integer number = (numbers[i] != null) ? getPositiveInteger(numbers[i])</span>
            : null;
<span class="nc" id="L257">        int start = getPositiveInteger(starts[i]);</span>
<span class="nc" id="L258">        int left = getPositiveInteger(lefts[i]);</span>
<span class="nc" id="L259">        int right = getPositiveInteger(rights[i]);</span>
<span class="nc" id="L260">        String output = outputs[i];</span>
<span class="nc" id="L261">        mtasFields.list.get(fields[i]).kwicList.add(new ComponentKwic(q, key,</span>
            prefix, number, start, left, right, output));
      }
    }
<span class="nc" id="L265">  }</span>

  /* (non-Javadoc)
   * @see mtas.solr.handler.component.util.MtasSolrComponent#create(mtas.codec.util.CodecComponent.BasicComponent, java.lang.Boolean)
   */
  public SimpleOrderedMap&lt;Object&gt; create(ComponentKwic kwic, Boolean encode) {
<span class="nc" id="L271">    SimpleOrderedMap&lt;Object&gt; mtasKwicResponse = new SimpleOrderedMap&lt;&gt;();</span>
<span class="nc" id="L272">    mtasKwicResponse.add(&quot;key&quot;, kwic.key);</span>
<span class="nc" id="L273">    ArrayList&lt;NamedList&lt;Object&gt;&gt; mtasKwicItemResponses = new ArrayList&lt;&gt;();</span>
<span class="nc bnc" id="L274" title="All 2 branches missed.">    if (kwic.output.equals(ComponentKwic.KWIC_OUTPUT_HIT)) {</span>
<span class="nc bnc" id="L275" title="All 2 branches missed.">      for (int docId : kwic.hits.keySet()) {</span>
<span class="nc" id="L276">        NamedList&lt;Object&gt; mtasKwicItemResponse = new SimpleOrderedMap&lt;&gt;();</span>
<span class="nc" id="L277">        List&lt;KwicHit&gt; list = kwic.hits.get(docId);</span>
<span class="nc" id="L278">        List&lt;NamedList&lt;Object&gt;&gt; mtasKwicItemResponseItems = new ArrayList&lt;&gt;();</span>
<span class="nc bnc" id="L279" title="All 2 branches missed.">        for (KwicHit h : list) {</span>
<span class="nc" id="L280">          NamedList&lt;Object&gt; mtasKwicItemResponseItem = new SimpleOrderedMap&lt;&gt;();</span>
<span class="nc" id="L281">          SortedMap&lt;Integer, List&lt;List&lt;String&gt;&gt;&gt; hitData = new TreeMap&lt;&gt;();</span>
<span class="nc" id="L282">          SortedMap&lt;Integer, List&lt;List&lt;String&gt;&gt;&gt; leftData = null;</span>
<span class="nc" id="L283">          SortedMap&lt;Integer, List&lt;List&lt;String&gt;&gt;&gt; rightData = null;</span>
<span class="nc bnc" id="L284" title="All 2 branches missed.">          if (kwic.left &gt; 0) {</span>
<span class="nc" id="L285">            leftData = new TreeMap&lt;&gt;();</span>
          }
<span class="nc bnc" id="L287" title="All 2 branches missed.">          if (kwic.right &gt; 0) {</span>
<span class="nc" id="L288">            rightData = new TreeMap&lt;&gt;();</span>
          }
<span class="nc" id="L290">          for (int position = Math.max(0,</span>
<span class="nc bnc" id="L291" title="All 2 branches missed.">              h.startPosition - kwic.left); position &lt;= (h.endPosition</span>
<span class="nc" id="L292">                  + kwic.right); position++) {</span>
<span class="nc bnc" id="L293" title="All 2 branches missed.">            if (h.hits.containsKey(position)) {</span>
<span class="nc" id="L294">              List&lt;List&lt;String&gt;&gt; hitDataItem = new ArrayList&lt;&gt;();</span>
<span class="nc bnc" id="L295" title="All 2 branches missed.">              for (String term : h.hits.get(position)) {</span>
<span class="nc" id="L296">                List&lt;String&gt; hitDataSubItem = new ArrayList&lt;&gt;();</span>
<span class="nc" id="L297">                hitDataSubItem.add(CodecUtil.termPrefix(term));</span>
<span class="nc" id="L298">                hitDataSubItem.add(CodecUtil.termValue(term));</span>
<span class="nc" id="L299">                hitDataItem.add(hitDataSubItem);</span>
<span class="nc" id="L300">              }</span>
<span class="nc bnc" id="L301" title="All 2 branches missed.">              if (position &lt; h.startPosition) {</span>
<span class="nc bnc" id="L302" title="All 2 branches missed.">                if (leftData != null) {</span>
<span class="nc" id="L303">                  leftData.put(position, hitDataItem);</span>
                }
<span class="nc bnc" id="L305" title="All 2 branches missed.">              } else if (position &gt; h.endPosition) {</span>
<span class="nc bnc" id="L306" title="All 2 branches missed.">                if (rightData != null) {</span>
<span class="nc" id="L307">                  rightData.put(position, hitDataItem);</span>
                }
              } else {
<span class="nc" id="L310">                hitData.put(position, hitDataItem);</span>
              }
            }
          }
<span class="nc bnc" id="L314" title="All 2 branches missed.">          if (kwic.left &gt; 0) {</span>
<span class="nc" id="L315">            mtasKwicItemResponseItem.add(&quot;left&quot;, leftData);</span>
          }
<span class="nc" id="L317">          mtasKwicItemResponseItem.add(&quot;hit&quot;, hitData);</span>
<span class="nc bnc" id="L318" title="All 2 branches missed.">          if (kwic.right &gt; 0) {</span>
<span class="nc" id="L319">            mtasKwicItemResponseItem.add(&quot;right&quot;, rightData);</span>
          }
<span class="nc" id="L321">          mtasKwicItemResponseItems.add(mtasKwicItemResponseItem);</span>
<span class="nc" id="L322">        }</span>
<span class="nc" id="L323">        mtasKwicItemResponse.add(&quot;documentKey&quot;, kwic.uniqueKey.get(docId));</span>
<span class="nc" id="L324">        mtasKwicItemResponse.add(&quot;documentTotal&quot;, kwic.subTotal.get(docId));</span>
<span class="nc" id="L325">        mtasKwicItemResponse.add(&quot;documentMinPosition&quot;,</span>
<span class="nc" id="L326">            kwic.minPosition.get(docId));</span>
<span class="nc" id="L327">        mtasKwicItemResponse.add(&quot;documentMaxPosition&quot;,</span>
<span class="nc" id="L328">            kwic.maxPosition.get(docId));</span>
<span class="nc" id="L329">        mtasKwicItemResponse.add(&quot;list&quot;, mtasKwicItemResponseItems);</span>
<span class="nc" id="L330">        mtasKwicItemResponses.add(mtasKwicItemResponse);</span>
<span class="nc" id="L331">      }</span>
<span class="nc bnc" id="L332" title="All 2 branches missed.">    } else if (kwic.output.equals(ComponentKwic.KWIC_OUTPUT_TOKEN)) {</span>
<span class="nc bnc" id="L333" title="All 2 branches missed.">      for (int docId : kwic.tokens.keySet()) {</span>
<span class="nc" id="L334">        NamedList&lt;Object&gt; mtasKwicItemResponse = new SimpleOrderedMap&lt;&gt;();</span>
<span class="nc" id="L335">        List&lt;KwicToken&gt; list = kwic.tokens.get(docId);</span>
<span class="nc" id="L336">        List&lt;NamedList&lt;Object&gt;&gt; mtasKwicItemResponseItems = new ArrayList&lt;&gt;();</span>
<span class="nc bnc" id="L337" title="All 2 branches missed.">        for (KwicToken k : list) {</span>
<span class="nc" id="L338">          NamedList&lt;Object&gt; mtasKwicItemResponseItem = new SimpleOrderedMap&lt;&gt;();</span>
<span class="nc" id="L339">          mtasKwicItemResponseItem.add(&quot;startPosition&quot;, k.startPosition);</span>
<span class="nc" id="L340">          mtasKwicItemResponseItem.add(&quot;endPosition&quot;, k.endPosition);</span>
<span class="nc" id="L341">          ArrayList&lt;NamedList&lt;Object&gt;&gt; mtasKwicItemResponseItemTokens = new ArrayList&lt;&gt;();</span>
<span class="nc bnc" id="L342" title="All 2 branches missed.">          for (MtasToken token : k.tokens) {</span>
<span class="nc" id="L343">            NamedList&lt;Object&gt; mtasKwicItemResponseItemToken = new SimpleOrderedMap&lt;&gt;();</span>
<span class="nc bnc" id="L344" title="All 2 branches missed.">            if (token.getId() != null) {</span>
<span class="nc" id="L345">              mtasKwicItemResponseItemToken.add(&quot;mtasId&quot;, token.getId());</span>
            }
<span class="nc" id="L347">            mtasKwicItemResponseItemToken.add(&quot;prefix&quot;, token.getPrefix());</span>
<span class="nc" id="L348">            mtasKwicItemResponseItemToken.add(&quot;value&quot;, token.getPostfix());</span>
<span class="nc bnc" id="L349" title="All 2 branches missed.">            if (token.getPositionStart() != null) {</span>
<span class="nc" id="L350">              mtasKwicItemResponseItemToken.add(&quot;positionStart&quot;,</span>
<span class="nc" id="L351">                  token.getPositionStart());</span>
<span class="nc" id="L352">              mtasKwicItemResponseItemToken.add(&quot;positionEnd&quot;,</span>
<span class="nc" id="L353">                  token.getPositionEnd());</span>
            }
<span class="nc bnc" id="L355" title="All 2 branches missed.">            if (token.getPositions() != null) {</span>
<span class="nc" id="L356">              mtasKwicItemResponseItemToken.add(&quot;positions&quot;,</span>
<span class="nc" id="L357">                  token.getPositions());</span>
            }
<span class="nc bnc" id="L359" title="All 2 branches missed.">            if (token.getParentId() != null) {</span>
<span class="nc" id="L360">              mtasKwicItemResponseItemToken.add(&quot;parentMtasId&quot;,</span>
<span class="nc" id="L361">                  token.getParentId());</span>
            }
<span class="nc bnc" id="L363" title="All 2 branches missed.">            if (token.getPayload() != null) {</span>
<span class="nc" id="L364">              mtasKwicItemResponseItemToken.add(&quot;payload&quot;, token.getPayload());</span>
            }
<span class="nc bnc" id="L366" title="All 2 branches missed.">            if (token.getOffsetStart() != null) {</span>
<span class="nc" id="L367">              mtasKwicItemResponseItemToken.add(&quot;offsetStart&quot;,</span>
<span class="nc" id="L368">                  token.getOffsetStart());</span>
<span class="nc" id="L369">              mtasKwicItemResponseItemToken.add(&quot;offsetEnd&quot;,</span>
<span class="nc" id="L370">                  token.getOffsetEnd());</span>
            }
<span class="nc bnc" id="L372" title="All 2 branches missed.">            if (token.getRealOffsetStart() != null) {</span>
<span class="nc" id="L373">              mtasKwicItemResponseItemToken.add(&quot;realOffsetStart&quot;,</span>
<span class="nc" id="L374">                  token.getRealOffsetStart());</span>
<span class="nc" id="L375">              mtasKwicItemResponseItemToken.add(&quot;realOffsetEnd&quot;,</span>
<span class="nc" id="L376">                  token.getRealOffsetEnd());</span>
            }
<span class="nc" id="L378">            mtasKwicItemResponseItemTokens.add(mtasKwicItemResponseItemToken);</span>
<span class="nc" id="L379">          }</span>
<span class="nc" id="L380">          mtasKwicItemResponseItem.add(&quot;tokens&quot;,</span>
              mtasKwicItemResponseItemTokens);
<span class="nc" id="L382">          mtasKwicItemResponseItems.add(mtasKwicItemResponseItem);</span>
<span class="nc" id="L383">        }</span>
<span class="nc" id="L384">        mtasKwicItemResponse.add(&quot;documentKey&quot;, kwic.uniqueKey.get(docId));</span>
<span class="nc" id="L385">        mtasKwicItemResponse.add(&quot;documentTotal&quot;, kwic.subTotal.get(docId));</span>
<span class="nc" id="L386">        mtasKwicItemResponse.add(&quot;documentMinPosition&quot;,</span>
<span class="nc" id="L387">            kwic.minPosition.get(docId));</span>
<span class="nc" id="L388">        mtasKwicItemResponse.add(&quot;documentMaxPosition&quot;,</span>
<span class="nc" id="L389">            kwic.maxPosition.get(docId));</span>
<span class="nc" id="L390">        mtasKwicItemResponse.add(&quot;list&quot;, mtasKwicItemResponseItems);</span>
<span class="nc" id="L391">        mtasKwicItemResponses.add(mtasKwicItemResponse);</span>
<span class="nc" id="L392">      }</span>
    }
<span class="nc" id="L394">    mtasKwicResponse.add(&quot;list&quot;, mtasKwicItemResponses);</span>
<span class="nc" id="L395">    return mtasKwicResponse;</span>
  }

  /* (non-Javadoc)
   * @see mtas.solr.handler.component.util.MtasSolrComponent#modifyRequest(org.apache.solr.handler.component.ResponseBuilder, org.apache.solr.handler.component.SearchComponent, org.apache.solr.handler.component.ShardRequest)
   */
  public void modifyRequest(ResponseBuilder rb, SearchComponent who,
      ShardRequest sreq) {
<span class="nc bnc" id="L403" title="All 2 branches missed.">    if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) {</span>
<span class="nc bnc" id="L404" title="All 4 branches missed.">      if (sreq.params.getBool(PARAM_MTAS_KWIC, false)</span>
          &amp;&amp; (sreq.purpose &amp; ShardRequest.PURPOSE_GET_FIELDS) != 0) {
        // do nothing
      } else {
<span class="nc" id="L408">        Set&lt;String&gt; keys = MtasSolrResultUtil</span>
<span class="nc" id="L409">            .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_KWIC);</span>
<span class="nc" id="L410">        sreq.params.remove(PARAM_MTAS_KWIC);</span>
<span class="nc bnc" id="L411" title="All 2 branches missed.">        for (String key : keys) {</span>
<span class="nc" id="L412">          sreq.params</span>
<span class="nc" id="L413">              .remove(PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_FIELD);</span>
<span class="nc" id="L414">          sreq.params.remove(</span>
              PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_TYPE);
<span class="nc" id="L416">          sreq.params.remove(</span>
              PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_VALUE);
<span class="nc" id="L418">          sreq.params.remove(</span>
              PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_PREFIX);
<span class="nc" id="L420">          sreq.params.remove(</span>
              PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_IGNORE);
<span class="nc" id="L422">          sreq.params.remove(PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot;</span>
              + NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH);
<span class="nc" id="L424">          sreq.params</span>
<span class="nc" id="L425">              .remove(PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_KEY);</span>
<span class="nc" id="L426">          sreq.params.remove(</span>
              PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_PREFIX);
<span class="nc" id="L428">          sreq.params.remove(</span>
              PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_NUMBER);
<span class="nc" id="L430">          sreq.params</span>
<span class="nc" id="L431">              .remove(PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_LEFT);</span>
<span class="nc" id="L432">          sreq.params</span>
<span class="nc" id="L433">              .remove(PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_RIGHT);</span>
<span class="nc" id="L434">          sreq.params.remove(</span>
              PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_OUTPUT);
<span class="nc" id="L436">        }</span>
      }
    }
<span class="nc" id="L439">  }</span>

  /* (non-Javadoc)
   * @see mtas.solr.handler.component.util.MtasSolrComponent#finishStage(org.apache.solr.handler.component.ResponseBuilder)
   */
  public void finishStage(ResponseBuilder rb) {
<span class="nc bnc" id="L445" 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="L448" title="All 2 branches missed.">      for (ShardRequest sreq : rb.finished) {</span>
<span class="nc bnc" id="L449" title="All 2 branches missed.">        if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="nc bnc" id="L450" title="All 2 branches missed.">            &amp;&amp; sreq.params.getBool(PARAM_MTAS_KWIC, false)) {</span>
          // nothing to do
        }
<span class="nc" id="L453">      }</span>
    }
<span class="nc" id="L455">  }</span>

  /* (non-Javadoc)
   * @see mtas.solr.handler.component.util.MtasSolrComponent#distributedProcess(org.apache.solr.handler.component.ResponseBuilder, mtas.codec.util.CodecComponent.ComponentFields)
   */
  public void distributedProcess(ResponseBuilder rb, ComponentFields mtasFields)
      throws IOException {
    // nothing to do
<span class="nc" id="L463">  }</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>