<?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> > <a href="index.source.html" class="el_package">mtas.solr.handler.component.util</a> > <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<ComponentStats> {
/** The Constant log. */
<span class="fc" id="L40"> private static final Log log = LogFactory</span>
<span class="fc" id="L41"> .getLog(MtasSolrComponentStats.class);</span>
/** The search component. */
MtasSolrSearchComponent searchComponent;
/** The Constant PARAM_MTAS_STATS. */
public static final String PARAM_MTAS_STATS = MtasSolrSearchComponent.PARAM_MTAS
+ ".stats";
/** The Constant PARAM_MTAS_STATS_POSITIONS. */
public static final String PARAM_MTAS_STATS_POSITIONS = PARAM_MTAS_STATS
+ ".positions";
/** The Constant NAME_MTAS_STATS_POSITIONS_FIELD. */
public static final String NAME_MTAS_STATS_POSITIONS_FIELD = "field";
/** The Constant NAME_MTAS_STATS_POSITIONS_KEY. */
public static final String NAME_MTAS_STATS_POSITIONS_KEY = "key";
/** The Constant NAME_MTAS_STATS_POSITIONS_TYPE. */
public static final String NAME_MTAS_STATS_POSITIONS_TYPE = "type";
/** The Constant NAME_MTAS_STATS_POSITIONS_MINIMUM. */
public static final String NAME_MTAS_STATS_POSITIONS_MINIMUM = "minimum";
/** The Constant NAME_MTAS_STATS_POSITIONS_MAXIMUM. */
public static final String NAME_MTAS_STATS_POSITIONS_MAXIMUM = "maximum";
/** The Constant PARAM_MTAS_STATS_TOKENS. */
public static final String PARAM_MTAS_STATS_TOKENS = PARAM_MTAS_STATS
+ ".tokens";
/** The Constant NAME_MTAS_STATS_TOKENS_FIELD. */
public static final String NAME_MTAS_STATS_TOKENS_FIELD = "field";
/** The Constant NAME_MTAS_STATS_TOKENS_KEY. */
public static final String NAME_MTAS_STATS_TOKENS_KEY = "key";
/** The Constant NAME_MTAS_STATS_TOKENS_TYPE. */
public static final String NAME_MTAS_STATS_TOKENS_TYPE = "type";
/** The Constant NAME_MTAS_STATS_TOKENS_MINIMUM. */
public static final String NAME_MTAS_STATS_TOKENS_MINIMUM = "minimum";
/** The Constant NAME_MTAS_STATS_TOKENS_MAXIMUM. */
public static final String NAME_MTAS_STATS_TOKENS_MAXIMUM = "maximum";
/** The Constant PARAM_MTAS_STATS_SPANS. */
public static final String PARAM_MTAS_STATS_SPANS = PARAM_MTAS_STATS
+ ".spans";
/** The Constant NAME_MTAS_STATS_SPANS_FIELD. */
public static final String NAME_MTAS_STATS_SPANS_FIELD = "field";
/** The Constant NAME_MTAS_STATS_SPANS_QUERY. */
public static final String NAME_MTAS_STATS_SPANS_QUERY = "query";
/** The Constant NAME_MTAS_STATS_SPANS_EXPAND. */
public static final String NAME_MTAS_STATS_SPANS_EXPAND = "expand";
/** The Constant NAME_MTAS_STATS_SPANS_KEY. */
public static final String NAME_MTAS_STATS_SPANS_KEY = "key";
/** The Constant NAME_MTAS_STATS_SPANS_TYPE. */
public static final String NAME_MTAS_STATS_SPANS_TYPE = "type";
/** The Constant NAME_MTAS_STATS_SPANS_MINIMUM. */
public static final String NAME_MTAS_STATS_SPANS_MINIMUM = "minimum";
/** The Constant NAME_MTAS_STATS_SPANS_MAXIMUM. */
public static final String NAME_MTAS_STATS_SPANS_MAXIMUM = "maximum";
/** The Constant NAME_MTAS_STATS_SPANS_FUNCTION. */
public static final String NAME_MTAS_STATS_SPANS_FUNCTION = "function";
/** The Constant SUBNAME_MTAS_STATS_SPANS_FUNCTION_EXPRESSION. */
public static final String SUBNAME_MTAS_STATS_SPANS_FUNCTION_EXPRESSION = "expression";
/** The Constant SUBNAME_MTAS_STATS_SPANS_FUNCTION_KEY. */
public static final String SUBNAME_MTAS_STATS_SPANS_FUNCTION_KEY = "key";
/** The Constant SUBNAME_MTAS_STATS_SPANS_FUNCTION_TYPE. */
public static final String SUBNAME_MTAS_STATS_SPANS_FUNCTION_TYPE = "type";
/** The Constant SUBNAME_MTAS_STATS_SPANS_QUERY_TYPE. */
public static final String SUBNAME_MTAS_STATS_SPANS_QUERY_TYPE = "type";
/** The Constant SUBNAME_MTAS_STATS_SPANS_QUERY_VALUE. */
public static final String SUBNAME_MTAS_STATS_SPANS_QUERY_VALUE = "value";
/** The Constant SUBNAME_MTAS_STATS_SPANS_QUERY_IGNORE. */
public static final String SUBNAME_MTAS_STATS_SPANS_QUERY_IGNORE = "ignore";
/** The Constant SUBNAME_MTAS_STATS_SPANS_QUERY_MAXIMUM_IGNORE_LENGTH. */
public static final String SUBNAME_MTAS_STATS_SPANS_QUERY_MAXIMUM_IGNORE_LENGTH = "maximumIgnoreLength";
/** The Constant SUBNAME_MTAS_STATS_SPANS_QUERY_PREFIX. */
public static final String SUBNAME_MTAS_STATS_SPANS_QUERY_PREFIX = "prefix";
/** The Constant SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE. */
public static final String SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE = "variable";
/** The Constant SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE_NAME. */
public static final String SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE_NAME = "name";
/** The Constant SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE_VALUE. */
public static final String SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE_VALUE = "value";
/**
* Instantiates a new mtas solr component stats.
*
* @param searchComponent the search component
*/
<span class="fc" id="L154"> public MtasSolrComponentStats(MtasSolrSearchComponent searchComponent) {</span>
<span class="fc" id="L155"> this.searchComponent = searchComponent;</span>
<span class="fc" id="L156"> }</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="L168" title="All 2 branches covered."> if (rb.req.getParams().getBool(PARAM_MTAS_STATS_POSITIONS, false)) {</span>
<span class="fc" id="L169"> preparePositions(rb, mtasFields);</span>
}
<span class="fc bfc" id="L171" title="All 2 branches covered."> if (rb.req.getParams().getBool(PARAM_MTAS_STATS_TOKENS, false)) {</span>
<span class="fc" id="L172"> prepareTokens(rb, mtasFields);</span>
}
<span class="fc bfc" id="L174" title="All 2 branches covered."> if (rb.req.getParams().getBool(PARAM_MTAS_STATS_SPANS, false)) {</span>
<span class="fc" id="L175"> prepareSpans(rb, mtasFields);</span>
}
<span class="fc" id="L177"> }</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="L188"> Set<String> ids = MtasSolrResultUtil</span>
<span class="fc" id="L189"> .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_STATS_POSITIONS);</span>
<span class="pc bpc" id="L190" title="1 of 2 branches missed."> if (!ids.isEmpty()) {</span>
<span class="fc" id="L191"> int tmpCounter = 0;</span>
<span class="fc" id="L192"> String[] fields = new String[ids.size()];</span>
<span class="fc" id="L193"> String[] keys = new String[ids.size()];</span>
<span class="fc" id="L194"> String[] minima = new String[ids.size()];</span>
<span class="fc" id="L195"> String[] maxima = new String[ids.size()];</span>
<span class="fc" id="L196"> String[] types = new String[ids.size()];</span>
<span class="fc bfc" id="L197" title="All 2 branches covered."> for (String id : ids) {</span>
<span class="fc" id="L198"> fields[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_POSITIONS</span>
+ "." + id + "." + NAME_MTAS_STATS_POSITIONS_FIELD, null);
<span class="fc" id="L200"> keys[tmpCounter] = rb.req.getParams()</span>
<span class="fc" id="L201"> .get(PARAM_MTAS_STATS_POSITIONS + "." + id + "."</span>
<span class="fc" id="L202"> + NAME_MTAS_STATS_POSITIONS_KEY, String.valueOf(tmpCounter))</span>
<span class="fc" id="L203"> .trim();</span>
<span class="fc" id="L204"> minima[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_POSITIONS</span>
+ "." + id + "." + NAME_MTAS_STATS_POSITIONS_MINIMUM, null);
<span class="fc" id="L206"> maxima[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_POSITIONS</span>
+ "." + id + "." + NAME_MTAS_STATS_POSITIONS_MAXIMUM, null);
<span class="fc" id="L208"> types[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_POSITIONS</span>
+ "." + id + "." + NAME_MTAS_STATS_POSITIONS_TYPE, null);
<span class="fc" id="L210"> tmpCounter++;</span>
<span class="fc" id="L211"> }</span>
<span class="fc" id="L212"> String uniqueKeyField = rb.req.getSchema().getUniqueKeyField().getName();</span>
<span class="fc" id="L213"> mtasFields.doStats = true;</span>
<span class="fc" id="L214"> mtasFields.doStatsPositions = true;</span>
<span class="fc" id="L215"> rb.setNeedDocSet(true);</span>
<span class="fc bfc" id="L216" title="All 2 branches covered."> for (String field : fields) {</span>
<span class="pc bpc" id="L217" title="2 of 4 branches missed."> if (field == null || field.isEmpty()) {</span>
<span class="nc" id="L218"> throw new IOException("no (valid) field in mtas stats positions");</span>
<span class="pc bpc" id="L219" title="1 of 2 branches missed."> } else if (!mtasFields.list.containsKey(field)) {</span>
<span class="fc" id="L220"> mtasFields.list.put(field, new ComponentField(uniqueKeyField));</span>
}
}
<span class="fc" id="L223"> MtasSolrResultUtil.compareAndCheck(keys, fields,</span>
<span class="fc" id="L224"> NAME_MTAS_STATS_POSITIONS_KEY, NAME_MTAS_STATS_POSITIONS_FIELD, true);</span>
<span class="fc" id="L225"> MtasSolrResultUtil.compareAndCheck(minima, fields,</span>
NAME_MTAS_STATS_POSITIONS_MINIMUM, NAME_MTAS_STATS_POSITIONS_FIELD,
<span class="fc" id="L227"> false);</span>
<span class="fc" id="L228"> MtasSolrResultUtil.compareAndCheck(maxima, fields,</span>
NAME_MTAS_STATS_POSITIONS_MAXIMUM, NAME_MTAS_STATS_POSITIONS_FIELD,
<span class="fc" id="L230"> false);</span>
<span class="fc" id="L231"> MtasSolrResultUtil.compareAndCheck(types, fields,</span>
NAME_MTAS_STATS_POSITIONS_TYPE, NAME_MTAS_STATS_POSITIONS_FIELD,
<span class="fc" id="L233"> false);</span>
<span class="fc bfc" id="L234" title="All 2 branches covered."> for (int i = 0; i < fields.length; i++) {</span>
<span class="fc" id="L235"> String field = fields[i];</span>
<span class="fc" id="L236"> String key = keys[i];</span>
<span class="pc bpc" id="L237" title="2 of 4 branches missed."> String type = (types[i] == null) || (types[i].isEmpty()) ? null</span>
<span class="fc" id="L238"> : types[i].trim();</span>
<span class="pc bpc" id="L239" title="3 of 4 branches missed."> Double minimum = (minima[i] == null) || (minima[i].isEmpty()) ? null</span>
<span class="pc" id="L240"> : Double.parseDouble(minima[i]);</span>
<span class="pc bpc" id="L241" title="3 of 4 branches missed."> Double maximum = (maxima[i] == null) || (maxima[i].isEmpty()) ? null</span>
<span class="pc" id="L242"> : Double.parseDouble(maxima[i]);</span>
try {
<span class="fc" id="L244"> mtasFields.list.get(field).statsPositionList</span>
<span class="fc" id="L245"> .add(new ComponentPosition(key, minimum, maximum, type));</span>
<span class="nc" id="L246"> } catch (ParseException e) {</span>
<span class="nc" id="L247"> throw new IOException(e.getMessage());</span>
<span class="fc" id="L248"> }</span>
}
}
<span class="fc" id="L251"> }</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="L262"> Set<String> ids = MtasSolrResultUtil</span>
<span class="fc" id="L263"> .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_STATS_TOKENS);</span>
<span class="pc bpc" id="L264" title="1 of 2 branches missed."> if (!ids.isEmpty()) {</span>
<span class="fc" id="L265"> int tmpCounter = 0;</span>
<span class="fc" id="L266"> String[] fields = new String[ids.size()];</span>
<span class="fc" id="L267"> String[] keys = new String[ids.size()];</span>
<span class="fc" id="L268"> String[] minima = new String[ids.size()];</span>
<span class="fc" id="L269"> String[] maxima = new String[ids.size()];</span>
<span class="fc" id="L270"> String[] types = new String[ids.size()];</span>
<span class="fc bfc" id="L271" title="All 2 branches covered."> for (String id : ids) {</span>
<span class="fc" id="L272"> fields[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_TOKENS</span>
+ "." + id + "." + NAME_MTAS_STATS_TOKENS_FIELD, null);
<span class="fc" id="L274"> keys[tmpCounter] = rb.req.getParams()</span>
<span class="fc" id="L275"> .get(PARAM_MTAS_STATS_TOKENS + "." + id + "."</span>
<span class="fc" id="L276"> + NAME_MTAS_STATS_TOKENS_KEY, String.valueOf(tmpCounter))</span>
<span class="fc" id="L277"> .trim();</span>
<span class="fc" id="L278"> minima[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_TOKENS</span>
+ "." + id + "." + NAME_MTAS_STATS_TOKENS_MINIMUM, null);
<span class="fc" id="L280"> maxima[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_TOKENS</span>
+ "." + id + "." + NAME_MTAS_STATS_TOKENS_MAXIMUM, null);
<span class="fc" id="L282"> types[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_TOKENS + "."</span>
+ id + "." + NAME_MTAS_STATS_TOKENS_TYPE, null);
<span class="fc" id="L284"> tmpCounter++;</span>
<span class="fc" id="L285"> }</span>
<span class="fc" id="L286"> String uniqueKeyField = rb.req.getSchema().getUniqueKeyField().getName();</span>
<span class="fc" id="L287"> mtasFields.doStats = true;</span>
<span class="fc" id="L288"> mtasFields.doStatsTokens = true;</span>
<span class="fc" id="L289"> rb.setNeedDocSet(true);</span>
<span class="fc bfc" id="L290" title="All 2 branches covered."> for (String field : fields) {</span>
<span class="pc bpc" id="L291" title="2 of 4 branches missed."> if (field == null || field.isEmpty()) {</span>
<span class="nc" id="L292"> throw new IOException("no (valid) field in mtas stats tokens");</span>
<span class="fc bfc" id="L293" title="All 2 branches covered."> } else if (!mtasFields.list.containsKey(field)) {</span>
<span class="fc" id="L294"> mtasFields.list.put(field, new ComponentField(uniqueKeyField));</span>
}
}
<span class="fc" id="L297"> MtasSolrResultUtil.compareAndCheck(keys, fields,</span>
<span class="fc" id="L298"> NAME_MTAS_STATS_TOKENS_KEY, NAME_MTAS_STATS_TOKENS_FIELD, true);</span>
<span class="fc" id="L299"> MtasSolrResultUtil.compareAndCheck(minima, fields,</span>
<span class="fc" id="L300"> NAME_MTAS_STATS_TOKENS_MINIMUM, NAME_MTAS_STATS_TOKENS_FIELD, false);</span>
<span class="fc" id="L301"> MtasSolrResultUtil.compareAndCheck(maxima, fields,</span>
<span class="fc" id="L302"> NAME_MTAS_STATS_TOKENS_MAXIMUM, NAME_MTAS_STATS_TOKENS_FIELD, false);</span>
<span class="fc" id="L303"> MtasSolrResultUtil.compareAndCheck(types, fields,</span>
<span class="fc" id="L304"> NAME_MTAS_STATS_TOKENS_TYPE, NAME_MTAS_STATS_TOKENS_FIELD, false);</span>
<span class="fc bfc" id="L305" title="All 2 branches covered."> for (int i = 0; i < fields.length; i++) {</span>
<span class="fc" id="L306"> String field = fields[i];</span>
<span class="fc" id="L307"> String key = keys[i];</span>
<span class="pc bpc" id="L308" title="2 of 4 branches missed."> String type = (types[i] == null) || (types[i].isEmpty()) ? null</span>
<span class="fc" id="L309"> : types[i].trim();</span>
<span class="pc bpc" id="L310" title="1 of 4 branches missed."> Double minimum = (minima[i] == null) || (minima[i].isEmpty()) ? null</span>
<span class="fc" id="L311"> : Double.parseDouble(minima[i]);</span>
<span class="pc bpc" id="L312" title="1 of 4 branches missed."> Double maximum = (maxima[i] == null) || (maxima[i].isEmpty()) ? null</span>
<span class="fc" id="L313"> : Double.parseDouble(maxima[i]);</span>
try {
<span class="fc" id="L315"> mtasFields.list.get(field).statsTokenList</span>
<span class="fc" id="L316"> .add(new ComponentToken(key, minimum, maximum, type));</span>
<span class="nc" id="L317"> } catch (ParseException e) {</span>
<span class="nc" id="L318"> throw new IOException(e.getMessage());</span>
<span class="fc" id="L319"> }</span>
}
}
<span class="fc" id="L322"> }</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="L333"> SortedSet<String> ids = MtasSolrResultUtil</span>
<span class="fc" id="L334"> .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_STATS_SPANS);</span>
<span class="pc bpc" id="L335" title="1 of 2 branches missed."> if (!ids.isEmpty()) {</span>
<span class="fc" id="L336"> int tmpCounter = 0;</span>
<span class="fc" id="L337"> String[] fields = new String[ids.size()];</span>
<span class="fc" id="L338"> String[] keys = new String[ids.size()];</span>
<span class="fc" id="L339"> String[] minima = new String[ids.size()];</span>
<span class="fc" id="L340"> String[] maxima = new String[ids.size()];</span>
<span class="fc" id="L341"> String[] types = new String[ids.size()];</span>
<span class="fc" id="L342"> String[][] functionExpressions = new String[ids.size()][];</span>
<span class="fc" id="L343"> String[][] functionKeys = new String[ids.size()][];</span>
<span class="fc" id="L344"> String[][] functionTypes = new String[ids.size()][];</span>
<span class="fc" id="L345"> String[][] queryTypes = new String[ids.size()][];</span>
<span class="fc" id="L346"> String[][] queryValues = new String[ids.size()][];</span>
<span class="fc" id="L347"> String[][] queryIgnores = new String[ids.size()][];</span>
<span class="fc" id="L348"> String[][] queryMaximumIgnoreLengths = new String[ids.size()][];</span>
<span class="fc" id="L349"> String[][] queryPrefixes = new String[ids.size()][];</span>
<span class="fc" id="L350"> HashMap<String, String[]>[][] queryVariables = new HashMap[ids.size()][];</span>
<span class="fc" id="L351"> Boolean[] expand = new Boolean[ids.size()];</span>
<span class="fc bfc" id="L352" title="All 2 branches covered."> for (String id : ids) {</span>
<span class="fc" id="L353"> fields[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_SPANS + "."</span>
+ id + "." + NAME_MTAS_STATS_SPANS_FIELD, null);
<span class="fc" id="L355"> keys[tmpCounter] = rb.req.getParams().get(</span>
PARAM_MTAS_STATS_SPANS + "." + id + "." + NAME_MTAS_STATS_SPANS_KEY,
<span class="fc" id="L357"> String.valueOf(tmpCounter)).trim();</span>
<span class="fc" id="L358"> minima[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_SPANS + "."</span>
+ id + "." + NAME_MTAS_STATS_SPANS_MINIMUM, null);
<span class="fc" id="L360"> maxima[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_SPANS + "."</span>
+ id + "." + NAME_MTAS_STATS_SPANS_MAXIMUM, null);
<span class="fc" id="L362"> types[tmpCounter] = rb.req.getParams().get(PARAM_MTAS_STATS_SPANS + "."</span>
+ id + "." + NAME_MTAS_STATS_SPANS_TYPE, null);
<span class="fc" id="L364"> Set<String> functionIds = MtasSolrResultUtil</span>
<span class="fc" id="L365"> .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_STATS_SPANS</span>
+ "." + id + "." + NAME_MTAS_STATS_SPANS_FUNCTION);
<span class="fc" id="L367"> functionExpressions[tmpCounter] = new String[functionIds.size()];</span>
<span class="fc" id="L368"> functionKeys[tmpCounter] = new String[functionIds.size()];</span>
<span class="fc" id="L369"> functionTypes[tmpCounter] = new String[functionIds.size()];</span>
<span class="fc" id="L370"> int tmpSubCounter = 0;</span>
<span class="pc bpc" id="L371" title="1 of 2 branches missed."> for (String functionId : functionIds) {</span>
<span class="nc" id="L372"> functionKeys[tmpCounter][tmpSubCounter] = rb.req.getParams()</span>
<span class="nc" id="L373"> .get(</span>
PARAM_MTAS_STATS_SPANS + "." + id + "."
+ NAME_MTAS_STATS_SPANS_FUNCTION + "." + functionId + "."
+ SUBNAME_MTAS_STATS_SPANS_FUNCTION_KEY,
<span class="nc" id="L377"> String.valueOf(tmpSubCounter))</span>
<span class="nc" id="L378"> .trim();</span>
<span class="nc" id="L379"> functionExpressions[tmpCounter][tmpSubCounter] = rb.req.getParams()</span>
<span class="nc" id="L380"> .get(PARAM_MTAS_STATS_SPANS + "." + id + "."</span>
+ NAME_MTAS_STATS_SPANS_FUNCTION + "." + functionId + "."
+ SUBNAME_MTAS_STATS_SPANS_FUNCTION_EXPRESSION, null);
<span class="nc" id="L383"> functionTypes[tmpCounter][tmpSubCounter] = rb.req.getParams()</span>
<span class="nc" id="L384"> .get(PARAM_MTAS_STATS_SPANS + "." + id + "."</span>
+ NAME_MTAS_STATS_SPANS_FUNCTION + "." + functionId + "."
+ SUBNAME_MTAS_STATS_SPANS_FUNCTION_TYPE, null);
<span class="nc" id="L387"> tmpSubCounter++;</span>
<span class="nc" id="L388"> }</span>
<span class="fc" id="L390"> Set<String> qIds = MtasSolrResultUtil</span>
<span class="fc" id="L391"> .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_STATS_SPANS</span>
+ "." + id + "." + NAME_MTAS_STATS_SPANS_QUERY);
<span class="pc bpc" id="L393" title="1 of 2 branches missed."> if (!qIds.isEmpty()) {</span>
<span class="fc" id="L394"> int tmpQCounter = 0;</span>
<span class="fc" id="L395"> queryTypes[tmpCounter] = new String[qIds.size()];</span>
<span class="fc" id="L396"> queryValues[tmpCounter] = new String[qIds.size()];</span>
<span class="fc" id="L397"> queryIgnores[tmpCounter] = new String[qIds.size()];</span>
<span class="fc" id="L398"> queryMaximumIgnoreLengths[tmpCounter] = new String[qIds.size()];</span>
<span class="fc" id="L399"> queryPrefixes[tmpCounter] = new String[qIds.size()];</span>
<span class="fc" id="L400"> queryVariables[tmpCounter] = new HashMap[qIds.size()];</span>
<span class="fc bfc" id="L401" title="All 2 branches covered."> for (String qId : qIds) {</span>
<span class="fc" id="L402"> queryTypes[tmpCounter][tmpQCounter] = rb.req.getParams()</span>
<span class="fc" id="L403"> .get(PARAM_MTAS_STATS_SPANS + "." + id + "."</span>
+ NAME_MTAS_STATS_SPANS_QUERY + "." + qId + "."
+ SUBNAME_MTAS_STATS_SPANS_QUERY_TYPE, null);
<span class="fc" id="L406"> queryValues[tmpCounter][tmpQCounter] = rb.req.getParams()</span>
<span class="fc" id="L407"> .get(PARAM_MTAS_STATS_SPANS + "." + id + "."</span>
+ NAME_MTAS_STATS_SPANS_QUERY + "." + qId + "."
+ SUBNAME_MTAS_STATS_SPANS_QUERY_VALUE, null);
<span class="fc" id="L410"> queryIgnores[tmpCounter][tmpQCounter] = rb.req.getParams()</span>
<span class="fc" id="L411"> .get(PARAM_MTAS_STATS_SPANS + "." + id + "."</span>
+ NAME_MTAS_STATS_SPANS_QUERY + "." + qId + "."
+ SUBNAME_MTAS_STATS_SPANS_QUERY_IGNORE, null);
<span class="fc" id="L414"> queryMaximumIgnoreLengths[tmpCounter][tmpQCounter] = rb.req</span>
<span class="fc" id="L415"> .getParams().get(</span>
PARAM_MTAS_STATS_SPANS + "." + id + "."
+ NAME_MTAS_STATS_SPANS_QUERY + "." + qId + "."
+ SUBNAME_MTAS_STATS_SPANS_QUERY_MAXIMUM_IGNORE_LENGTH,
null);
<span class="fc" id="L420"> queryPrefixes[tmpCounter][tmpQCounter] = rb.req.getParams()</span>
<span class="fc" id="L421"> .get(PARAM_MTAS_STATS_SPANS + "." + id + "."</span>
+ NAME_MTAS_STATS_SPANS_QUERY + "." + qId + "."
+ SUBNAME_MTAS_STATS_SPANS_QUERY_PREFIX, null);
<span class="fc" id="L424"> Set<String> vIds = MtasSolrResultUtil.getIdsFromParameters(</span>
<span class="fc" id="L425"> rb.req.getParams(),</span>
PARAM_MTAS_STATS_SPANS + "." + id + "."
+ NAME_MTAS_STATS_SPANS_QUERY + "." + qId + "."
+ SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE);
<span class="fc" id="L429"> queryVariables[tmpCounter][tmpQCounter] = new HashMap<>();</span>
<span class="fc bfc" id="L430" title="All 2 branches covered."> if (!vIds.isEmpty()) {</span>
<span class="fc" id="L431"> HashMap<String, ArrayList<String>> tmpVariables = new HashMap<>();</span>
<span class="fc bfc" id="L432" title="All 2 branches covered."> for (String vId : vIds) {</span>
<span class="fc" id="L433"> String name = rb.req.getParams()</span>
<span class="fc" id="L434"> .get(PARAM_MTAS_STATS_SPANS + "." + id + "."</span>
+ NAME_MTAS_STATS_SPANS_QUERY + "." + qId + "."
+ SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE + "." + vId
+ "." + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE_NAME,
null);
<span class="pc bpc" id="L439" title="1 of 2 branches missed."> if (name != null) {</span>
<span class="pc bpc" id="L440" title="1 of 2 branches missed."> if (!tmpVariables.containsKey(name)) {</span>
<span class="fc" id="L441"> tmpVariables.put(name, new ArrayList<String>());</span>
}
<span class="fc" id="L443"> String value = rb.req.getParams()</span>
<span class="fc" id="L444"> .get(PARAM_MTAS_STATS_SPANS + "." + id + "."</span>
+ NAME_MTAS_STATS_SPANS_QUERY + "." + qId + "."
+ SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE + "." + vId
+ "." + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE_VALUE,
null);
<span class="pc bpc" id="L449" title="1 of 2 branches missed."> if (value != null) {</span>
<span class="fc" id="L450"> ArrayList<String> list = new ArrayList<>();</span>
<span class="fc" id="L451"> String[] subList = value.split("(?<!\\\\),");</span>
<span class="fc bfc" id="L452" title="All 2 branches covered."> for (int i = 0; i < subList.length; i++) {</span>
<span class="fc" id="L453"> list.add(</span>
<span class="fc" id="L454"> subList[i].replace("\\,", ",").replace("\\\\", "\\"));</span>
}
<span class="fc" id="L456"> tmpVariables.get(name).addAll(list);</span>
}
}
<span class="fc" id="L459"> }</span>
<span class="fc bfc" id="L460" title="All 2 branches covered."> for (Entry<String, ArrayList<String>> entry : tmpVariables</span>
<span class="fc" id="L461"> .entrySet()) {</span>
<span class="fc" id="L462"> queryVariables[tmpCounter][tmpQCounter].put(entry.getKey(),</span>
<span class="fc" id="L463"> entry.getValue()</span>
<span class="fc" id="L464"> .toArray(new String[entry.getValue().size()]));</span>
<span class="fc" id="L465"> }</span>
}
<span class="fc" id="L467"> tmpQCounter++;</span>
<span class="fc" id="L468"> }</span>
<span class="fc" id="L469"> } else {</span>
<span class="nc" id="L470"> throw new IOException("no " + NAME_MTAS_STATS_SPANS_QUERY</span>
+ " for mtas stats span " + id);
}
<span class="pc bpc" id="L473" title="1 of 2 branches missed."> if (rb.req.getParams().getBool(PARAM_MTAS_STATS_SPANS + "." + id + "."</span>
+ NAME_MTAS_STATS_SPANS_EXPAND, false)) {
<span class="nc" id="L475"> expand[tmpCounter] = true;</span>
} else {
<span class="fc" id="L477"> expand[tmpCounter] = false;</span>
}
<span class="fc" id="L479"> tmpCounter++;</span>
<span class="fc" id="L480"> }</span>
<span class="fc" id="L481"> String uniqueKeyField = rb.req.getSchema().getUniqueKeyField().getName();</span>
<span class="fc" id="L482"> mtasFields.doStats = true;</span>
<span class="fc" id="L483"> mtasFields.doStatsSpans = true;</span>
<span class="fc" id="L484"> rb.setNeedDocSet(true);</span>
<span class="fc bfc" id="L485" title="All 2 branches covered."> for (String field : fields) {</span>
<span class="pc bpc" id="L486" title="2 of 4 branches missed."> if (field == null || field.isEmpty()) {</span>
<span class="nc" id="L487"> throw new IOException("no (valid) field in mtas stats spans");</span>
<span class="fc bfc" id="L488" title="All 2 branches covered."> } else if (!mtasFields.list.containsKey(field)) {</span>
<span class="fc" id="L489"> mtasFields.list.put(field, new ComponentField(uniqueKeyField));</span>
}
}
<span class="fc" id="L492"> MtasSolrResultUtil.compareAndCheck(keys, fields,</span>
<span class="fc" id="L493"> NAME_MTAS_STATS_SPANS_KEY, NAME_MTAS_STATS_SPANS_FIELD, true);</span>
<span class="fc" id="L494"> MtasSolrResultUtil.compareAndCheck(minima, fields,</span>
<span class="fc" id="L495"> NAME_MTAS_STATS_SPANS_MINIMUM, NAME_MTAS_STATS_SPANS_FIELD, false);</span>
<span class="fc" id="L496"> MtasSolrResultUtil.compareAndCheck(maxima, fields,</span>
<span class="fc" id="L497"> NAME_MTAS_STATS_SPANS_MAXIMUM, NAME_MTAS_STATS_SPANS_FIELD, false);</span>
<span class="fc" id="L498"> MtasSolrResultUtil.compareAndCheck(types, fields,</span>
<span class="fc" id="L499"> NAME_MTAS_STATS_SPANS_TYPE, NAME_MTAS_STATS_SPANS_FIELD, false);</span>
<span class="fc" id="L500"> MtasSolrResultUtil.compareAndCheck(types, fields,</span>
<span class="fc" id="L501"> NAME_MTAS_STATS_SPANS_FUNCTION, NAME_MTAS_STATS_SPANS_FIELD, false);</span>
<span class="fc bfc" id="L503" title="All 2 branches covered."> for (int i = 0; i < fields.length; i++) {</span>
<span class="fc" id="L504"> ComponentField cf = mtasFields.list.get(fields[i]);</span>
<span class="fc" id="L505"> int queryNumber = queryValues[i].length;</span>
<span class="fc" id="L506"> MtasSpanQuery[] ql = new MtasSpanQuery[queryNumber];</span>
<span class="fc bfc" id="L507" title="All 2 branches covered."> for (int j = 0; j < queryNumber; j++) {</span>
<span class="pc bpc" id="L508" title="1 of 2 branches missed."> Integer maximumIgnoreLength = (queryMaximumIgnoreLengths[i][j] == null)</span>
<span class="pc" id="L509"> ? null : Integer.parseInt(queryMaximumIgnoreLengths[i][j]);</span>
<span class="fc" id="L510"> 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="L514" title="All 2 branches covered."> if (cf.spanQueryList.contains(q)) {</span>
<span class="fc" id="L515"> q = cf.spanQueryList.get(cf.spanQueryList.indexOf(q));</span>
} else {
<span class="fc" id="L517"> cf.spanQueryList.add(q);</span>
}
<span class="fc" id="L519"> ql[j] = q;</span>
}
<span class="pc bpc" id="L521" title="1 of 4 branches missed."> Double minimum = (minima[i] == null) || (minima[i].isEmpty()) ? null</span>
<span class="fc" id="L522"> : Double.parseDouble(minima[i]);</span>
<span class="pc bpc" id="L523" title="3 of 4 branches missed."> Double maximum = (maxima[i] == null) || (maxima[i].isEmpty()) ? null</span>
<span class="pc" id="L524"> : Double.parseDouble(maxima[i]);</span>
<span class="pc bpc" id="L525" title="2 of 4 branches missed."> String key = (keys[i] == null) || (keys[i].isEmpty())</span>
<span class="pc" id="L526"> ? String.valueOf(i) + ":" + fields[i] + ":" + queryNumber</span>
<span class="fc" id="L527"> : keys[i].trim();</span>
<span class="pc bpc" id="L528" title="2 of 4 branches missed."> String type = (types[i] == null) || (types[i].isEmpty()) ? null</span>
<span class="fc" id="L529"> : types[i].trim();</span>
<span class="fc" id="L530"> String[] functionKey = functionKeys[i];</span>
<span class="fc" id="L531"> String[] functionExpression = functionExpressions[i];</span>
<span class="fc" id="L532"> String[] functionType = functionTypes[i];</span>
try {
<span class="fc" id="L534"> mtasFields.list.get(fields[i]).statsSpanList</span>
<span class="fc" id="L535"> .add(new ComponentSpan(ql, key, minimum, maximum, type,</span>
functionKey, functionExpression, functionType));
<span class="nc" id="L537"> } catch (ParseException e) {</span>
<span class="nc" id="L538"> throw new IOException(e.getMessage());</span>
<span class="fc" id="L539"> }</span>
<span class="pc bpc" id="L540" title="1 of 2 branches missed."> if (expand[i]) {</span>
<span class="nc" id="L541"> HashMap<String, String[]>[][] expandedQueryVariables = expandedQueryVariables(</span>
queryVariables[i]);
<span class="nc bnc" id="L543" title="All 2 branches missed."> for (int e = 0; e < expandedQueryVariables.length; e++) {</span>
<span class="nc" id="L544"> MtasSpanQuery[] eql = new MtasSpanQuery[queryNumber];</span>
<span class="nc bnc" id="L545" title="All 2 branches missed."> for (int j = 0; j < queryNumber; j++) {</span>
<span class="nc bnc" id="L546" title="All 2 branches missed."> Integer maximumIgnoreLength = (queryMaximumIgnoreLengths[i][j] == null)</span>
<span class="nc" id="L547"> ? null : Integer.parseInt(queryMaximumIgnoreLengths[i][j]);</span>
<span class="nc" id="L548"> 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="L553" title="All 2 branches missed."> if (cf.spanQueryList.contains(q)) {</span>
<span class="nc" id="L554"> q = cf.spanQueryList.get(cf.spanQueryList.indexOf(q));</span>
} else {
<span class="nc" id="L556"> cf.spanQueryList.add(q);</span>
}
<span class="nc" id="L558"> eql[j] = q;</span>
}
<span class="nc" id="L560"> String newKey = generateKey(key + " (" + e + ")",</span>
expandedQueryVariables[e]);
try {
<span class="nc" id="L563"> mtasFields.list.get(fields[i]).statsSpanList</span>
<span class="nc" id="L564"> .add(new ComponentSpan(eql, newKey, minimum, maximum, type,</span>
functionKey, functionExpression, functionType));
<span class="nc" id="L566"> } catch (ParseException ee) {</span>
<span class="nc" id="L567"> throw new IOException(ee.getMessage());</span>
<span class="nc" id="L568"> }</span>
}
}
}
<span class="fc" id="L572"> } else {</span>
<span class="nc" id="L573"> throw new IOException("missing parameters stats spans");</span>
}
<span class="fc" id="L575"> }</span>
/**
* Generate key.
*
* @param key the key
* @param queryVariables the query variables
* @return the string
*/
private String generateKey(String key,
HashMap<String, String[]>[] queryVariables) {
<span class="nc" id="L586"> StringBuilder newKey = new StringBuilder(key);</span>
<span class="nc" id="L587"> newKey.append(" -");</span>
<span class="nc bnc" id="L588" title="All 2 branches missed."> for (int q = 0; q < queryVariables.length; q++) {</span>
<span class="nc bnc" id="L589" title="All 4 branches missed."> if (queryVariables[q] != null && queryVariables[q].size() > 0) {</span>
<span class="nc bnc" id="L590" title="All 2 branches missed."> for (String name : queryVariables[q].keySet()) {</span>
<span class="nc" id="L591"> newKey.append(" q" + q + ":$" + name + "=");</span>
<span class="nc bnc" id="L592" title="All 2 branches missed."> if (queryVariables[q].get(name) != null</span>
<span class="nc bnc" id="L593" title="All 2 branches missed."> && queryVariables[q].get(name).length == 1) {</span>
<span class="nc" id="L594"> newKey.append("'" + queryVariables[q].get(name)[0]</span>
<span class="nc" id="L595"> .replace("\\", "\\\\").replace(",", "\\,") + "'");</span>
} else {
<span class="nc" id="L597"> newKey.append("-");</span>
}
<span class="nc" id="L599"> }</span>
}
}
<span class="nc" id="L602"> return newKey.toString();</span>
}
/**
* Expanded query variables.
*
* @param queryVariables the query variables
* @return the hash map[][]
*/
private HashMap<String, String[]>[][] expandedQueryVariables(
HashMap<String, String[]>[] queryVariables) {
<span class="nc" id="L613"> HashMap<String, String[]>[][] subResult = new HashMap[queryVariables.length][];</span>
<span class="nc bnc" id="L614" title="All 2 branches missed."> for (int q = 0; q < queryVariables.length; q++) {</span>
<span class="nc" id="L615"> subResult[q] = expandedQueryVariables(queryVariables[q]);</span>
}
<span class="nc" id="L617"> ArrayList<HashMap<String, String[]>[]> result = new ArrayList<>();</span>
<span class="nc" id="L618"> generatePermutations(result, 0, subResult);</span>
<span class="nc" id="L619"> 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<HashMap<String, String[]>[]> result, int index,
HashMap<String, String[]>[][] subResult) {
<span class="nc" id="L632"> int localIndex = index;</span>
<span class="nc" id="L633"> HashMap<String, String[]>[] value = subResult[localIndex];</span>
<span class="nc bnc" id="L634" title="All 2 branches missed."> if (localIndex == 0) {</span>
<span class="nc bnc" id="L635" title="All 2 branches missed."> for (int i = 0; i < value.length; i++) {</span>
<span class="nc" id="L636"> HashMap<String, String[]>[] resultItem = new HashMap[subResult.length];</span>
<span class="nc" id="L637"> resultItem[localIndex] = value[i];</span>
<span class="nc" id="L638"> result.add(resultItem);</span>
}
} else {
<span class="nc" id="L641"> ArrayList<HashMap<String, String[]>[]> newResult = new ArrayList<>();</span>
<span class="nc bnc" id="L642" title="All 2 branches missed."> for (int e = 0; e < result.size(); e++) {</span>
<span class="nc bnc" id="L643" title="All 2 branches missed."> for (int i = 0; i < value.length; i++) {</span>
<span class="nc" id="L644"> HashMap<String, String[]>[] resultItem = result.get(e);</span>
<span class="nc" id="L645"> resultItem[localIndex] = value[i];</span>
<span class="nc" id="L646"> newResult.add(resultItem);</span>
}
}
<span class="nc" id="L649"> result.clear();</span>
<span class="nc" id="L650"> result.addAll(newResult);</span>
}
<span class="nc" id="L652"> localIndex++;</span>
<span class="nc bnc" id="L653" title="All 2 branches missed."> if (localIndex < subResult.length) {</span>
<span class="nc" id="L654"> generatePermutations(result, localIndex, subResult);</span>
}
<span class="nc" id="L656"> }</span>
/**
* Expanded query variables.
*
* @param queryVariables the query variables
* @return the hash map[]
*/
private HashMap<String, String[]>[] expandedQueryVariables(
HashMap<String, String[]> queryVariables) {
<span class="nc" id="L666"> ArrayList<HashMap<String, String[]>> result = new ArrayList<>();</span>
<span class="nc" id="L667"> Set<String> keys = queryVariables.keySet();</span>
<span class="nc" id="L668"> generatePermutationsQueryVariables(result, keys, queryVariables);</span>
<span class="nc" id="L669"> 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<HashMap<String, String[]>> result, Set<String> keys,
HashMap<String, String[]> queryVariables) {
<span class="nc bnc" id="L682" title="All 4 branches missed."> if (keys != null && !keys.isEmpty()) {</span>
<span class="nc" id="L683"> Set<String> newKeys = new HashSet<>();</span>
<span class="nc" id="L684"> Iterator<String> it = keys.iterator();</span>
<span class="nc" id="L685"> String key = it.next();</span>
<span class="nc" id="L686"> String[] value = queryVariables.get(key);</span>
<span class="nc bnc" id="L687" title="All 2 branches missed."> if (result.isEmpty()) {</span>
HashMap<String, String[]> newItem;
<span class="nc bnc" id="L689" title="All 4 branches missed."> if (value == null || value.length == 0) {</span>
<span class="nc" id="L690"> newItem = new HashMap<>();</span>
<span class="nc" id="L691"> newItem.put(key, value);</span>
<span class="nc" id="L692"> result.add(newItem);</span>
} else {
<span class="nc bnc" id="L694" title="All 2 branches missed."> for (int j = 0; j < value.length; j++) {</span>
<span class="nc" id="L695"> newItem = new HashMap<>();</span>
<span class="nc" id="L696"> newItem.put(key, new String[] { value[j] });</span>
<span class="nc" id="L697"> result.add(newItem);</span>
}
}
} else {
<span class="nc" id="L701"> ArrayList<HashMap<String, String[]>> newResult = new ArrayList<>();</span>
<span class="nc bnc" id="L702" title="All 2 branches missed."> for (int i = 0; i < result.size(); i++) {</span>
HashMap<String, String[]> newItem;
<span class="nc bnc" id="L704" title="All 4 branches missed."> if (value == null || value.length == 0) {</span>
<span class="nc" id="L705"> newItem = (HashMap<String, String[]>) result.get(i).clone();</span>
<span class="nc" id="L706"> newItem.put(key, value);</span>
<span class="nc" id="L707"> newResult.add(newItem);</span>
} else {
<span class="nc bnc" id="L709" title="All 2 branches missed."> for (int j = 0; j < value.length; j++) {</span>
<span class="nc" id="L710"> newItem = (HashMap<String, String[]>) result.get(i).clone();</span>
<span class="nc" id="L711"> newItem.put(key, new String[] { value[j] });</span>
<span class="nc" id="L712"> newResult.add(newItem);</span>
}
}
}
<span class="nc" id="L716"> result.clear();</span>
<span class="nc" id="L717"> result.addAll(newResult);</span>
}
<span class="nc bnc" id="L719" title="All 2 branches missed."> while (it.hasNext()) {</span>
<span class="nc" id="L720"> newKeys.add(it.next());</span>
}
<span class="nc" id="L722"> generatePermutationsQueryVariables(result, newKeys, queryVariables);</span>
}
<span class="nc" id="L724"> }</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="L737" title="All 2 branches covered."> if ((sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) {</span>
// do nothing
} else {
// remove stats for other requests
<span class="fc" id="L741"> sreq.params.remove(PARAM_MTAS_STATS);</span>
<span class="fc" id="L742"> sreq.params.remove(PARAM_MTAS_STATS_POSITIONS);</span>
<span class="fc" id="L743"> Set<String> keys = MtasSolrResultUtil</span>
<span class="fc" id="L744"> .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_STATS_POSITIONS);</span>
<span class="fc bfc" id="L745" title="All 2 branches covered."> for (String key : keys) {</span>
<span class="fc" id="L746"> sreq.params.remove(</span>
PARAM_MTAS_STATS + "." + key + "." + NAME_MTAS_STATS_POSITIONS_KEY);
<span class="fc" id="L748"> sreq.params.remove(PARAM_MTAS_STATS + "." + key + "."</span>
+ NAME_MTAS_STATS_POSITIONS_FIELD);
<span class="fc" id="L750"> sreq.params.remove(PARAM_MTAS_STATS + "." + key + "."</span>
+ NAME_MTAS_STATS_POSITIONS_TYPE);
<span class="fc" id="L752"> sreq.params.remove(PARAM_MTAS_STATS + "." + key + "."</span>
+ NAME_MTAS_STATS_POSITIONS_MAXIMUM);
<span class="fc" id="L754"> sreq.params.remove(PARAM_MTAS_STATS + "." + key + "."</span>
+ NAME_MTAS_STATS_POSITIONS_MINIMUM);
<span class="fc" id="L756"> }</span>
<span class="fc" id="L757"> sreq.params.remove(PARAM_MTAS_STATS_TOKENS);</span>
<span class="fc" id="L758"> keys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
PARAM_MTAS_STATS_TOKENS);
<span class="fc bfc" id="L760" title="All 2 branches covered."> for (String key : keys) {</span>
<span class="fc" id="L761"> sreq.params.remove(</span>
PARAM_MTAS_STATS + "." + key + "." + NAME_MTAS_STATS_TOKENS_KEY);
<span class="fc" id="L763"> sreq.params.remove(</span>
PARAM_MTAS_STATS + "." + key + "." + NAME_MTAS_STATS_TOKENS_FIELD);
<span class="fc" id="L765"> sreq.params.remove(</span>
PARAM_MTAS_STATS + "." + key + "." + NAME_MTAS_STATS_TOKENS_TYPE);
<span class="fc" id="L767"> sreq.params.remove(PARAM_MTAS_STATS + "." + key + "."</span>
+ NAME_MTAS_STATS_TOKENS_MAXIMUM);
<span class="fc" id="L769"> sreq.params.remove(PARAM_MTAS_STATS + "." + key + "."</span>
+ NAME_MTAS_STATS_TOKENS_MINIMUM);
<span class="fc" id="L771"> }</span>
<span class="fc" id="L772"> sreq.params.remove(PARAM_MTAS_STATS_SPANS);</span>
<span class="fc" id="L773"> keys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
PARAM_MTAS_STATS_SPANS);
<span class="fc bfc" id="L775" title="All 2 branches covered."> for (String key : keys) {</span>
<span class="fc" id="L776"> sreq.params.remove(PARAM_MTAS_STATS_SPANS + "." + key + "."</span>
+ NAME_MTAS_STATS_SPANS_KEY);
<span class="fc" id="L778"> sreq.params.remove(PARAM_MTAS_STATS_SPANS + "." + key + "."</span>
+ NAME_MTAS_STATS_SPANS_FIELD);
<span class="fc" id="L780"> sreq.params.remove(PARAM_MTAS_STATS_SPANS + "." + key + "."</span>
+ NAME_MTAS_STATS_SPANS_TYPE);
<span class="fc" id="L782"> sreq.params.remove(PARAM_MTAS_STATS_SPANS + "." + key + "."</span>
+ NAME_MTAS_STATS_SPANS_MAXIMUM);
<span class="fc" id="L784"> sreq.params.remove(PARAM_MTAS_STATS_SPANS + "." + key + "."</span>
+ NAME_MTAS_STATS_SPANS_MINIMUM);
<span class="fc" id="L786"> Set<String> subKeys = MtasSolrResultUtil</span>
<span class="fc" id="L787"> .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_STATS_SPANS</span>
+ "." + key + "." + NAME_MTAS_STATS_SPANS_FUNCTION);
<span class="pc bpc" id="L789" title="1 of 2 branches missed."> for (String subKey : subKeys) {</span>
<span class="nc" id="L790"> sreq.params.remove(PARAM_MTAS_STATS_SPANS + "." + key + "."</span>
+ NAME_MTAS_STATS_SPANS_FUNCTION + "." + subKey + "."
+ SUBNAME_MTAS_STATS_SPANS_FUNCTION_EXPRESSION);
<span class="nc" id="L793"> sreq.params.remove(PARAM_MTAS_STATS_SPANS + "." + key + "."</span>
+ NAME_MTAS_STATS_SPANS_FUNCTION + "." + subKey + "."
+ SUBNAME_MTAS_STATS_SPANS_FUNCTION_KEY);
<span class="nc" id="L796"> sreq.params.remove(PARAM_MTAS_STATS_SPANS + "." + key + "."</span>
+ NAME_MTAS_STATS_SPANS_FUNCTION + "." + subKey + "."
+ SUBNAME_MTAS_STATS_SPANS_FUNCTION_TYPE);
<span class="nc" id="L799"> }</span>
<span class="fc" id="L800"> subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span>
PARAM_MTAS_STATS_SPANS + "." + key + "."
+ NAME_MTAS_STATS_SPANS_QUERY);
<span class="fc bfc" id="L803" title="All 2 branches covered."> for (String subKey : subKeys) {</span>
<span class="fc" id="L804"> sreq.params.remove(PARAM_MTAS_STATS_SPANS + "." + key + "."</span>
+ NAME_MTAS_STATS_SPANS_QUERY + "." + subKey + "."
+ SUBNAME_MTAS_STATS_SPANS_QUERY_IGNORE);
<span class="fc" id="L807"> sreq.params.remove(PARAM_MTAS_STATS_SPANS + "." + key + "."</span>
+ NAME_MTAS_STATS_SPANS_QUERY + "." + subKey + "."
+ SUBNAME_MTAS_STATS_SPANS_QUERY_MAXIMUM_IGNORE_LENGTH);
<span class="fc" id="L810"> sreq.params.remove(PARAM_MTAS_STATS_SPANS + "." + key + "."</span>
+ NAME_MTAS_STATS_SPANS_QUERY + "." + subKey + "."
+ SUBNAME_MTAS_STATS_SPANS_QUERY_PREFIX);
<span class="fc" id="L813"> sreq.params.remove(PARAM_MTAS_STATS_SPANS + "." + key + "."</span>
+ NAME_MTAS_STATS_SPANS_QUERY + "." + subKey + "."
+ SUBNAME_MTAS_STATS_SPANS_QUERY_TYPE);
<span class="fc" id="L816"> sreq.params.remove(PARAM_MTAS_STATS_SPANS + "." + key + "."</span>
+ NAME_MTAS_STATS_SPANS_QUERY + "." + subKey + "."
+ SUBNAME_MTAS_STATS_SPANS_QUERY_VALUE);
<span class="fc" id="L819"> Set<String> subSubKeys = MtasSolrResultUtil.getIdsFromParameters(</span>
<span class="fc" id="L820"> rb.req.getParams(),</span>
PARAM_MTAS_STATS_SPANS + "." + key + "."
+ NAME_MTAS_STATS_SPANS_QUERY + "." + subKey + "."
+ SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE);
<span class="fc bfc" id="L824" title="All 2 branches covered."> for (String subSubKey : subSubKeys) {</span>
<span class="fc" id="L825"> sreq.params.remove(PARAM_MTAS_STATS_SPANS + "." + key + "."</span>
+ NAME_MTAS_STATS_SPANS_QUERY + "." + subKey + "."
+ SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE + "." + subSubKey
+ "." + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE_NAME);
<span class="fc" id="L829"> sreq.params.remove(PARAM_MTAS_STATS_SPANS + "." + key + "."</span>
+ NAME_MTAS_STATS_SPANS_QUERY + "." + subKey + "."
+ SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE + "." + subSubKey
+ "." + SUBNAME_MTAS_STATS_SPANS_QUERY_VARIABLE_VALUE);
<span class="fc" id="L833"> }</span>
<span class="fc" id="L834"> }</span>
<span class="fc" id="L835"> }</span>
}
<span class="fc" id="L837"> }</span>
/*
* (non-Javadoc)
*
* @see
* mtas.solr.handler.component.util.MtasSolrComponent#create(mtas.codec.util.
* CodecComponent.BasicComponent, java.lang.Boolean)
*/
@Override
public SimpleOrderedMap<Object> create(ComponentStats response,
Boolean encode) throws IOException {
<span class="fc bfc" id="L849" title="All 2 branches covered."> if (response instanceof ComponentPosition) {</span>
<span class="fc" id="L850"> return createPosition((ComponentPosition) response, encode);</span>
<span class="fc bfc" id="L851" title="All 2 branches covered."> } else if (response instanceof ComponentToken) {</span>
<span class="fc" id="L852"> return createToken((ComponentToken) response, encode);</span>
<span class="pc bpc" id="L853" title="1 of 2 branches missed."> } else if (response instanceof ComponentSpan) {</span>
<span class="fc" id="L854"> return createSpan((ComponentSpan) response, encode);</span>
} else {
<span class="nc" id="L856"> throw new IOException("incorrect type " + 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<Object> createPosition(ComponentPosition position,
Boolean encode) throws IOException {
// System.out.println("Create stats position " + position.dataType + " "
// + position.statsType + " " + position.statsItems + " --- " + encode);
<span class="fc" id="L872"> SimpleOrderedMap<Object> mtasPositionResponse = new SimpleOrderedMap<>();</span>
<span class="fc" id="L873"> mtasPositionResponse.add("key", position.key);</span>
<span class="fc" id="L874"> MtasSolrMtasResult data = new MtasSolrMtasResult(position.dataCollector,</span>
position.dataType, position.statsType, position.statsItems, null);
<span class="fc bfc" id="L876" title="All 2 branches covered."> if (encode) {</span>
<span class="fc" id="L877"> mtasPositionResponse.add("_encoded_data",</span>
<span class="fc" id="L878"> MtasSolrResultUtil.encode(data));</span>
} else {
<span class="fc" id="L880"> mtasPositionResponse.add(position.dataCollector.getCollectorType(), data);</span>
<span class="fc" id="L881"> MtasSolrResultUtil.rewrite(mtasPositionResponse, searchComponent);</span>
}
<span class="fc" id="L883"> 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<Object> createToken(ComponentToken token,
Boolean encode) throws IOException {
// System.out.println("Create stats position " + position.dataType + " "
// + position.statsType + " " + position.statsItems + " --- " + encode);
<span class="fc" id="L898"> SimpleOrderedMap<Object> mtasTokenResponse = new SimpleOrderedMap<>();</span>
<span class="fc" id="L899"> mtasTokenResponse.add("key", token.key);</span>
<span class="fc" id="L900"> MtasSolrMtasResult data = new MtasSolrMtasResult(token.dataCollector,</span>
token.dataType, token.statsType, token.statsItems, null);
<span class="fc bfc" id="L902" title="All 2 branches covered."> if (encode) {</span>
<span class="fc" id="L903"> mtasTokenResponse.add("_encoded_data", MtasSolrResultUtil.encode(data));</span>
} else {
<span class="fc" id="L905"> mtasTokenResponse.add(token.dataCollector.getCollectorType(), data);</span>
<span class="fc" id="L906"> MtasSolrResultUtil.rewrite(mtasTokenResponse, searchComponent);</span>
}
<span class="fc" id="L908"> 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("unchecked")
private SimpleOrderedMap<Object> createSpan(ComponentSpan span,
Boolean encode) throws IOException {
// System.out.println("Create stats span " + span.dataType + " "
// + span.statsType + " " + span.statsItems + " --- " + encode);
<span class="fc" id="L924"> SimpleOrderedMap<Object> mtasSpanResponse = new SimpleOrderedMap<>();</span>
<span class="fc" id="L925"> mtasSpanResponse.add("key", span.key);</span>
<span class="fc" id="L926"> HashMap<MtasDataCollector<?, ?>, HashMap<String, MtasSolrMtasResult>> functionData = new HashMap<>();</span>
<span class="fc" id="L927"> HashMap<String, MtasSolrMtasResult> functionDataItem = new HashMap<>();</span>
<span class="fc" id="L928"> functionData.put(span.dataCollector, functionDataItem);</span>
<span class="pc bpc" id="L929" title="1 of 2 branches missed."> if (span.functions != null) {</span>
<span class="pc bpc" id="L930" title="1 of 2 branches missed."> for (SubComponentFunction function : span.functions) {</span>
<span class="nc" id="L931"> function.dataCollector.close();</span>
<span class="nc" id="L932"> 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="L937"> new String[] { null }, new Integer[] { 0 },</span>
<span class="nc" id="L938"> new Integer[] { Integer.MAX_VALUE }, null));</span>
<span class="nc" id="L939"> }</span>
}
<span class="fc" id="L941"> MtasSolrMtasResult data = new MtasSolrMtasResult(span.dataCollector,</span>
span.dataType, span.statsType, span.statsItems, functionData);
<span class="fc bfc" id="L943" title="All 2 branches covered."> if (encode) {</span>
<span class="fc" id="L944"> mtasSpanResponse.add("_encoded_data", MtasSolrResultUtil.encode(data));</span>
} else {
<span class="fc" id="L946"> mtasSpanResponse.add(span.dataCollector.getCollectorType(), data);</span>
<span class="fc" id="L947"> MtasSolrResultUtil.rewrite(mtasSpanResponse, searchComponent);</span>
}
<span class="fc" id="L949"> return mtasSpanResponse;</span>
}
/*
* (non-Javadoc)
*
* @see
* mtas.solr.handler.component.util.MtasSolrComponent#finishStage(org.apache.
* solr.handler.component.ResponseBuilder)
*/
@SuppressWarnings("unchecked")
public void finishStage(ResponseBuilder rb) {
<span class="pc bpc" id="L961" title="1 of 6 branches missed."> if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
&& rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY
&& rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {
<span class="fc bfc" id="L964" title="All 2 branches covered."> for (ShardRequest sreq : rb.finished) {</span>
<span class="pc bpc" id="L965" title="1 of 2 branches missed."> if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="pc bpc" id="L966" title="1 of 2 branches missed."> && sreq.params.getBool(PARAM_MTAS_STATS, false)) {</span>
<span class="fc bfc" id="L967" title="All 2 branches covered."> for (ShardResponse shardResponse : sreq.responses) {</span>
<span class="fc" id="L968"> NamedList<Object> response = shardResponse.getSolrResponse()</span>
<span class="fc" id="L969"> .getResponse();</span>
try {
<span class="fc" id="L971"> ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response</span>
<span class="nc" id="L972"> .findRecursive("mtas", "stats");</span>
<span class="nc bnc" id="L973" title="All 2 branches missed."> if (data != null) {</span>
<span class="nc" id="L974"> MtasSolrResultUtil.decode(data);</span>
}
<span class="fc" id="L976"> } catch (ClassCastException e) {</span>
<span class="fc" id="L977"> log.debug(e);</span>
// shouldnt happen
<span class="nc" id="L979"> }</span>
<span class="fc" id="L980"> }</span>
}
<span class="fc" id="L982"> }</span>
}
<span class="fc" id="L984"> }</span>
/*
* (non-Javadoc)
*
* @see
* mtas.solr.handler.component.util.MtasSolrComponent#distributedProcess(org.
* apache.solr.handler.component.ResponseBuilder,
* mtas.codec.util.CodecComponent.ComponentFields)
*/
@SuppressWarnings("unchecked")
public void distributedProcess(ResponseBuilder rb, ComponentFields mtasFields)
throws IOException {
// rewrite
<span class="fc" id="L998"> NamedList<Object> mtasResponse = null;</span>
try {
<span class="fc" id="L1000"> mtasResponse = (NamedList<Object>) rb.rsp.getValues().get("mtas");</span>
<span class="nc" id="L1001"> } catch (ClassCastException e) {</span>
<span class="nc" id="L1002"> log.debug(e);</span>
<span class="nc" id="L1003"> mtasResponse = null;</span>
<span class="fc" id="L1004"> }</span>
<span class="pc bpc" id="L1005" title="1 of 2 branches missed."> if (mtasResponse != null) {</span>
NamedList<Object> mtasResponseStats;
try {
<span class="fc" id="L1008"> mtasResponseStats = (NamedList<Object>) mtasResponse.get("stats");</span>
<span class="pc bpc" id="L1009" title="1 of 2 branches missed."> if (mtasResponseStats != null) {</span>
<span class="fc" id="L1010"> MtasSolrResultUtil.rewrite(mtasResponseStats, searchComponent);</span>
}
<span class="nc" id="L1012"> } catch (ClassCastException e) {</span>
<span class="nc" id="L1013"> log.debug(e);</span>
<span class="nc" id="L1014"> mtasResponse.remove("stats");</span>
<span class="fc" id="L1015"> }</span>
}
<span class="fc" id="L1017"> }</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>