MtasSolrComponentKwic.java.html 35 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
<?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.Arrays;
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="L91">  public MtasSolrComponentKwic(MtasSolrSearchComponent searchComponent) {</span>
<span class="fc" id="L92">  }</span>

  /**
   * Gets the positive integer.
   *
   * @param number the number
   * @return the positive integer
   */
  private int getPositiveInteger(String number) {
    try {
<span class="nc" id="L102">      return Math.max(0, Integer.parseInt(number));</span>
<span class="nc" id="L103">    } catch (NumberFormatException e) {</span>
<span class="nc" id="L104">      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="L118">    Set&lt;String&gt; ids = MtasSolrResultUtil</span>
<span class="nc" id="L119">        .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_KWIC);</span>
<span class="nc bnc" id="L120" title="All 2 branches missed.">    if (!ids.isEmpty()) {</span>
<span class="nc" id="L121">      int tmpCounter = 0;</span>
<span class="nc" id="L122">      String[] fields = new String[ids.size()];</span>
<span class="nc" id="L123">      String[] queryTypes = new String[ids.size()];</span>
<span class="nc" id="L124">      String[] queryValues = new String[ids.size()];</span>
<span class="nc" id="L125">      String[] queryPrefixes = new String[ids.size()];</span>
<span class="nc" id="L126">      String[] queryIgnores = new String[ids.size()];</span>
<span class="nc" id="L127">      String[] queryMaximumIgnoreLengths = new String[ids.size()];</span>
<span class="nc" id="L128">      HashMap&lt;String, String[]&gt;[] queryVariables = new HashMap[ids.size()];</span>
<span class="nc" id="L129">      String[] keys = new String[ids.size()];</span>
<span class="nc" id="L130">      String[] prefixes = new String[ids.size()];</span>
<span class="nc" id="L131">      String[] numbers = new String[ids.size()];</span>
<span class="nc" id="L132">      String[] starts = new String[ids.size()];</span>
<span class="nc" id="L133">      String[] lefts = new String[ids.size()];</span>
<span class="nc" id="L134">      String[] rights = new String[ids.size()];</span>
<span class="nc" id="L135">      String[] outputs = new String[ids.size()];</span>
<span class="nc bnc" id="L136" title="All 2 branches missed.">      for (String id : ids) {</span>
<span class="nc" id="L137">        fields[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L138">            .get(PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_FIELD, null);</span>
<span class="nc" id="L139">        queryTypes[tmpCounter] = rb.req.getParams().get(</span>
<span class="nc" id="L140">            PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_TYPE, null);</span>
<span class="nc" id="L141">        queryValues[tmpCounter] = rb.req.getParams().get(</span>
<span class="nc" id="L142">            PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_VALUE,</span>
<span class="nc" id="L143">            null);</span>
<span class="nc" id="L144">        queryPrefixes[tmpCounter] = rb.req.getParams().get(</span>
<span class="nc" id="L145">            PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_PREFIX,</span>
<span class="nc" id="L146">            null);</span>
<span class="nc" id="L147">        queryIgnores[tmpCounter] = rb.req.getParams().get(</span>
<span class="nc" id="L148">            PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_IGNORE,</span>
<span class="nc" id="L149">            null);</span>
<span class="nc" id="L150">        queryMaximumIgnoreLengths[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L151">            .get(PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot;</span>
<span class="nc" id="L152">                + NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH, null);</span>
<span class="nc" id="L153">        Set&lt;String&gt; vIds = MtasSolrResultUtil.getIdsFromParameters(</span>
<span class="nc" id="L154">            rb.req.getParams(),</span>
<span class="nc" id="L155">            PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_VARIABLE);</span>
<span class="nc" id="L156">        queryVariables[tmpCounter] = new HashMap&lt;&gt;();</span>
<span class="nc bnc" id="L157" title="All 2 branches missed.">        if (!vIds.isEmpty()) {</span>
<span class="nc" id="L158">          HashMap&lt;String, ArrayList&lt;String&gt;&gt; tmpVariables = new HashMap&lt;&gt;();</span>
<span class="nc bnc" id="L159" title="All 2 branches missed.">          for (String vId : vIds) {</span>
<span class="nc" id="L160">            String name = rb.req.getParams().get(</span>
<span class="nc" id="L161">                PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_VARIABLE</span>
<span class="nc" id="L162">                    + &quot;.&quot; + vId + &quot;.&quot; + SUBNAME_MTAS_KWIC_QUERY_VARIABLE_NAME,</span>
<span class="nc" id="L163">                null);</span>
<span class="nc bnc" id="L164" title="All 2 branches missed.">            if (name != null) {</span>
<span class="nc bnc" id="L165" title="All 2 branches missed.">              if (!tmpVariables.containsKey(name)) {</span>
<span class="nc" id="L166">                tmpVariables.put(name, new ArrayList&lt;String&gt;());</span>
              }
<span class="nc" id="L168">              String value = rb.req.getParams()</span>
<span class="nc" id="L169">                  .get(PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot;</span>
<span class="nc" id="L170">                      + NAME_MTAS_KWIC_QUERY_VARIABLE + &quot;.&quot; + vId + &quot;.&quot;</span>
<span class="nc" id="L171">                      + SUBNAME_MTAS_KWIC_QUERY_VARIABLE_VALUE, null);</span>
<span class="nc bnc" id="L172" title="All 2 branches missed.">              if (value != null) {</span>
<span class="nc" id="L173">                ArrayList&lt;String&gt; list = new ArrayList&lt;&gt;();</span>
<span class="nc" id="L174">                String[] subList = value.split(&quot;(?&lt;!\\\\),&quot;);</span>
<span class="nc bnc" id="L175" title="All 2 branches missed.">                for (int i = 0; i &lt; subList.length; i++) {</span>
<span class="nc" id="L176">                  list.add(</span>
<span class="nc" id="L177">                      subList[i].replace(&quot;\\,&quot;, &quot;,&quot;).replace(&quot;\\\\&quot;, &quot;\\&quot;));</span>
                }
<span class="nc" id="L179">                tmpVariables.get(name).addAll(list);</span>
              }
            }
          }
<span class="nc bnc" id="L183" title="All 2 branches missed.">          for (Entry&lt;String, ArrayList&lt;String&gt;&gt; entry : tmpVariables</span>
<span class="nc" id="L184">              .entrySet()) {</span>
<span class="nc" id="L185">            queryVariables[tmpCounter].put(entry.getKey(),</span>
<span class="nc" id="L186">                entry.getValue().toArray(new String[entry.getValue().size()]));</span>
          }
        }
<span class="nc" id="L189">        keys[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L190">            .get(PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_KEY,</span>
<span class="nc" id="L191">                String.valueOf(tmpCounter))</span>
<span class="nc" id="L192">            .trim();</span>
<span class="nc" id="L193">        prefixes[tmpCounter] = rb.req.getParams().get(</span>
<span class="nc" id="L194">            PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_PREFIX, null);</span>
<span class="nc" id="L195">        numbers[tmpCounter] = rb.req.getParams().get(</span>
<span class="nc" id="L196">            PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_NUMBER, 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">        lefts[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L200">            .get(PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_LEFT, null);</span>
<span class="nc" id="L201">        rights[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L202">            .get(PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_RIGHT, null);</span>
<span class="nc" id="L203">        starts[tmpCounter] = rb.req.getParams()</span>
<span class="nc" id="L204">            .get(PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_START, null);</span>
<span class="nc" id="L205">        outputs[tmpCounter] = rb.req.getParams().get(</span>
<span class="nc" id="L206">            PARAM_MTAS_KWIC + &quot;.&quot; + id + &quot;.&quot; + NAME_MTAS_KWIC_OUTPUT, null);</span>
<span class="nc" id="L207">        tmpCounter++;</span>
      }
<span class="nc" id="L209">      String uniqueKeyField = rb.req.getSchema().getUniqueKeyField().getName();</span>
<span class="nc" id="L210">      mtasFields.doKwic = true;</span>
<span class="nc" id="L211">      rb.setNeedDocList(true);</span>
<span class="nc bnc" id="L212" title="All 2 branches missed.">      for (String field : fields) {</span>
<span class="nc bnc" id="L213" title="All 4 branches missed.">        if (field == null || field.isEmpty()) {</span>
<span class="nc" id="L214">          throw new IOException(&quot;no (valid) field in mtas kwic&quot;);</span>
<span class="nc bnc" id="L215" title="All 2 branches missed.">        } else if (!mtasFields.list.containsKey(field)) {</span>
<span class="nc" id="L216">          mtasFields.list.put(field, new ComponentField(uniqueKeyField));</span>
        }
      }
<span class="nc" id="L219">      MtasSolrResultUtil.compareAndCheck(keys, fields, NAME_MTAS_KWIC_KEY,</span>
<span class="nc" id="L220">          NAME_MTAS_KWIC_FIELD, true);</span>
<span class="nc" id="L221">      MtasSolrResultUtil.compareAndCheck(queryValues, fields,</span>
<span class="nc" id="L222">          NAME_MTAS_KWIC_QUERY_VALUE, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L223">      MtasSolrResultUtil.compareAndCheck(queryTypes, fields,</span>
<span class="nc" id="L224">          NAME_MTAS_KWIC_QUERY_TYPE, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L225">      MtasSolrResultUtil.compareAndCheck(queryPrefixes, fields,</span>
<span class="nc" id="L226">          NAME_MTAS_KWIC_QUERY_PREFIX, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L227">      MtasSolrResultUtil.compareAndCheck(queryIgnores, fields,</span>
<span class="nc" id="L228">          NAME_MTAS_KWIC_QUERY_IGNORE, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L229">      MtasSolrResultUtil.compareAndCheck(queryMaximumIgnoreLengths, fields,</span>
<span class="nc" id="L230">          NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH, NAME_MTAS_KWIC_FIELD,</span>
<span class="nc" id="L231">          false);</span>
<span class="nc" id="L232">      MtasSolrResultUtil.compareAndCheck(prefixes, fields,</span>
<span class="nc" id="L233">          NAME_MTAS_KWIC_PREFIX, NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L234">      MtasSolrResultUtil.compareAndCheck(numbers, fields, NAME_MTAS_KWIC_NUMBER,</span>
<span class="nc" id="L235">          NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L236">      MtasSolrResultUtil.compareAndCheck(starts, fields, NAME_MTAS_KWIC_START,</span>
<span class="nc" id="L237">          NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L238">      MtasSolrResultUtil.compareAndCheck(lefts, fields, NAME_MTAS_KWIC_LEFT,</span>
<span class="nc" id="L239">          NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L240">      MtasSolrResultUtil.compareAndCheck(rights, fields, NAME_MTAS_KWIC_RIGHT,</span>
<span class="nc" id="L241">          NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc" id="L242">      MtasSolrResultUtil.compareAndCheck(outputs, fields, NAME_MTAS_KWIC_OUTPUT,</span>
<span class="nc" id="L243">          NAME_MTAS_KWIC_FIELD, false);</span>
<span class="nc bnc" id="L244" title="All 2 branches missed.">      for (int i = 0; i &lt; fields.length; i++) {</span>
<span class="nc" id="L245">        ComponentField cf = mtasFields.list.get(fields[i]);</span>
<span class="nc bnc" id="L246" title="All 2 branches missed.">        Integer maximumIgnoreLength = (queryMaximumIgnoreLengths[i] == null)</span>
<span class="nc" id="L247">            ? null : Integer.parseInt(queryMaximumIgnoreLengths[i]);</span>
<span class="nc" id="L248">        MtasSpanQuery q = MtasSolrResultUtil.constructQuery(queryValues[i],</span>
<span class="nc" id="L249">            queryTypes[i], queryPrefixes[i], queryVariables[i], fields[i],</span>
<span class="nc" id="L250">            queryIgnores[i], maximumIgnoreLength);</span>
        // minimize number of queries
<span class="nc bnc" id="L252" title="All 2 branches missed.">        if (cf.spanQueryList.contains(q)) {</span>
<span class="nc" id="L253">          q = cf.spanQueryList.get(cf.spanQueryList.indexOf(q));</span>
<span class="nc" id="L254">        } else {</span>
<span class="nc" id="L255">          cf.spanQueryList.add(q);</span>
        }
<span class="nc bnc" id="L257" title="All 4 branches missed.">        String key = (keys[i] == null) || (keys[i].isEmpty())</span>
<span class="nc" id="L258">            ? String.valueOf(i) + &quot;:&quot; + fields[i] + &quot;:&quot; + queryValues[i]</span>
<span class="nc" id="L259">            : keys[i].trim();</span>
<span class="nc" id="L260">        String prefix = prefixes[i];</span>
<span class="nc bnc" id="L261" title="All 2 branches missed.">        Integer number = (numbers[i] != null) ? getPositiveInteger(numbers[i])</span>
<span class="nc" id="L262">            : null;</span>
<span class="nc" id="L263">        int start = getPositiveInteger(starts[i]);</span>
<span class="nc" id="L264">        int left = getPositiveInteger(lefts[i]);</span>
<span class="nc" id="L265">        int right = getPositiveInteger(rights[i]);</span>
<span class="nc" id="L266">        String output = outputs[i];</span>
<span class="nc" id="L267">        mtasFields.list.get(fields[i]).kwicList.add(new ComponentKwic(q, key,</span>
<span class="nc" id="L268">            prefix, number, start, left, right, output));</span>
      }
    }
<span class="nc" id="L271">  }</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="L281">    SimpleOrderedMap&lt;Object&gt; mtasKwicResponse = new SimpleOrderedMap&lt;&gt;();</span>
<span class="nc" id="L282">    mtasKwicResponse.add(&quot;key&quot;, kwic.key);</span>
<span class="nc" id="L283">    ArrayList&lt;NamedList&lt;Object&gt;&gt; mtasKwicItemResponses = new ArrayList&lt;&gt;();</span>
<span class="nc bnc" id="L284" title="All 2 branches missed.">    if (kwic.output.equals(ComponentKwic.KWIC_OUTPUT_HIT)) {</span>
<span class="nc bnc" id="L285" title="All 2 branches missed.">      for (int docId : kwic.hits.keySet()) {</span>
<span class="nc" id="L286">        NamedList&lt;Object&gt; mtasKwicItemResponse = new SimpleOrderedMap&lt;&gt;();</span>
<span class="nc" id="L287">        List&lt;KwicHit&gt; list = kwic.hits.get(docId);</span>
<span class="nc" id="L288">        List&lt;NamedList&lt;Object&gt;&gt; mtasKwicItemResponseItems = new ArrayList&lt;&gt;();</span>
<span class="nc bnc" id="L289" title="All 2 branches missed.">        for (KwicHit h : list) {</span>
<span class="nc" id="L290">          NamedList&lt;Object&gt; mtasKwicItemResponseItem = new SimpleOrderedMap&lt;&gt;();</span>
<span class="nc" id="L291">          SortedMap&lt;Integer, List&lt;List&lt;String&gt;&gt;&gt; hitData = new TreeMap&lt;&gt;();</span>
<span class="nc" id="L292">          SortedMap&lt;Integer, List&lt;List&lt;String&gt;&gt;&gt; leftData = null;</span>
<span class="nc" id="L293">          SortedMap&lt;Integer, List&lt;List&lt;String&gt;&gt;&gt; rightData = null;</span>
<span class="nc bnc" id="L294" title="All 2 branches missed.">          if (kwic.left &gt; 0) {</span>
<span class="nc" id="L295">            leftData = new TreeMap&lt;&gt;();</span>
          }
<span class="nc bnc" id="L297" title="All 2 branches missed.">          if (kwic.right &gt; 0) {</span>
<span class="nc" id="L298">            rightData = new TreeMap&lt;&gt;();</span>
          }
<span class="nc bnc" id="L300" title="All 2 branches missed.">          for (int position = Math.max(0,</span>
<span class="nc" id="L301">              h.startPosition - kwic.left); position &lt;= (h.endPosition</span>
<span class="nc" id="L302">                  + kwic.right); position++) {</span>
<span class="nc bnc" id="L303" title="All 2 branches missed.">            if (h.hits.containsKey(position)) {</span>
<span class="nc" id="L304">              List&lt;List&lt;String&gt;&gt; hitDataItem = new ArrayList&lt;&gt;();</span>
<span class="nc bnc" id="L305" title="All 2 branches missed.">              for (String term : h.hits.get(position)) {</span>
<span class="nc" id="L306">                List&lt;String&gt; hitDataSubItem = new ArrayList&lt;&gt;();</span>
<span class="nc" id="L307">                hitDataSubItem.add(CodecUtil.termPrefix(term));</span>
<span class="nc" id="L308">                hitDataSubItem.add(CodecUtil.termValue(term));</span>
<span class="nc" id="L309">                hitDataItem.add(hitDataSubItem);</span>
              }
<span class="nc bnc" id="L311" title="All 2 branches missed.">              if (position &lt; h.startPosition) {</span>
<span class="nc bnc" id="L312" title="All 2 branches missed.">                if (leftData != null) {</span>
<span class="nc" id="L313">                  leftData.put(position, hitDataItem);</span>
                }
<span class="nc bnc" id="L315" title="All 2 branches missed.">              } else if (position &gt; h.endPosition) {</span>
<span class="nc bnc" id="L316" title="All 2 branches missed.">                if (rightData != null) {</span>
<span class="nc" id="L317">                  rightData.put(position, hitDataItem);</span>
                }
<span class="nc" id="L319">              } else {</span>
<span class="nc" id="L320">                hitData.put(position, hitDataItem);</span>
              }
            }
          }
<span class="nc bnc" id="L324" title="All 2 branches missed.">          if (kwic.left &gt; 0) {</span>
<span class="nc" id="L325">            mtasKwicItemResponseItem.add(&quot;left&quot;, leftData);</span>
          }
<span class="nc" id="L327">          mtasKwicItemResponseItem.add(&quot;hit&quot;, hitData);</span>
<span class="nc bnc" id="L328" title="All 2 branches missed.">          if (kwic.right &gt; 0) {</span>
<span class="nc" id="L329">            mtasKwicItemResponseItem.add(&quot;right&quot;, rightData);</span>
          }
<span class="nc" id="L331">          mtasKwicItemResponseItems.add(mtasKwicItemResponseItem);</span>
        }
<span class="nc" id="L333">        mtasKwicItemResponse.add(&quot;documentKey&quot;, kwic.uniqueKey.get(docId));</span>
<span class="nc" id="L334">        mtasKwicItemResponse.add(&quot;documentTotal&quot;, kwic.subTotal.get(docId));</span>
<span class="nc" id="L335">        mtasKwicItemResponse.add(&quot;documentMinPosition&quot;,</span>
<span class="nc" id="L336">            kwic.minPosition.get(docId));</span>
<span class="nc" id="L337">        mtasKwicItemResponse.add(&quot;documentMaxPosition&quot;,</span>
<span class="nc" id="L338">            kwic.maxPosition.get(docId));</span>
<span class="nc" id="L339">        mtasKwicItemResponse.add(&quot;list&quot;, mtasKwicItemResponseItems);</span>
<span class="nc" id="L340">        mtasKwicItemResponses.add(mtasKwicItemResponse);</span>
      }
<span class="nc bnc" id="L342" title="All 2 branches missed.">    } else if (kwic.output.equals(ComponentKwic.KWIC_OUTPUT_TOKEN)) {</span>
<span class="nc bnc" id="L343" title="All 2 branches missed.">      for (int docId : kwic.tokens.keySet()) {</span>
<span class="nc" id="L344">        NamedList&lt;Object&gt; mtasKwicItemResponse = new SimpleOrderedMap&lt;&gt;();</span>
<span class="nc" id="L345">        List&lt;KwicToken&gt; list = kwic.tokens.get(docId);</span>
<span class="nc" id="L346">        List&lt;NamedList&lt;Object&gt;&gt; mtasKwicItemResponseItems = new ArrayList&lt;&gt;();</span>
<span class="nc bnc" id="L347" title="All 2 branches missed.">        for (KwicToken k : list) {</span>
<span class="nc" id="L348">          NamedList&lt;Object&gt; mtasKwicItemResponseItem = new SimpleOrderedMap&lt;&gt;();</span>
<span class="nc" id="L349">          mtasKwicItemResponseItem.add(&quot;startPosition&quot;, k.startPosition);</span>
<span class="nc" id="L350">          mtasKwicItemResponseItem.add(&quot;endPosition&quot;, k.endPosition);</span>
<span class="nc" id="L351">          ArrayList&lt;NamedList&lt;Object&gt;&gt; mtasKwicItemResponseItemTokens = new ArrayList&lt;&gt;();</span>
<span class="nc bnc" id="L352" title="All 2 branches missed.">          for (MtasToken token : k.tokens) {</span>
<span class="nc" id="L353">            NamedList&lt;Object&gt; mtasKwicItemResponseItemToken = new SimpleOrderedMap&lt;&gt;();</span>
<span class="nc bnc" id="L354" title="All 2 branches missed.">            if (token.getId() != null) {</span>
<span class="nc" id="L355">              mtasKwicItemResponseItemToken.add(&quot;mtasId&quot;, token.getId());</span>
            }
<span class="nc" id="L357">            mtasKwicItemResponseItemToken.add(&quot;prefix&quot;, token.getPrefix());</span>
<span class="nc" id="L358">            mtasKwicItemResponseItemToken.add(&quot;value&quot;, token.getPostfix());</span>
<span class="nc bnc" id="L359" title="All 2 branches missed.">            if (token.getPositionStart() != null) {</span>
<span class="nc" id="L360">              mtasKwicItemResponseItemToken.add(&quot;positionStart&quot;,</span>
<span class="nc" id="L361">                  token.getPositionStart());</span>
<span class="nc" id="L362">              mtasKwicItemResponseItemToken.add(&quot;positionEnd&quot;,</span>
<span class="nc" id="L363">                  token.getPositionEnd());</span>
            }
<span class="nc bnc" id="L365" title="All 2 branches missed.">            if (token.getPositions() != null) {</span>
<span class="nc" id="L366">              mtasKwicItemResponseItemToken.add(&quot;positions&quot;,</span>
<span class="nc" id="L367">                  Arrays.toString(token.getPositions()));</span>
            }
<span class="nc bnc" id="L369" title="All 2 branches missed.">            if (token.getParentId() != null) {</span>
<span class="nc" id="L370">              mtasKwicItemResponseItemToken.add(&quot;parentMtasId&quot;,</span>
<span class="nc" id="L371">                  token.getParentId());</span>
            }
<span class="nc bnc" id="L373" title="All 2 branches missed.">            if (token.getPayload() != null) {</span>
<span class="nc" id="L374">              mtasKwicItemResponseItemToken.add(&quot;payload&quot;, token.getPayload());</span>
            }
<span class="nc bnc" id="L376" title="All 2 branches missed.">            if (token.getOffsetStart() != null) {</span>
<span class="nc" id="L377">              mtasKwicItemResponseItemToken.add(&quot;offsetStart&quot;,</span>
<span class="nc" id="L378">                  token.getOffsetStart());</span>
<span class="nc" id="L379">              mtasKwicItemResponseItemToken.add(&quot;offsetEnd&quot;,</span>
<span class="nc" id="L380">                  token.getOffsetEnd());</span>
            }
<span class="nc bnc" id="L382" title="All 2 branches missed.">            if (token.getRealOffsetStart() != null) {</span>
<span class="nc" id="L383">              mtasKwicItemResponseItemToken.add(&quot;realOffsetStart&quot;,</span>
<span class="nc" id="L384">                  token.getRealOffsetStart());</span>
<span class="nc" id="L385">              mtasKwicItemResponseItemToken.add(&quot;realOffsetEnd&quot;,</span>
<span class="nc" id="L386">                  token.getRealOffsetEnd());</span>
            }
<span class="nc" id="L388">            mtasKwicItemResponseItemTokens.add(mtasKwicItemResponseItemToken);</span>
          }
<span class="nc" id="L390">          mtasKwicItemResponseItem.add(&quot;tokens&quot;,</span>
<span class="nc" id="L391">              mtasKwicItemResponseItemTokens);</span>
<span class="nc" id="L392">          mtasKwicItemResponseItems.add(mtasKwicItemResponseItem);</span>
        }
<span class="nc" id="L394">        mtasKwicItemResponse.add(&quot;documentKey&quot;, kwic.uniqueKey.get(docId));</span>
<span class="nc" id="L395">        mtasKwicItemResponse.add(&quot;documentTotal&quot;, kwic.subTotal.get(docId));</span>
<span class="nc" id="L396">        mtasKwicItemResponse.add(&quot;documentMinPosition&quot;,</span>
<span class="nc" id="L397">            kwic.minPosition.get(docId));</span>
<span class="nc" id="L398">        mtasKwicItemResponse.add(&quot;documentMaxPosition&quot;,</span>
<span class="nc" id="L399">            kwic.maxPosition.get(docId));</span>
<span class="nc" id="L400">        mtasKwicItemResponse.add(&quot;list&quot;, mtasKwicItemResponseItems);</span>
<span class="nc" id="L401">        mtasKwicItemResponses.add(mtasKwicItemResponse);</span>
      }
    }
<span class="nc" id="L404">    mtasKwicResponse.add(&quot;list&quot;, mtasKwicItemResponses);</span>
<span class="nc" id="L405">    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="L419" title="All 2 branches missed.">    if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) {</span>
<span class="nc bnc" id="L420" title="All 2 branches missed.">      if (sreq.params.getBool(PARAM_MTAS_KWIC, false)</span>
<span class="nc bnc" id="L421" title="All 2 branches missed.">          &amp;&amp; (sreq.purpose &amp; ShardRequest.PURPOSE_GET_FIELDS) != 0) {</span>
        // do nothing
      } else {
<span class="nc" id="L424">        Set&lt;String&gt; keys = MtasSolrResultUtil</span>
<span class="nc" id="L425">            .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_KWIC);</span>
<span class="nc" id="L426">        sreq.params.remove(PARAM_MTAS_KWIC);</span>
<span class="nc bnc" id="L427" title="All 2 branches missed.">        for (String key : keys) {</span>
<span class="nc" id="L428">          sreq.params</span>
<span class="nc" id="L429">              .remove(PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_FIELD);</span>
<span class="nc" id="L430">          sreq.params.remove(</span>
<span class="nc" id="L431">              PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_TYPE);</span>
<span class="nc" id="L432">          sreq.params.remove(</span>
<span class="nc" id="L433">              PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_VALUE);</span>
<span class="nc" id="L434">          sreq.params.remove(</span>
<span class="nc" id="L435">              PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_PREFIX);</span>
<span class="nc" id="L436">          sreq.params.remove(</span>
<span class="nc" id="L437">              PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_QUERY_IGNORE);</span>
<span class="nc" id="L438">          sreq.params.remove(PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot;</span>
<span class="nc" id="L439">              + NAME_MTAS_KWIC_QUERY_MAXIMUM_IGNORE_LENGTH);</span>
<span class="nc" id="L440">          sreq.params</span>
<span class="nc" id="L441">              .remove(PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_KEY);</span>
<span class="nc" id="L442">          sreq.params.remove(</span>
<span class="nc" id="L443">              PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_PREFIX);</span>
<span class="nc" id="L444">          sreq.params.remove(</span>
<span class="nc" id="L445">              PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_NUMBER);</span>
<span class="nc" id="L446">          sreq.params</span>
<span class="nc" id="L447">              .remove(PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_LEFT);</span>
<span class="nc" id="L448">          sreq.params</span>
<span class="nc" id="L449">              .remove(PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_RIGHT);</span>
<span class="nc" id="L450">          sreq.params.remove(</span>
<span class="nc" id="L451">              PARAM_MTAS_KWIC + &quot;.&quot; + key + &quot;.&quot; + NAME_MTAS_KWIC_OUTPUT);</span>
        }
      }
    }
<span class="nc" id="L455">  }</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="L465" title="All 2 branches missed.">    if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="nc bnc" id="L466" title="All 2 branches missed.">        &amp;&amp; rb.stage &gt;= ResponseBuilder.STAGE_EXECUTE_QUERY</span>
<span class="nc bnc" id="L467" title="All 2 branches missed.">        &amp;&amp; rb.stage &lt; ResponseBuilder.STAGE_GET_FIELDS) {</span>
<span class="nc bnc" id="L468" title="All 2 branches missed.">      for (ShardRequest sreq : rb.finished) {</span>
<span class="nc bnc" id="L469" title="All 2 branches missed.">        if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="nc" id="L470">            &amp;&amp; sreq.params.getBool(PARAM_MTAS_KWIC, false)) {</span>
          // nothing to do
        }
      }
    }
<span class="nc" id="L475">  }</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="L488">  }</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>