<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>MtasSolrComponentGroup.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">MTAS</a> > <a href="index.source.html" class="el_package">mtas.solr.handler.component.util</a> > <span class="el_source">MtasSolrComponentGroup.java</span></div><h1>MtasSolrComponentGroup.java</h1><pre class="source lang-java linenums">package mtas.solr.handler.component.util; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Map.Entry; import java.util.Set; import java.util.SortedSet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.SimpleOrderedMap; import org.apache.solr.handler.component.ResponseBuilder; import org.apache.solr.handler.component.SearchComponent; import org.apache.solr.handler.component.ShardRequest; import org.apache.solr.handler.component.ShardResponse; import mtas.codec.util.CodecComponent.ComponentField; import mtas.codec.util.CodecComponent.ComponentFields; import mtas.codec.util.CodecComponent.ComponentGroup; import mtas.search.spans.util.MtasSpanQuery; import mtas.solr.handler.component.MtasSolrSearchComponent; /** * The Class MtasSolrComponentGroup. */ public class MtasSolrComponentGroup implements MtasSolrComponent<ComponentGroup> { /** The Constant log. */ <span class="fc" id="L32"> private static final Log log = LogFactory</span> <span class="fc" id="L33"> .getLog(MtasSolrComponentGroup.class);</span> /** The search component. */ MtasSolrSearchComponent searchComponent; /** The Constant PARAM_MTAS_GROUP. */ public static final String PARAM_MTAS_GROUP = MtasSolrSearchComponent.PARAM_MTAS + ".group"; /** The Constant NAME_MTAS_GROUP_FIELD. */ public static final String NAME_MTAS_GROUP_FIELD = "field"; /** The Constant NAME_MTAS_GROUP_QUERY_TYPE. */ public static final String NAME_MTAS_GROUP_QUERY_TYPE = "query.type"; /** The Constant NAME_MTAS_GROUP_QUERY_VALUE. */ public static final String NAME_MTAS_GROUP_QUERY_VALUE = "query.value"; /** The Constant NAME_MTAS_GROUP_QUERY_PREFIX. */ public static final String NAME_MTAS_GROUP_QUERY_PREFIX = "query.prefix"; /** The Constant NAME_MTAS_GROUP_QUERY_IGNORE. */ public static final String NAME_MTAS_GROUP_QUERY_IGNORE = "query.ignore"; /** The Constant NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH. */ public static final String NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH = "query.maximumIgnoreLength"; /** The Constant NAME_MTAS_GROUP_QUERY_VARIABLE. */ public static final String NAME_MTAS_GROUP_QUERY_VARIABLE = "query.variable"; /** The Constant SUBNAME_MTAS_GROUP_QUERY_VARIABLE_NAME. */ public static final String SUBNAME_MTAS_GROUP_QUERY_VARIABLE_NAME = "name"; /** The Constant SUBNAME_MTAS_GROUP_QUERY_VARIABLE_VALUE. */ public static final String SUBNAME_MTAS_GROUP_QUERY_VARIABLE_VALUE = "value"; /** The Constant NAME_MTAS_GROUP_KEY. */ public static final String NAME_MTAS_GROUP_KEY = "key"; /** The Constant NAME_MTAS_GROUP_NUMBER. */ public static final String NAME_MTAS_GROUP_NUMBER = "number"; /** The Constant NAME_MTAS_GROUP_GROUPING_LEFT. */ public static final String NAME_MTAS_GROUP_GROUPING_LEFT = "grouping.left"; /** The Constant NAME_MTAS_GROUP_GROUPING_RIGHT. */ public static final String NAME_MTAS_GROUP_GROUPING_RIGHT = "grouping.right"; /** The Constant NAME_MTAS_GROUP_GROUPING_HIT_INSIDE. */ public static final String NAME_MTAS_GROUP_GROUPING_HIT_INSIDE = "grouping.hit.inside"; /** The Constant NAME_MTAS_GROUP_GROUPING_HIT_LEFT. */ public static final String NAME_MTAS_GROUP_GROUPING_HIT_LEFT = "grouping.hit.left"; /** The Constant NAME_MTAS_GROUP_GROUPING_HIT_RIGHT. */ public static final String NAME_MTAS_GROUP_GROUPING_HIT_RIGHT = "grouping.hit.right"; /** The Constant NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT. */ public static final String NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT = "grouping.hit.insideLeft"; /** The Constant NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT. */ public static final String NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT = "grouping.hit.insideRight"; /** The Constant NAME_MTAS_GROUP_GROUPING_POSITION. */ public static final String NAME_MTAS_GROUP_GROUPING_POSITION = "position"; /** The Constant NAME_MTAS_GROUP_GROUPING_PREFIXES. */ public static final String NAME_MTAS_GROUP_GROUPING_PREFIXES = "prefixes"; /** The Constant DEFAULT_NUMBER. */ private static final int DEFAULT_NUMBER = 10; /** * Instantiates a new mtas solr component group. * * @param searchComponent the search component */ <span class="fc" id="L110"> public MtasSolrComponentGroup(MtasSolrSearchComponent searchComponent) {</span> <span class="fc" id="L111"> this.searchComponent = searchComponent;</span> <span class="fc" id="L112"> }</span> /* * (non-Javadoc) * * @see * mtas.solr.handler.component.util.MtasSolrComponent#prepare(org.apache.solr. * handler.component.ResponseBuilder, * mtas.codec.util.CodecComponent.ComponentFields) */ public void prepare(ResponseBuilder rb, ComponentFields mtasFields) throws IOException { <span class="nc" id="L124"> Set<String> ids = MtasSolrResultUtil</span> <span class="nc" id="L125"> .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_GROUP);</span> <span class="nc bnc" id="L126" title="All 2 branches missed."> if (!ids.isEmpty()) {</span> <span class="nc" id="L127"> int tmpCounter = 0;</span> <span class="nc" id="L128"> String[] fields = new String[ids.size()];</span> <span class="nc" id="L129"> String[] queryTypes = new String[ids.size()];</span> <span class="nc" id="L130"> String[] queryValues = new String[ids.size()];</span> <span class="nc" id="L131"> String[] queryPrefixes = new String[ids.size()];</span> <span class="nc" id="L132"> String[] queryIgnores = new String[ids.size()];</span> <span class="nc" id="L133"> String[] queryMaximumIgnoreLengths = new String[ids.size()];</span> <span class="nc" id="L134"> HashMap<String, String[]>[] queryVariables = new HashMap[ids.size()];</span> <span class="nc" id="L135"> String[] keys = new String[ids.size()];</span> <span class="nc" id="L136"> String[] numbers = new String[ids.size()];</span> <span class="nc" id="L137"> String[][] groupingLeftPosition = new String[ids.size()][];</span> <span class="nc" id="L138"> String[][] groupingLeftPrefixes = new String[ids.size()][];</span> <span class="nc" id="L139"> String[][] groupingRightPosition = new String[ids.size()][];</span> <span class="nc" id="L140"> String[][] groupingRightPrefixes = new String[ids.size()][];</span> <span class="nc" id="L141"> String[] groupingHitInsidePrefixes = new String[ids.size()];</span> <span class="nc" id="L142"> String[][] groupingHitLeftPosition = new String[ids.size()][];</span> <span class="nc" id="L143"> String[][] groupingHitLeftPrefixes = new String[ids.size()][];</span> <span class="nc" id="L144"> String[][] groupingHitRightPosition = new String[ids.size()][];</span> <span class="nc" id="L145"> String[][] groupingHitRightPrefixes = new String[ids.size()][];</span> <span class="nc" id="L146"> String[][] groupingHitInsideLeftPosition = new String[ids.size()][];</span> <span class="nc" id="L147"> String[][] groupingHitInsideLeftPrefixes = new String[ids.size()][];</span> <span class="nc" id="L148"> String[][] groupingHitInsideRightPosition = new String[ids.size()][];</span> <span class="nc" id="L149"> String[][] groupingHitInsideRightPrefixes = new String[ids.size()][];</span> <span class="nc bnc" id="L150" title="All 2 branches missed."> for (String id : ids) {</span> <span class="nc" id="L151"> fields[tmpCounter] = rb.req.getParams().get(</span> PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_FIELD, null); <span class="nc" id="L153"> keys[tmpCounter] = rb.req.getParams()</span> <span class="nc" id="L154"> .get(PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_KEY,</span> <span class="nc" id="L155"> String.valueOf(tmpCounter))</span> <span class="nc" id="L156"> .trim();</span> <span class="nc" id="L157"> numbers[tmpCounter] = rb.req.getParams().get(</span> PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_NUMBER, null); <span class="nc" id="L159"> queryTypes[tmpCounter] = rb.req.getParams().get(</span> PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_QUERY_TYPE, null); <span class="nc" id="L162"> queryValues[tmpCounter] = rb.req.getParams().get(</span> PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_QUERY_VALUE, null); <span class="nc" id="L165"> queryPrefixes[tmpCounter] = rb.req.getParams().get(</span> PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_QUERY_PREFIX, null); <span class="nc" id="L168"> queryIgnores[tmpCounter] = rb.req.getParams().get(</span> PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_QUERY_IGNORE, null); <span class="nc" id="L171"> queryMaximumIgnoreLengths[tmpCounter] = rb.req.getParams()</span> <span class="nc" id="L172"> .get(PARAM_MTAS_GROUP + "." + id + "."</span> + NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH, null); <span class="nc" id="L174"> Set<String> vIds = MtasSolrResultUtil.getIdsFromParameters(</span> <span class="nc" id="L175"> rb.req.getParams(),</span> PARAM_MTAS_GROUP + "." + id + "." + NAME_MTAS_GROUP_QUERY_VARIABLE); <span class="nc" id="L177"> queryVariables[tmpCounter] = new HashMap<>();</span> <span class="nc bnc" id="L178" title="All 2 branches missed."> if (!vIds.isEmpty()) {</span> <span class="nc" id="L179"> HashMap<String, ArrayList<String>> tmpVariables = new HashMap<>();</span> <span class="nc bnc" id="L180" title="All 2 branches missed."> for (String vId : vIds) {</span> <span class="nc" id="L181"> String name = rb.req.getParams()</span> <span class="nc" id="L182"> .get(PARAM_MTAS_GROUP + "." + id + "."</span> + NAME_MTAS_GROUP_QUERY_VARIABLE + "." + vId + "." + SUBNAME_MTAS_GROUP_QUERY_VARIABLE_NAME, null); <span class="nc bnc" id="L185" title="All 2 branches missed."> if (name != null) {</span> <span class="nc bnc" id="L186" title="All 2 branches missed."> if (!tmpVariables.containsKey(name)) {</span> <span class="nc" id="L187"> tmpVariables.put(name, new ArrayList<String>());</span> } <span class="nc" id="L189"> String value = rb.req.getParams()</span> <span class="nc" id="L190"> .get(PARAM_MTAS_GROUP + "." + id + "."</span> + NAME_MTAS_GROUP_QUERY_VARIABLE + "." + vId + "." + SUBNAME_MTAS_GROUP_QUERY_VARIABLE_VALUE, null); <span class="nc bnc" id="L193" title="All 2 branches missed."> if (value != null) {</span> <span class="nc" id="L194"> ArrayList<String> list = new ArrayList<>();</span> <span class="nc" id="L195"> String[] subList = value.split("(?<!\\\\),");</span> <span class="nc bnc" id="L196" title="All 2 branches missed."> for (int i = 0; i < subList.length; i++) {</span> <span class="nc" id="L197"> list.add(</span> <span class="nc" id="L198"> subList[i].replace("\\,", ",").replace("\\\\", "\\"));</span> } <span class="nc" id="L200"> tmpVariables.get(name).addAll(list);</span> } } <span class="nc" id="L203"> }</span> <span class="nc bnc" id="L204" title="All 2 branches missed."> for (Entry<String, ArrayList<String>> entry : tmpVariables</span> <span class="nc" id="L205"> .entrySet()) {</span> <span class="nc" id="L206"> queryVariables[tmpCounter].put(entry.getKey(),</span> <span class="nc" id="L207"> entry.getValue().toArray(new String[entry.getValue().size()]));</span> <span class="nc" id="L208"> }</span> } <span class="nc" id="L210"> groupingHitInsidePrefixes[tmpCounter] = null;</span> // collect SortedSet<String> gids; String tmpName; // collect grouping inside <span class="nc" id="L215"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span> + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE; <span class="nc" id="L217"> groupingHitInsidePrefixes[tmpCounter] = rb.req.getParams()</span> <span class="nc" id="L218"> .get(tmpName + "." + NAME_MTAS_GROUP_GROUPING_PREFIXES);</span> // collect grouping left <span class="nc" id="L220"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span> + NAME_MTAS_GROUP_GROUPING_LEFT; <span class="nc" id="L222"> gids = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span> tmpName); <span class="nc" id="L224"> groupingLeftPosition[tmpCounter] = new String[gids.size()];</span> <span class="nc" id="L225"> groupingLeftPrefixes[tmpCounter] = new String[gids.size()];</span> <span class="nc" id="L226"> prepare(rb.req.getParams(), gids, tmpName,</span> groupingLeftPosition[tmpCounter], groupingLeftPrefixes[tmpCounter]); // collect grouping right <span class="nc" id="L229"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span> + NAME_MTAS_GROUP_GROUPING_RIGHT; <span class="nc" id="L231"> gids = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span> tmpName); <span class="nc" id="L233"> groupingRightPosition[tmpCounter] = new String[gids.size()];</span> <span class="nc" id="L234"> groupingRightPrefixes[tmpCounter] = new String[gids.size()];</span> <span class="nc" id="L235"> prepare(rb.req.getParams(), gids, tmpName,</span> groupingRightPosition[tmpCounter], groupingRightPrefixes[tmpCounter]); // collect grouping hit left <span class="nc" id="L239"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span> + NAME_MTAS_GROUP_GROUPING_HIT_LEFT; <span class="nc" id="L241"> gids = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span> tmpName); <span class="nc" id="L243"> groupingHitLeftPosition[tmpCounter] = new String[gids.size()];</span> <span class="nc" id="L244"> groupingHitLeftPrefixes[tmpCounter] = new String[gids.size()];</span> <span class="nc" id="L245"> prepare(rb.req.getParams(), gids, tmpName,</span> groupingHitLeftPosition[tmpCounter], groupingHitLeftPrefixes[tmpCounter]); // collect grouping hit right <span class="nc" id="L249"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span> + NAME_MTAS_GROUP_GROUPING_HIT_RIGHT; <span class="nc" id="L251"> gids = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span> tmpName); <span class="nc" id="L253"> groupingHitRightPosition[tmpCounter] = new String[gids.size()];</span> <span class="nc" id="L254"> groupingHitRightPrefixes[tmpCounter] = new String[gids.size()];</span> <span class="nc" id="L255"> prepare(rb.req.getParams(), gids, tmpName,</span> groupingHitRightPosition[tmpCounter], groupingHitRightPrefixes[tmpCounter]); // collect grouping hit inside left <span class="nc" id="L259"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span> + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT; <span class="nc" id="L261"> gids = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span> tmpName); <span class="nc" id="L263"> groupingHitInsideLeftPosition[tmpCounter] = new String[gids.size()];</span> <span class="nc" id="L264"> groupingHitInsideLeftPrefixes[tmpCounter] = new String[gids.size()];</span> <span class="nc" id="L265"> prepare(rb.req.getParams(), gids, tmpName,</span> groupingHitInsideLeftPosition[tmpCounter], groupingHitInsideLeftPrefixes[tmpCounter]); // collect grouping hit inside right <span class="nc" id="L269"> tmpName = PARAM_MTAS_GROUP + "." + id + "."</span> + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT; <span class="nc" id="L271"> gids = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span> tmpName); <span class="nc" id="L273"> groupingHitInsideRightPosition[tmpCounter] = new String[gids.size()];</span> <span class="nc" id="L274"> groupingHitInsideRightPrefixes[tmpCounter] = new String[gids.size()];</span> <span class="nc" id="L275"> prepare(rb.req.getParams(), gids, tmpName,</span> groupingHitInsideRightPosition[tmpCounter], groupingHitInsideRightPrefixes[tmpCounter]); <span class="nc" id="L279"> tmpCounter++;</span> <span class="nc" id="L280"> }</span> <span class="nc" id="L281"> String uniqueKeyField = rb.req.getSchema().getUniqueKeyField().getName();</span> <span class="nc" id="L282"> mtasFields.doGroup = true;</span> <span class="nc" id="L283"> rb.setNeedDocSet(true);</span> <span class="nc bnc" id="L284" title="All 2 branches missed."> for (String field : fields) {</span> <span class="nc bnc" id="L285" title="All 4 branches missed."> if (field == null || field.isEmpty()) {</span> <span class="nc" id="L286"> throw new IOException("no (valid) field in mtas group");</span> <span class="nc bnc" id="L287" title="All 2 branches missed."> } else if (!mtasFields.list.containsKey(field)) {</span> <span class="nc" id="L288"> mtasFields.list.put(field, new ComponentField(uniqueKeyField));</span> } } <span class="nc" id="L291"> MtasSolrResultUtil.compareAndCheck(keys, fields, NAME_MTAS_GROUP_KEY,</span> <span class="nc" id="L292"> NAME_MTAS_GROUP_FIELD, true);</span> <span class="nc" id="L293"> MtasSolrResultUtil.compareAndCheck(queryValues, fields,</span> <span class="nc" id="L294"> NAME_MTAS_GROUP_QUERY_VALUE, NAME_MTAS_GROUP_FIELD, false);</span> <span class="nc" id="L295"> MtasSolrResultUtil.compareAndCheck(queryTypes, fields,</span> <span class="nc" id="L296"> NAME_MTAS_GROUP_QUERY_TYPE, NAME_MTAS_GROUP_FIELD, false);</span> <span class="nc bnc" id="L297" title="All 2 branches missed."> for (int i = 0; i < fields.length; i++) {</span> <span class="nc" id="L298"> ComponentField cf = mtasFields.list.get(fields[i]);</span> <span class="nc bnc" id="L299" title="All 2 branches missed."> Integer maximumIgnoreLength = (queryMaximumIgnoreLengths[i] == null)</span> <span class="nc" id="L300"> ? null : Integer.parseInt(queryMaximumIgnoreLengths[i]);</span> <span class="nc" id="L301"> MtasSpanQuery q = MtasSolrResultUtil.constructQuery(queryValues[i],</span> queryTypes[i], queryPrefixes[i], queryVariables[i], fields[i], queryIgnores[i], maximumIgnoreLength); // minimize number of queries <span class="nc bnc" id="L305" title="All 2 branches missed."> if (cf.spanQueryList.contains(q)) {</span> <span class="nc" id="L306"> q = cf.spanQueryList.get(cf.spanQueryList.indexOf(q));</span> } else { <span class="nc" id="L308"> cf.spanQueryList.add(q);</span> } <span class="nc bnc" id="L310" title="All 4 branches missed."> String key = (keys[i] == null) || (keys[i].isEmpty())</span> <span class="nc" id="L311"> ? String.valueOf(i) + ":" + fields[i] + ":" + queryValues[i]</span> <span class="nc" id="L312"> : keys[i].trim();</span> <span class="nc bnc" id="L313" title="All 4 branches missed."> int number = (numbers[i] == null) || (numbers[i].isEmpty())</span> <span class="nc" id="L314"> ? DEFAULT_NUMBER : Integer.parseInt(numbers[i]);</span> <span class="nc" id="L315"> mtasFields.list.get(fields[i]).groupList.add(new ComponentGroup(q, key,</span> number, groupingHitInsidePrefixes[i], groupingHitInsideLeftPosition[i], groupingHitInsideLeftPrefixes[i], groupingHitInsideRightPosition[i], groupingHitInsideRightPrefixes[i], groupingHitLeftPosition[i], groupingHitLeftPrefixes[i], groupingHitRightPosition[i], groupingHitRightPrefixes[i], groupingLeftPosition[i], groupingLeftPrefixes[i], groupingRightPosition[i], groupingRightPrefixes[i])); } } <span class="nc" id="L326"> }</span> /** * Prepare. * * @param solrParams the solr params * @param gids the gids * @param name the name * @param positions the positions * @param prefixes the prefixes * @throws IOException Signals that an I/O exception has occurred. */ private void prepare(SolrParams solrParams, SortedSet<String> gids, String name, String[] positions, String[] prefixes) throws IOException { <span class="nc bnc" id="L340" title="All 2 branches missed."> if (!gids.isEmpty()) {</span> <span class="nc" id="L341"> int tmpSubCounter = 0;</span> <span class="nc bnc" id="L342" title="All 2 branches missed."> for (String gid : gids) {</span> <span class="nc" id="L343"> positions[tmpSubCounter] = solrParams.get(</span> name + "." + gid + "." + NAME_MTAS_GROUP_GROUPING_POSITION, null); <span class="nc" id="L345"> prefixes[tmpSubCounter] = solrParams.get(</span> name + "." + gid + "." + NAME_MTAS_GROUP_GROUPING_PREFIXES, null); <span class="nc bnc" id="L347" title="All 2 branches missed."> if (positions[tmpSubCounter] == null) {</span> <span class="nc" id="L348"> throw new IOException("no position for " + gid);</span> <span class="nc bnc" id="L349" title="All 2 branches missed."> } else if (prefixes[tmpSubCounter] == null) {</span> <span class="nc" id="L350"> throw new IOException("no prefix for " + gid);</span> } <span class="nc" id="L352"> tmpSubCounter++;</span> <span class="nc" id="L353"> }</span> } <span class="nc" id="L355"> }</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="L368" title="All 2 branches missed."> if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span> <span class="nc bnc" id="L369" title="All 2 branches missed."> && sreq.params.getBool(PARAM_MTAS_GROUP, false)) {</span> <span class="nc bnc" id="L370" title="All 2 branches missed."> if ((sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) {</span> // do nothing } else { // remove prefix for other requests <span class="nc" id="L374"> Set<String> keys = MtasSolrResultUtil</span> <span class="nc" id="L375"> .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_GROUP);</span> <span class="nc" id="L376"> sreq.params.remove(PARAM_MTAS_GROUP);</span> Set<String> subKeys; <span class="nc bnc" id="L378" title="All 2 branches missed."> for (String key : keys) {</span> <span class="nc" id="L379"> sreq.params.remove(</span> PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_FIELD); <span class="nc" id="L381"> sreq.params</span> <span class="nc" id="L382"> .remove(PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_KEY);</span> <span class="nc" id="L383"> sreq.params.remove(</span> PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_QUERY_TYPE); <span class="nc" id="L385"> sreq.params.remove(</span> PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_QUERY_VALUE); <span class="nc" id="L387"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span> + NAME_MTAS_GROUP_QUERY_PREFIX); <span class="nc" id="L389"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span> + NAME_MTAS_GROUP_QUERY_IGNORE); <span class="nc" id="L391"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span> + NAME_MTAS_GROUP_QUERY_MAXIMUM_IGNORE_LENGTH); <span class="nc" id="L393"> subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span> PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_GROUPING_LEFT); <span class="nc bnc" id="L396" title="All 2 branches missed."> for (String subKey : subKeys) {</span> <span class="nc" id="L397"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span> + NAME_MTAS_GROUP_GROUPING_LEFT + "." + subKey + "." + NAME_MTAS_GROUP_GROUPING_POSITION); <span class="nc" id="L400"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span> + NAME_MTAS_GROUP_GROUPING_LEFT + "." + subKey + "." + NAME_MTAS_GROUP_GROUPING_PREFIXES); <span class="nc" id="L403"> }</span> <span class="nc" id="L404"> subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span> PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_GROUPING_RIGHT); <span class="nc bnc" id="L407" title="All 2 branches missed."> for (String subKey : subKeys) {</span> <span class="nc" id="L408"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span> + NAME_MTAS_GROUP_GROUPING_RIGHT + "." + subKey + "." + NAME_MTAS_GROUP_GROUPING_POSITION); <span class="nc" id="L411"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span> + NAME_MTAS_GROUP_GROUPING_RIGHT + "." + subKey + "." + NAME_MTAS_GROUP_GROUPING_PREFIXES); <span class="nc" id="L414"> }</span> <span class="nc" id="L415"> subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span> PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE); <span class="nc bnc" id="L418" title="All 2 branches missed."> for (String subKey : subKeys) {</span> <span class="nc" id="L419"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span> + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE + "." + subKey + "." + NAME_MTAS_GROUP_GROUPING_POSITION); <span class="nc" id="L422"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span> + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE + "." + subKey + "." + NAME_MTAS_GROUP_GROUPING_PREFIXES); <span class="nc" id="L425"> }</span> <span class="nc" id="L426"> subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span> PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT); <span class="nc bnc" id="L429" title="All 2 branches missed."> for (String subKey : subKeys) {</span> <span class="nc" id="L430"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span> + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT + "." + subKey + "." + NAME_MTAS_GROUP_GROUPING_POSITION); <span class="nc" id="L433"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span> + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_LEFT + "." + subKey + "." + NAME_MTAS_GROUP_GROUPING_PREFIXES); <span class="nc" id="L436"> }</span> <span class="nc" id="L437"> subKeys = MtasSolrResultUtil.getIdsFromParameters(rb.req.getParams(),</span> PARAM_MTAS_GROUP + "." + key + "." + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT); <span class="nc bnc" id="L440" title="All 2 branches missed."> for (String subKey : subKeys) {</span> <span class="nc" id="L441"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span> + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT + "." + subKey + "." + NAME_MTAS_GROUP_GROUPING_POSITION); <span class="nc" id="L444"> sreq.params.remove(PARAM_MTAS_GROUP + "." + key + "."</span> + NAME_MTAS_GROUP_GROUPING_HIT_INSIDE_RIGHT + "." + subKey + "." + NAME_MTAS_GROUP_GROUPING_PREFIXES); <span class="nc" id="L447"> }</span> <span class="nc" id="L448"> }</span> } } <span class="nc" id="L451"> }</span> /* * (non-Javadoc) * * @see * mtas.solr.handler.component.util.MtasSolrComponent#create(mtas.codec.util. * CodecComponent.BasicComponent, java.lang.Boolean) */ @SuppressWarnings("unchecked") public SimpleOrderedMap<Object> create(ComponentGroup group, Boolean encode) throws IOException { <span class="nc" id="L463"> SimpleOrderedMap<Object> mtasGroupResponse = new SimpleOrderedMap<>();</span> <span class="nc" id="L464"> mtasGroupResponse.add("key", group.key);</span> <span class="nc" id="L465"> MtasSolrMtasResult data = new MtasSolrMtasResult(group.dataCollector,</span> new String[] { group.dataType }, new String[] { group.statsType }, new SortedSet[] { group.statsItems }, new String[] { group.sortType }, new String[] { group.sortDirection }, new Integer[] { group.start }, new Integer[] { group.number }, null); <span class="nc bnc" id="L470" title="All 2 branches missed."> if (encode) {</span> <span class="nc" id="L471"> mtasGroupResponse.add("_encoded_list", MtasSolrResultUtil.encode(data));</span> } else { <span class="nc" id="L473"> mtasGroupResponse.add("list", data);</span> <span class="nc" id="L474"> MtasSolrResultUtil.rewrite(mtasGroupResponse, searchComponent);</span> } <span class="nc" id="L476"> return mtasGroupResponse;</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="nc bnc" id="L488" title="All 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="nc bnc" id="L491" title="All 2 branches missed."> for (ShardRequest sreq : rb.finished) {</span> <span class="nc bnc" id="L492" title="All 2 branches missed."> if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span> <span class="nc bnc" id="L493" title="All 2 branches missed."> && sreq.params.getBool(PARAM_MTAS_GROUP, false)) {</span> <span class="nc bnc" id="L494" title="All 2 branches missed."> for (ShardResponse shardResponse : sreq.responses) {</span> <span class="nc" id="L495"> NamedList<Object> response = shardResponse.getSolrResponse()</span> <span class="nc" id="L496"> .getResponse();</span> try { <span class="nc" id="L498"> ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response</span> <span class="nc" id="L499"> .findRecursive("mtas", "group");</span> <span class="nc bnc" id="L500" title="All 2 branches missed."> if (data != null) {</span> <span class="nc" id="L501"> MtasSolrResultUtil.decode(data);</span> } <span class="nc" id="L503"> } catch (ClassCastException e) {</span> <span class="nc" id="L504"> log.debug(e);</span> // shouldn't happen <span class="nc" id="L506"> }</span> <span class="nc" id="L507"> }</span> } <span class="nc" id="L509"> }</span> } <span class="nc" id="L511"> }</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="nc" id="L525"> NamedList<Object> mtasResponse = null;</span> try { <span class="nc" id="L527"> mtasResponse = (NamedList<Object>) rb.rsp.getValues().get("mtas");</span> <span class="nc" id="L528"> } catch (ClassCastException e) {</span> <span class="nc" id="L529"> log.debug(e);</span> <span class="nc" id="L530"> mtasResponse = null;</span> <span class="nc" id="L531"> }</span> <span class="nc bnc" id="L532" title="All 2 branches missed."> if (mtasResponse != null) {</span> ArrayList<Object> mtasResponseGroup; try { <span class="nc" id="L535"> mtasResponseGroup = (ArrayList<Object>) mtasResponse.get("group");</span> <span class="nc bnc" id="L536" title="All 2 branches missed."> if (mtasResponseGroup != null) {</span> <span class="nc" id="L537"> MtasSolrResultUtil.rewrite(mtasResponseGroup, searchComponent);</span> } <span class="nc" id="L539"> } catch (ClassCastException e) {</span> <span class="nc" id="L540"> log.debug(e);</span> <span class="nc" id="L541"> mtasResponse.remove("group");</span> <span class="nc" id="L542"> }</span> } <span class="nc" id="L544"> }</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>