<?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>MtasSolrSearchComponent.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</a> > <span class="el_source">MtasSolrSearchComponent.java</span></div><h1>MtasSolrSearchComponent.java</h1><pre class="source lang-java linenums">package mtas.solr.handler.component; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import mtas.codec.util.CodecComponent.ComponentDocument; import mtas.codec.util.CodecComponent.ComponentFacet; import mtas.codec.util.CodecComponent.ComponentFields; import mtas.codec.util.CodecComponent.ComponentGroup; import mtas.codec.util.CodecComponent.ComponentCollection; import mtas.codec.util.CodecComponent.ComponentKwic; import mtas.codec.util.CodecComponent.ComponentList; import mtas.codec.util.CodecComponent.ComponentPosition; import mtas.codec.util.CodecComponent.ComponentSpan; import mtas.codec.util.CodecComponent.ComponentTermVector; import mtas.codec.util.CodecComponent.ComponentToken; import mtas.codec.util.CodecUtil; import mtas.solr.handler.component.util.MtasSolrResultMerge; import mtas.solr.search.MtasSolrCollectionCache; import mtas.solr.handler.component.util.MtasSolrComponentDocument; import mtas.solr.handler.component.util.MtasSolrComponentFacet; import mtas.solr.handler.component.util.MtasSolrComponentGroup; import mtas.solr.handler.component.util.MtasSolrComponentCollection; import mtas.solr.handler.component.util.MtasSolrComponentKwic; import mtas.solr.handler.component.util.MtasSolrComponentList; import mtas.solr.handler.component.util.MtasSolrComponentPrefix; import mtas.solr.handler.component.util.MtasSolrComponentStats; import mtas.solr.handler.component.util.MtasSolrComponentTermvector; 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.search.DocList; import org.apache.solr.search.DocSet; import org.apache.solr.search.SolrIndexSearcher; /** * The Class MtasSolrSearchComponent. */ <span class="fc" id="L46">public class MtasSolrSearchComponent extends SearchComponent {</span> /** The log. */ <span class="fc" id="L49"> private static Log log = LogFactory.getLog(MtasSolrSearchComponent.class);</span> /** The search component. */ MtasSolrSearchComponent searchComponent; /** The Constant CONFIG_COLLECTION_CACHE_DIRECTORY. */ public static final String CONFIG_COLLECTION_CACHE_DIRECTORY = "collectionCacheDirectory"; /** The Constant CONFIG_COLLECTION_LIFETIME. */ public static final String CONFIG_COLLECTION_LIFETIME = "collectionLifetime"; /** The Constant CONFIG_COLLECTION_MAXIMUM_NUMBER. */ public static final String CONFIG_COLLECTION_MAXIMUM_NUMBER = "collectionMaximumNumber"; /** The Constant CONFIG_COLLECTION_MAXIMUM_OVERFLOW. */ public static final String CONFIG_COLLECTION_MAXIMUM_OVERFLOW = "collectionMaximumOverflow"; /** The Constant PARAM_MTAS. */ public static final String PARAM_MTAS = "mtas"; /** The Constant STAGE_TERMVECTOR_MISSING_TOP. */ <span class="fc" id="L70"> public static final int STAGE_TERMVECTOR_MISSING_TOP = ResponseBuilder.STAGE_EXECUTE_QUERY</span> + 10; /** The Constant STAGE_TERMVECTOR_MISSING_KEY. */ <span class="fc" id="L74"> public static final int STAGE_TERMVECTOR_MISSING_KEY = ResponseBuilder.STAGE_EXECUTE_QUERY</span> + 11; /** The Constant STAGE_TERMVECTOR_FINISH. */ <span class="fc" id="L78"> public static final int STAGE_TERMVECTOR_FINISH = ResponseBuilder.STAGE_EXECUTE_QUERY</span> + 12; /** The Constant STAGE_LIST. */ <span class="fc" id="L82"> public static final int STAGE_LIST = ResponseBuilder.STAGE_EXECUTE_QUERY + 20;</span> /** The Constant STAGE_PREFIX. */ <span class="fc" id="L85"> public static final int STAGE_PREFIX = ResponseBuilder.STAGE_EXECUTE_QUERY</span> + 30; /** The Constant STAGE_STATS. */ <span class="fc" id="L89"> public static final int STAGE_STATS = ResponseBuilder.STAGE_EXECUTE_QUERY</span> + 40; /** The Constant STAGE_FACET. */ <span class="fc" id="L93"> public static final int STAGE_FACET = ResponseBuilder.STAGE_EXECUTE_QUERY</span> + 50; /** The Constant STAGE_GROUP. */ <span class="fc" id="L97"> public static final int STAGE_GROUP = ResponseBuilder.STAGE_EXECUTE_QUERY</span> + 60; /** The Constant STAGE_COLLECTION_INIT. */ <span class="fc" id="L101"> public static final int STAGE_COLLECTION_INIT = ResponseBuilder.STAGE_EXECUTE_QUERY</span> + 70; /** The Constant STAGE_COLLECTION_FINISH. */ <span class="fc" id="L105"> public static final int STAGE_COLLECTION_FINISH = ResponseBuilder.STAGE_EXECUTE_QUERY</span> + 71; /** The Constant STAGE_DOCUMENT. */ <span class="fc" id="L109"> public static final int STAGE_DOCUMENT = ResponseBuilder.STAGE_GET_FIELDS</span> + 10; /** The mtas solr result merge. */ private MtasSolrResultMerge mtasSolrResultMerge; /** The search stats. */ private MtasSolrComponentStats searchStats; /** The search termvector. */ private MtasSolrComponentTermvector searchTermvector; /** The search prefix. */ private MtasSolrComponentPrefix searchPrefix; /** The search facet. */ private MtasSolrComponentFacet searchFacet; /** The search group. */ private MtasSolrComponentGroup searchGroup; /** The search list. */ private MtasSolrComponentList searchList; /** The search kwic. */ private MtasSolrComponentKwic searchKwic; /** The search document. */ private MtasSolrComponentDocument searchDocument; /** The search collection. */ private MtasSolrComponentCollection searchCollection; /** The collection cache. */ <span class="fc" id="L143"> private MtasSolrCollectionCache collectionCache = null;</span> /* * (non-Javadoc) * * @see * org.apache.solr.handler.component.SearchComponent#init(org.apache.solr. * common.util.NamedList) */ @Override public void init(NamedList args) { <span class="fc" id="L154"> super.init(args); </span> // init components <span class="fc" id="L156"> searchDocument = new MtasSolrComponentDocument(this);</span> <span class="fc" id="L157"> searchKwic = new MtasSolrComponentKwic(this);</span> <span class="fc" id="L158"> searchList = new MtasSolrComponentList(this);</span> <span class="fc" id="L159"> searchGroup = new MtasSolrComponentGroup(this);</span> <span class="fc" id="L160"> searchTermvector = new MtasSolrComponentTermvector(this);</span> <span class="fc" id="L161"> searchPrefix = new MtasSolrComponentPrefix(this);</span> <span class="fc" id="L162"> searchStats = new MtasSolrComponentStats(this);</span> <span class="fc" id="L163"> searchFacet = new MtasSolrComponentFacet(this);</span> <span class="fc" id="L164"> searchCollection = new MtasSolrComponentCollection(this);</span> // init collection <span class="fc" id="L166"> String collectionCacheDirectory = null;</span> <span class="fc" id="L167"> Long collectionLifetime = null;</span> <span class="fc" id="L168"> Integer collectionMaximumNumber = null;</span> <span class="fc" id="L169"> Integer collectionMaximumOverflow = null;</span> <span class="pc bpc" id="L170" title="1 of 2 branches missed."> if (args.get(CONFIG_COLLECTION_CACHE_DIRECTORY) != null</span> <span class="pc bpc" id="L171" title="1 of 2 branches missed."> && args.get(CONFIG_COLLECTION_CACHE_DIRECTORY) instanceof String) {</span> <span class="fc" id="L172"> collectionCacheDirectory = (String) args</span> <span class="fc" id="L173"> .get(CONFIG_COLLECTION_CACHE_DIRECTORY);</span> } <span class="pc bpc" id="L175" title="1 of 2 branches missed."> if (args.get(CONFIG_COLLECTION_LIFETIME) != null</span> <span class="pc bpc" id="L176" title="1 of 2 branches missed."> && args.get(CONFIG_COLLECTION_LIFETIME) instanceof Long) {</span> <span class="fc" id="L177"> collectionLifetime = (Long) args.get(CONFIG_COLLECTION_LIFETIME);</span> } <span class="pc bpc" id="L179" title="1 of 2 branches missed."> if (args.get(CONFIG_COLLECTION_MAXIMUM_NUMBER) != null</span> <span class="pc bpc" id="L180" title="1 of 2 branches missed."> && args.get(CONFIG_COLLECTION_MAXIMUM_NUMBER) instanceof Integer) {</span> <span class="fc" id="L181"> collectionMaximumNumber = (Integer) args</span> <span class="fc" id="L182"> .get(CONFIG_COLLECTION_MAXIMUM_NUMBER);</span> } <span class="pc bpc" id="L184" title="1 of 2 branches missed."> if (args.get(CONFIG_COLLECTION_MAXIMUM_OVERFLOW) != null</span> <span class="pc bpc" id="L185" title="1 of 2 branches missed."> && args.get(CONFIG_COLLECTION_MAXIMUM_OVERFLOW) instanceof Integer) {</span> <span class="fc" id="L186"> collectionMaximumNumber = (Integer) args</span> <span class="fc" id="L187"> .get(CONFIG_COLLECTION_MAXIMUM_OVERFLOW);</span> } <span class="fc" id="L189"> collectionCache = new MtasSolrCollectionCache(collectionCacheDirectory,</span> collectionLifetime, collectionMaximumNumber, collectionMaximumOverflow); <span class="fc" id="L191"> }</span> /* * (non-Javadoc) * * @see org.apache.solr.handler.component.SearchComponent#getDescription() */ @Override public String getDescription() { <span class="nc" id="L200"> return "Mtas";</span> } /** * Gets the collection cache. * * @return the collection cache */ public MtasSolrCollectionCache getCollectionCache() { <span class="fc" id="L209"> return collectionCache;</span> } /* * (non-Javadoc) * * @see * org.apache.solr.handler.component.SearchComponent#prepare(org.apache.solr. * handler.component.ResponseBuilder) */ @Override public void prepare(ResponseBuilder rb) throws IOException { //System.out //.println(System.nanoTime() + " - " + Thread.currentThread().getId() //+ " - " + rb.req.getParams().getBool("isShard", false) + " PREPARE " //+ rb.stage + " " + rb.req.getParamString()); <span class="fc bfc" id="L225" title="All 2 branches covered."> if (rb.req.getParams().getBool(PARAM_MTAS, false)) {</span> <span class="fc" id="L226"> mtasSolrResultMerge = new MtasSolrResultMerge();</span> <span class="fc" id="L227"> ComponentFields mtasFields = new ComponentFields();</span> // get settings document <span class="fc" id="L229"> if (rb.req.getParams()</span> <span class="pc bpc" id="L230" title="1 of 2 branches missed."> .getBool(MtasSolrComponentDocument.PARAM_MTAS_DOCUMENT, false)) {</span> <span class="nc" id="L231"> searchDocument.prepare(rb, mtasFields);</span> } // get settings kwic <span class="pc bpc" id="L234" title="1 of 2 branches missed."> if (rb.req.getParams().getBool(MtasSolrComponentKwic.PARAM_MTAS_KWIC,</span> false)) { <span class="nc" id="L236"> searchKwic.prepare(rb, mtasFields);</span> } // get settings list <span class="pc bpc" id="L239" title="1 of 2 branches missed."> if (rb.req.getParams().getBool(MtasSolrComponentList.PARAM_MTAS_LIST,</span> false)) { <span class="nc" id="L241"> searchList.prepare(rb, mtasFields);</span> } // get settings group <span class="fc bfc" id="L244" title="All 2 branches covered."> if (rb.req.getParams().getBool(MtasSolrComponentGroup.PARAM_MTAS_GROUP,</span> false)) { <span class="fc" id="L246"> searchGroup.prepare(rb, mtasFields);</span> } // get settings termvector <span class="fc" id="L249"> if (rb.req.getParams()</span> <span class="fc bfc" id="L250" title="All 2 branches covered."> .getBool(MtasSolrComponentTermvector.PARAM_MTAS_TERMVECTOR, false)) {</span> <span class="fc" id="L251"> searchTermvector.prepare(rb, mtasFields);</span> } // get settings prefix <span class="fc bfc" id="L254" title="All 2 branches covered."> if (rb.req.getParams().getBool(MtasSolrComponentPrefix.PARAM_MTAS_PREFIX,</span> false)) { <span class="fc" id="L256"> searchPrefix.prepare(rb, mtasFields);</span> } // get settings stats <span class="fc bfc" id="L259" title="All 2 branches covered."> if (rb.req.getParams().getBool(MtasSolrComponentStats.PARAM_MTAS_STATS,</span> false)) { <span class="fc" id="L261"> searchStats.prepare(rb, mtasFields);</span> } // get settings facet <span class="pc bpc" id="L264" title="1 of 2 branches missed."> if (rb.req.getParams().getBool(MtasSolrComponentFacet.PARAM_MTAS_FACET,</span> false)) { <span class="nc" id="L266"> searchFacet.prepare(rb, mtasFields);</span> } // get settings collection <span class="fc" id="L269"> if (rb.req.getParams()</span> <span class="fc bfc" id="L270" title="All 2 branches covered."> .getBool(MtasSolrComponentCollection.PARAM_MTAS_COLLECTION, false)) {</span> <span class="fc" id="L271"> searchCollection.prepare(rb, mtasFields);</span> } <span class="fc" id="L273"> rb.req.getContext().put(ComponentFields.class, mtasFields);</span> } <span class="fc" id="L275"> }</span> /* * (non-Javadoc) * * @see * org.apache.solr.handler.component.SearchComponent#process(org.apache.solr. * handler.component.ResponseBuilder) */ @Override public void process(ResponseBuilder rb) throws IOException { // System.out // .println(System.nanoTime() + " - " + Thread.currentThread().getId() // + " - " + rb.req.getParams().getBool("isShard", false) + " PROCESS " // + rb.stage + " " + rb.req.getParamString()); <span class="fc" id="L290"> ComponentFields mtasFields = getMtasFields(rb);</span> <span class="fc bfc" id="L291" title="All 2 branches covered."> if (mtasFields != null) {</span> <span class="fc" id="L292"> DocSet docSet = rb.getResults().docSet;</span> <span class="fc" id="L293"> DocList docList = rb.getResults().docList;</span> <span class="pc bpc" id="L294" title="4 of 18 branches missed."> if (mtasFields.doStats || mtasFields.doDocument || mtasFields.doKwic</span> || mtasFields.doList || mtasFields.doGroup || mtasFields.doFacet || mtasFields.doCollection || mtasFields.doTermVector || mtasFields.doPrefix) { <span class="fc" id="L298"> SolrIndexSearcher searcher = rb.req.getSearcher();</span> <span class="fc" id="L299"> ArrayList<Integer> docSetList = null;</span> <span class="fc" id="L300"> ArrayList<Integer> docListList = null;</span> <span class="fc bfc" id="L301" title="All 2 branches covered."> if (docSet != null) {</span> <span class="fc" id="L302"> docSetList = new ArrayList<>();</span> <span class="fc" id="L303"> Iterator<Integer> docSetIterator = docSet.iterator();</span> <span class="fc bfc" id="L304" title="All 2 branches covered."> while (docSetIterator.hasNext()) {</span> <span class="fc" id="L305"> docSetList.add(docSetIterator.next());</span> } <span class="fc" id="L307"> Collections.sort(docSetList);</span> } <span class="pc bpc" id="L309" title="1 of 2 branches missed."> if (docList != null) {</span> <span class="fc" id="L310"> docListList = new ArrayList<>();</span> <span class="fc" id="L311"> Iterator<Integer> docListIterator = docList.iterator();</span> <span class="fc bfc" id="L312" title="All 2 branches covered."> while (docListIterator.hasNext()) {</span> <span class="fc" id="L313"> docListList.add(docListIterator.next());</span> } <span class="fc" id="L315"> Collections.sort(docListList);</span> } <span class="fc bfc" id="L317" title="All 2 branches covered."> for (String field : mtasFields.list.keySet()) {</span> try { <span class="fc" id="L319"> CodecUtil.collectField(field, searcher, searcher.getRawReader(),</span> <span class="fc" id="L320"> docListList, docSetList, mtasFields.list.get(field));</span> <span class="nc" id="L321"> } catch (IllegalAccessException | IllegalArgumentException</span> | InvocationTargetException e) { <span class="nc" id="L323"> log.error(e);</span> <span class="nc" id="L324"> throw new IOException(e);</span> <span class="fc" id="L325"> }</span> <span class="fc" id="L326"> }</span> <span class="fc bfc" id="L327" title="All 2 branches covered."> for (ComponentCollection collection : mtasFields.collection) {</span> <span class="fc" id="L328"> CodecUtil.collectCollection(searcher.getRawReader(), docSetList,</span> collection); <span class="fc" id="L330"> }</span> <span class="fc" id="L331"> NamedList<Object> mtasResponse = new SimpleOrderedMap<>();</span> <span class="pc bpc" id="L332" title="1 of 2 branches missed."> if (mtasFields.doDocument) {</span> <span class="nc" id="L333"> ArrayList<NamedList<?>> mtasDocumentResponses = new ArrayList<>();</span> <span class="nc bnc" id="L334" title="All 2 branches missed."> for (String field : mtasFields.list.keySet()) {</span> for (ComponentDocument document : mtasFields.list <span class="nc bnc" id="L336" title="All 2 branches missed."> .get(field).documentList) {</span> <span class="nc" id="L337"> mtasDocumentResponses.add(searchDocument.create(document, false));</span> <span class="nc" id="L338"> }</span> <span class="nc" id="L339"> }</span> // add to response <span class="nc" id="L341"> mtasResponse.add("document", mtasDocumentResponses);</span> } <span class="pc bpc" id="L343" title="1 of 2 branches missed."> if (mtasFields.doKwic) {</span> <span class="nc" id="L344"> ArrayList<NamedList<?>> mtasKwicResponses = new ArrayList<>();</span> <span class="nc bnc" id="L345" title="All 2 branches missed."> for (String field : mtasFields.list.keySet()) {</span> <span class="nc bnc" id="L346" title="All 2 branches missed."> for (ComponentKwic kwic : mtasFields.list.get(field).kwicList) {</span> <span class="nc" id="L347"> mtasKwicResponses.add(searchKwic.create(kwic, false));</span> <span class="nc" id="L348"> }</span> <span class="nc" id="L349"> }</span> // add to response <span class="nc" id="L351"> mtasResponse.add("kwic", mtasKwicResponses);</span> } <span class="pc bpc" id="L353" title="1 of 2 branches missed."> if (mtasFields.doFacet) {</span> <span class="nc" id="L354"> ArrayList<NamedList<?>> mtasFacetResponses = new ArrayList<>();</span> <span class="nc bnc" id="L355" title="All 2 branches missed."> for (String field : mtasFields.list.keySet()) {</span> <span class="nc bnc" id="L356" title="All 2 branches missed."> for (ComponentFacet facet : mtasFields.list.get(field).facetList) {</span> <span class="nc bnc" id="L357" title="All 2 branches missed."> if (rb.req.getParams().getBool("isShard", false)) {</span> <span class="nc" id="L358"> mtasFacetResponses.add(searchFacet.create(facet, true));</span> } else { <span class="nc" id="L360"> mtasFacetResponses.add(searchFacet.create(facet, false));</span> } <span class="nc" id="L362"> }</span> <span class="nc" id="L363"> }</span> // add to response <span class="nc" id="L365"> mtasResponse.add("facet", mtasFacetResponses);</span> } <span class="fc bfc" id="L367" title="All 2 branches covered."> if (mtasFields.doCollection) {</span> <span class="fc" id="L368"> ArrayList<NamedList<?>> mtasCollectionResponses = new ArrayList<>();</span> <span class="fc bfc" id="L369" title="All 2 branches covered."> for (ComponentCollection collection : mtasFields.collection) {</span> <span class="fc bfc" id="L370" title="All 2 branches covered."> if (rb.req.getParams().getBool("isShard", false)) {</span> <span class="fc" id="L371"> mtasCollectionResponses</span> <span class="fc" id="L372"> .add(searchCollection.create(collection, true));</span> } else { <span class="fc" id="L374"> mtasCollectionResponses</span> <span class="fc" id="L375"> .add(searchCollection.create(collection, false));</span> } <span class="fc" id="L377"> }</span> // add to response <span class="fc" id="L379"> mtasResponse.add("collection", mtasCollectionResponses);</span> } <span class="pc bpc" id="L381" title="1 of 2 branches missed."> if (mtasFields.doList) {</span> <span class="nc" id="L382"> ArrayList<NamedList<?>> mtasListResponses = new ArrayList<>();</span> <span class="nc bnc" id="L383" title="All 2 branches missed."> for (String field : mtasFields.list.keySet()) {</span> <span class="nc bnc" id="L384" title="All 2 branches missed."> for (ComponentList list : mtasFields.list.get(field).listList) {</span> <span class="nc" id="L385"> mtasListResponses.add(searchList.create(list, false));</span> <span class="nc" id="L386"> }</span> <span class="nc" id="L387"> }</span> // add to response <span class="nc" id="L389"> mtasResponse.add("list", mtasListResponses);</span> } <span class="fc bfc" id="L391" title="All 2 branches covered."> if (mtasFields.doGroup) {</span> <span class="fc" id="L392"> ArrayList<NamedList<?>> mtasGroupResponses = new ArrayList<>();</span> <span class="fc bfc" id="L393" title="All 2 branches covered."> for (String field : mtasFields.list.keySet()) {</span> <span class="fc bfc" id="L394" title="All 2 branches covered."> for (ComponentGroup group : mtasFields.list.get(field).groupList) {</span> <span class="pc bpc" id="L395" title="1 of 2 branches missed."> if (rb.req.getParams().getBool("isShard", false)) {</span> <span class="nc" id="L396"> mtasGroupResponses.add(searchGroup.create(group, true));</span> } else { <span class="fc" id="L398"> mtasGroupResponses.add(searchGroup.create(group, false));</span> } <span class="fc" id="L400"> }</span> <span class="fc" id="L401"> }</span> // add to response <span class="fc" id="L403"> mtasResponse.add("group", mtasGroupResponses);</span> } <span class="fc bfc" id="L405" title="All 2 branches covered."> if (mtasFields.doTermVector) {</span> <span class="fc" id="L406"> ArrayList<NamedList<?>> mtasTermVectorResponses = new ArrayList<>();</span> <span class="fc bfc" id="L407" title="All 2 branches covered."> for (String field : mtasFields.list.keySet()) {</span> for (ComponentTermVector termVector : mtasFields.list <span class="fc bfc" id="L409" title="All 2 branches covered."> .get(field).termVectorList) {</span> <span class="fc bfc" id="L410" title="All 2 branches covered."> if (rb.req.getParams().getBool("isShard", false)) {</span> <span class="fc" id="L411"> mtasTermVectorResponses</span> <span class="fc" id="L412"> .add(searchTermvector.create(termVector, true));</span> } else { <span class="fc" id="L414"> mtasTermVectorResponses</span> <span class="fc" id="L415"> .add(searchTermvector.create(termVector, false));</span> } <span class="fc" id="L417"> }</span> <span class="fc" id="L418"> }</span> // add to response <span class="fc" id="L420"> mtasResponse.add("termvector", mtasTermVectorResponses);</span> } <span class="fc bfc" id="L422" title="All 2 branches covered."> if (mtasFields.doPrefix) {</span> <span class="fc" id="L423"> ArrayList<NamedList<?>> mtasPrefixResponses = new ArrayList<>();</span> <span class="fc bfc" id="L424" title="All 2 branches covered."> for (String field : mtasFields.list.keySet()) {</span> <span class="pc bpc" id="L425" title="1 of 2 branches missed."> if (mtasFields.list.get(field).prefix != null) {</span> <span class="fc bfc" id="L426" title="All 2 branches covered."> if (rb.req.getParams().getBool("isShard", false)) {</span> <span class="fc" id="L427"> mtasPrefixResponses.add(searchPrefix</span> <span class="fc" id="L428"> .create(mtasFields.list.get(field).prefix, true));</span> } else { <span class="fc" id="L430"> mtasPrefixResponses.add(searchPrefix</span> <span class="fc" id="L431"> .create(mtasFields.list.get(field).prefix, false));</span> } } <span class="fc" id="L434"> }</span> <span class="fc" id="L435"> mtasResponse.add("prefix", mtasPrefixResponses);</span> } <span class="fc bfc" id="L437" title="All 2 branches covered."> if (mtasFields.doStats) {</span> <span class="fc" id="L438"> NamedList<Object> mtasStatsResponse = new SimpleOrderedMap<>();</span> <span class="pc bpc" id="L439" title="1 of 6 branches missed."> if (mtasFields.doStatsPositions || mtasFields.doStatsTokens</span> || mtasFields.doStatsSpans) { <span class="fc bfc" id="L441" title="All 2 branches covered."> if (mtasFields.doStatsTokens) {</span> <span class="fc" id="L442"> ArrayList<Object> mtasStatsTokensResponses = new ArrayList<>();</span> <span class="fc bfc" id="L443" title="All 2 branches covered."> for (String field : mtasFields.list.keySet()) {</span> for (ComponentToken token : mtasFields.list <span class="fc bfc" id="L445" title="All 2 branches covered."> .get(field).statsTokenList) {</span> <span class="fc bfc" id="L446" title="All 2 branches covered."> if (rb.req.getParams().getBool("isShard", false)) {</span> <span class="fc" id="L447"> mtasStatsTokensResponses</span> <span class="fc" id="L448"> .add(searchStats.create(token, true));</span> } else { <span class="fc" id="L450"> mtasStatsTokensResponses</span> <span class="fc" id="L451"> .add(searchStats.create(token, false));</span> } <span class="fc" id="L453"> }</span> <span class="fc" id="L454"> }</span> <span class="fc" id="L455"> mtasStatsResponse.add("tokens", mtasStatsTokensResponses);</span> } <span class="fc bfc" id="L457" title="All 2 branches covered."> if (mtasFields.doStatsPositions) {</span> <span class="fc" id="L458"> ArrayList<Object> mtasStatsPositionsResponses = new ArrayList<>();</span> <span class="fc bfc" id="L459" title="All 2 branches covered."> for (String field : mtasFields.list.keySet()) {</span> for (ComponentPosition position : mtasFields.list <span class="fc bfc" id="L461" title="All 2 branches covered."> .get(field).statsPositionList) {</span> <span class="fc bfc" id="L462" title="All 2 branches covered."> if (rb.req.getParams().getBool("isShard", false)) {</span> <span class="fc" id="L463"> mtasStatsPositionsResponses</span> <span class="fc" id="L464"> .add(searchStats.create(position, true));</span> } else { <span class="fc" id="L466"> mtasStatsPositionsResponses</span> <span class="fc" id="L467"> .add(searchStats.create(position, false));</span> } <span class="fc" id="L469"> }</span> <span class="fc" id="L470"> }</span> <span class="fc" id="L471"> mtasStatsResponse.add("positions", mtasStatsPositionsResponses);</span> } <span class="fc bfc" id="L473" title="All 2 branches covered."> if (mtasFields.doStatsSpans) {</span> <span class="fc" id="L474"> ArrayList<Object> mtasStatsSpansResponses = new ArrayList<>();</span> <span class="fc bfc" id="L475" title="All 2 branches covered."> for (String field : mtasFields.list.keySet()) {</span> for (ComponentSpan span : mtasFields.list <span class="fc bfc" id="L477" title="All 2 branches covered."> .get(field).statsSpanList) {</span> <span class="fc bfc" id="L478" title="All 2 branches covered."> if (rb.req.getParams().getBool("isShard", false)) {</span> <span class="fc" id="L479"> mtasStatsSpansResponses.add(searchStats.create(span, true));</span> } else { <span class="fc" id="L481"> mtasStatsSpansResponses</span> <span class="fc" id="L482"> .add(searchStats.create(span, false));</span> } <span class="fc" id="L484"> }</span> <span class="fc" id="L485"> }</span> <span class="fc" id="L486"> mtasStatsResponse.add("spans", mtasStatsSpansResponses);</span> } // add to response <span class="fc" id="L489"> mtasResponse.add("stats", mtasStatsResponse);</span> } } // add to response <span class="fc" id="L493"> rb.rsp.add("mtas", mtasResponse);</span> } } <span class="fc" id="L496"> }</span> /* * (non-Javadoc) * * @see * org.apache.solr.handler.component.SearchComponent#modifyRequest(org.apache. * solr.handler.component.ResponseBuilder, * org.apache.solr.handler.component.SearchComponent, * org.apache.solr.handler.component.ShardRequest) */ @Override public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) { // System.out.println(System.nanoTime() + " - " + // Thread.currentThread().getId() + " - " // + rb.req.getParams().getBool("isShard", false) + " MODIFY REQUEST " // + rb.stage + " " + rb.req.getParamString()); <span class="fc bfc" id="L514" title="All 2 branches covered."> if (sreq.params.getBool(PARAM_MTAS, false)) {</span> <span class="fc bfc" id="L515" title="All 2 branches covered."> if (sreq.params.getBool(MtasSolrComponentStats.PARAM_MTAS_STATS, false)) {</span> <span class="fc" id="L516"> searchStats.modifyRequest(rb, who, sreq);</span> } <span class="fc bfc" id="L518" title="All 2 branches covered."> if (sreq.params.getBool(MtasSolrComponentTermvector.PARAM_MTAS_TERMVECTOR,</span> false)) { <span class="fc" id="L520"> searchTermvector.modifyRequest(rb, who, sreq);</span> } <span class="fc bfc" id="L522" title="All 2 branches covered."> if (sreq.params.getBool(MtasSolrComponentPrefix.PARAM_MTAS_PREFIX,</span> false)) { <span class="fc" id="L524"> searchPrefix.modifyRequest(rb, who, sreq);</span> } <span class="pc bpc" id="L526" title="1 of 2 branches missed."> if (sreq.params.getBool(MtasSolrComponentFacet.PARAM_MTAS_FACET, false)) {</span> <span class="nc" id="L527"> searchFacet.modifyRequest(rb, who, sreq);</span> } <span class="fc bfc" id="L529" title="All 2 branches covered."> if (sreq.params.getBool(MtasSolrComponentCollection.PARAM_MTAS_COLLECTION,</span> false)) { <span class="fc" id="L531"> searchCollection.modifyRequest(rb, who, sreq);</span> } <span class="pc bpc" id="L533" title="1 of 2 branches missed."> if (sreq.params.getBool(MtasSolrComponentGroup.PARAM_MTAS_GROUP, false)) {</span> <span class="nc" id="L534"> searchGroup.modifyRequest(rb, who, sreq);</span> } <span class="pc bpc" id="L536" title="1 of 2 branches missed."> if (sreq.params.getBool(MtasSolrComponentList.PARAM_MTAS_LIST, false)) {</span> <span class="nc" id="L537"> searchList.modifyRequest(rb, who, sreq);</span> } <span class="pc bpc" id="L539" title="1 of 2 branches missed."> if (sreq.params.getBool(MtasSolrComponentDocument.PARAM_MTAS_DOCUMENT,</span> false)) { <span class="nc" id="L541"> searchDocument.modifyRequest(rb, who, sreq);</span> } <span class="pc bpc" id="L543" title="1 of 2 branches missed."> if (sreq.params.getBool(MtasSolrComponentKwic.PARAM_MTAS_KWIC, false)) {</span> <span class="nc" id="L544"> searchKwic.modifyRequest(rb, who, sreq);</span> } } <span class="fc" id="L547"> }</span> /* * (non-Javadoc) * * @see org.apache.solr.handler.component.SearchComponent#handleResponses(org. * apache.solr.handler.component.ResponseBuilder, * org.apache.solr.handler.component.ShardRequest) */ @Override public void handleResponses(ResponseBuilder rb, ShardRequest sreq) { // System.out // .println(System.nanoTime() + " - " + Thread.currentThread().getId() // + " - " + rb.req.getParams().getBool("isShard", false) // + " HANDLERESPONSES " + rb.stage + " " + rb.req.getParamString()); <span class="fc" id="L562"> }</span> /* * (non-Javadoc) * * @see * org.apache.solr.handler.component.SearchComponent#distributedProcess(org. * apache.solr.handler.component.ResponseBuilder) */ @Override public void finishStage(ResponseBuilder rb) { // System.out // .println(System.nanoTime() + " - " + Thread.currentThread().getId() // + " - " + rb.req.getParams().getBool("isShard", false) // + " FINISHRESPONSES " + rb.stage + " " + rb.req.getParamString()); <span class="fc bfc" id="L577" title="All 2 branches covered."> if (rb.req.getParams().getBool(PARAM_MTAS, false)) {</span> <span class="fc bfc" id="L578" title="All 2 branches covered."> if (rb.req.getParams().getBool(MtasSolrComponentStats.PARAM_MTAS_STATS,</span> false)) { <span class="fc" id="L580"> searchStats.finishStage(rb);</span> } <span class="fc" id="L582"> if (rb.req.getParams()</span> <span class="fc bfc" id="L583" title="All 2 branches covered."> .getBool(MtasSolrComponentTermvector.PARAM_MTAS_TERMVECTOR, false)) {</span> <span class="fc" id="L584"> searchTermvector.finishStage(rb);</span> } <span class="fc bfc" id="L586" title="All 2 branches covered."> if (rb.req.getParams().getBool(MtasSolrComponentPrefix.PARAM_MTAS_PREFIX,</span> false)) { <span class="fc" id="L588"> searchPrefix.finishStage(rb);</span> } <span class="pc bpc" id="L590" title="1 of 2 branches missed."> if (rb.req.getParams().getBool(MtasSolrComponentFacet.PARAM_MTAS_FACET,</span> false)) { <span class="nc" id="L592"> searchFacet.finishStage(rb);</span> } <span class="fc" id="L594"> if (rb.req.getParams()</span> <span class="fc bfc" id="L595" title="All 2 branches covered."> .getBool(MtasSolrComponentCollection.PARAM_MTAS_COLLECTION, false)) {</span> <span class="fc" id="L596"> searchCollection.finishStage(rb);</span> } <span class="pc bpc" id="L598" title="1 of 2 branches missed."> if (rb.req.getParams().getBool(MtasSolrComponentGroup.PARAM_MTAS_GROUP,</span> false)) { <span class="nc" id="L600"> searchGroup.finishStage(rb);</span> } <span class="pc bpc" id="L602" title="1 of 2 branches missed."> if (rb.req.getParams().getBool(MtasSolrComponentList.PARAM_MTAS_LIST,</span> false)) { <span class="nc" id="L604"> searchList.finishStage(rb);</span> } <span class="fc" id="L606"> if (rb.req.getParams()</span> <span class="pc bpc" id="L607" title="1 of 2 branches missed."> .getBool(MtasSolrComponentDocument.PARAM_MTAS_DOCUMENT, false)) {</span> <span class="nc" id="L608"> searchDocument.finishStage(rb);</span> } <span class="pc bpc" id="L610" title="1 of 2 branches missed."> if (rb.req.getParams().getBool(MtasSolrComponentKwic.PARAM_MTAS_KWIC,</span> false)) { <span class="nc" id="L612"> searchKwic.finishStage(rb);</span> } <span class="fc" id="L614"> mtasSolrResultMerge.merge(rb);</span> } <span class="fc" id="L616"> }</span> /* * (non-Javadoc) * * @see * org.apache.solr.handler.component.SearchComponent#distributedProcess(org. * apache.solr.handler.component.ResponseBuilder) */ @Override public int distributedProcess(ResponseBuilder rb) throws IOException { // System.out.println(System.nanoTime() + " - " + // Thread.currentThread().getId() + " - " // + rb.req.getParams().getBool("isShard", false) + " DISTIRBUTEDPROCESS " // + rb.stage + " " + rb.req.getParamString()); // distributed processes <span class="fc bfc" id="L632" title="All 2 branches covered."> if (rb.req.getParams().getBool(PARAM_MTAS, false)) {</span> <span class="fc bfc" id="L633" title="All 6 branches covered."> if (rb.stage == STAGE_TERMVECTOR_MISSING_TOP</span> || rb.stage == STAGE_TERMVECTOR_MISSING_KEY || rb.stage == STAGE_TERMVECTOR_FINISH) { <span class="fc" id="L636"> ComponentFields mtasFields = getMtasFields(rb);</span> <span class="fc" id="L637"> searchTermvector.distributedProcess(rb, mtasFields);</span> <span class="pc bpc" id="L638" title="1 of 2 branches missed."> } else if (rb.stage == STAGE_LIST) {</span> <span class="nc" id="L639"> ComponentFields mtasFields = getMtasFields(rb);</span> <span class="nc" id="L640"> searchList.distributedProcess(rb, mtasFields);</span> <span class="pc bfc" id="L641" title="All 2 branches covered."> } else if (rb.stage == STAGE_PREFIX) {</span> <span class="fc" id="L642"> ComponentFields mtasFields = getMtasFields(rb);</span> <span class="fc" id="L643"> searchPrefix.distributedProcess(rb, mtasFields);</span> <span class="fc bfc" id="L644" title="All 2 branches covered."> } else if (rb.stage == STAGE_STATS) {</span> <span class="fc" id="L645"> ComponentFields mtasFields = getMtasFields(rb);</span> <span class="fc" id="L646"> searchStats.distributedProcess(rb, mtasFields);</span> <span class="pc bpc" id="L647" title="1 of 2 branches missed."> } else if (rb.stage == STAGE_FACET) {</span> <span class="nc" id="L648"> ComponentFields mtasFields = getMtasFields(rb);</span> <span class="nc" id="L649"> searchFacet.distributedProcess(rb, mtasFields);</span> <span class="pc bfc" id="L650" title="All 4 branches covered."> } else if (rb.stage == STAGE_COLLECTION_INIT</span> || rb.stage == STAGE_COLLECTION_FINISH) { <span class="fc" id="L652"> ComponentFields mtasFields = getMtasFields(rb);</span> <span class="fc" id="L653"> searchCollection.distributedProcess(rb, mtasFields);</span> <span class="pc bpc" id="L654" title="1 of 2 branches missed."> } else if (rb.stage == STAGE_GROUP) {</span> <span class="nc" id="L655"> ComponentFields mtasFields = getMtasFields(rb);</span> <span class="nc" id="L656"> searchGroup.distributedProcess(rb, mtasFields);</span> <span class="pc bpc" id="L657" title="1 of 2 branches missed."> } else if (rb.stage == STAGE_DOCUMENT) {</span> <span class="nc" id="L658"> ComponentFields mtasFields = getMtasFields(rb);</span> <span class="nc" id="L659"> searchDocument.distributedProcess(rb, mtasFields);</span> } // compute new stage and return if not finished <span class="fc bfc" id="L662" title="All 4 branches covered."> if (rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY</span> && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) { <span class="fc bfc" id="L664" title="All 2 branches covered."> if (rb.stage < STAGE_TERMVECTOR_MISSING_TOP</span> <span class="fc bfc" id="L665" title="All 2 branches covered."> && rb.req.getParams().getBool(</span> MtasSolrComponentTermvector.PARAM_MTAS_TERMVECTOR, false)) { <span class="fc" id="L667"> return STAGE_TERMVECTOR_MISSING_TOP;</span> <span class="fc bfc" id="L668" title="All 2 branches covered."> } else if (rb.stage < STAGE_TERMVECTOR_MISSING_KEY</span> <span class="fc bfc" id="L669" title="All 2 branches covered."> && rb.req.getParams().getBool(</span> MtasSolrComponentTermvector.PARAM_MTAS_TERMVECTOR, false)) { <span class="fc" id="L671"> return STAGE_TERMVECTOR_MISSING_KEY;</span> <span class="fc bfc" id="L672" title="All 2 branches covered."> } else if (rb.stage < STAGE_TERMVECTOR_FINISH</span> <span class="fc bfc" id="L673" title="All 2 branches covered."> && rb.req.getParams().getBool(</span> MtasSolrComponentTermvector.PARAM_MTAS_TERMVECTOR, false)) { <span class="fc" id="L675"> return STAGE_TERMVECTOR_FINISH;</span> <span class="fc bfc" id="L676" title="All 2 branches covered."> } else if (rb.stage < STAGE_LIST && rb.req.getParams()</span> <span class="pc bpc" id="L677" title="1 of 2 branches missed."> .getBool(MtasSolrComponentList.PARAM_MTAS_LIST, false)) {</span> <span class="nc" id="L678"> return STAGE_LIST;</span> <span class="fc bfc" id="L679" title="All 2 branches covered."> } else if (rb.stage < STAGE_PREFIX && rb.req.getParams()</span> <span class="fc bfc" id="L680" title="All 2 branches covered."> .getBool(MtasSolrComponentPrefix.PARAM_MTAS_PREFIX, false)) {</span> <span class="fc" id="L681"> return STAGE_PREFIX;</span> <span class="fc bfc" id="L682" title="All 2 branches covered."> } else if (rb.stage < STAGE_STATS && rb.req.getParams()</span> <span class="fc bfc" id="L683" title="All 2 branches covered."> .getBool(MtasSolrComponentStats.PARAM_MTAS_STATS, false)) {</span> <span class="fc" id="L684"> return STAGE_STATS;</span> <span class="fc bfc" id="L685" title="All 2 branches covered."> } else if (rb.stage < STAGE_FACET && rb.req.getParams()</span> <span class="pc bpc" id="L686" title="1 of 2 branches missed."> .getBool(MtasSolrComponentFacet.PARAM_MTAS_FACET, false)) {</span> <span class="nc" id="L687"> return STAGE_FACET;</span> <span class="fc bfc" id="L688" title="All 2 branches covered."> } else if (rb.stage < STAGE_GROUP && rb.req.getParams()</span> <span class="pc bpc" id="L689" title="1 of 2 branches missed."> .getBool(MtasSolrComponentGroup.PARAM_MTAS_GROUP, false)) {</span> <span class="nc" id="L690"> return STAGE_GROUP;</span> <span class="fc bfc" id="L691" title="All 2 branches covered."> } else if (rb.stage < STAGE_COLLECTION_INIT</span> <span class="fc bfc" id="L692" title="All 2 branches covered."> && rb.req.getParams().getBool(</span> MtasSolrComponentCollection.PARAM_MTAS_COLLECTION, false)) { <span class="fc" id="L694"> return STAGE_COLLECTION_INIT;</span> <span class="fc bfc" id="L695" title="All 2 branches covered."> } else if (rb.stage < STAGE_COLLECTION_FINISH</span> <span class="fc bfc" id="L696" title="All 2 branches covered."> && rb.req.getParams().getBool(</span> MtasSolrComponentCollection.PARAM_MTAS_COLLECTION, false)) { <span class="fc" id="L698"> return STAGE_COLLECTION_FINISH;</span> } <span class="pc bpc" id="L700" title="1 of 4 branches missed."> } else if (rb.stage >= ResponseBuilder.STAGE_GET_FIELDS</span> && rb.stage < ResponseBuilder.STAGE_DONE) { <span class="pc bpc" id="L702" title="1 of 2 branches missed."> if (rb.stage < STAGE_DOCUMENT && rb.req.getParams()</span> <span class="pc bpc" id="L703" title="1 of 2 branches missed."> .getBool(MtasSolrComponentDocument.PARAM_MTAS_DOCUMENT, false)) {</span> <span class="nc" id="L704"> return STAGE_DOCUMENT;</span> } } } <span class="fc" id="L708"> return ResponseBuilder.STAGE_DONE;</span> } /** * Gets the mtas fields. * * @param rb the rb * @return the mtas fields */ private ComponentFields getMtasFields(ResponseBuilder rb) { <span class="fc" id="L719"> return (ComponentFields) rb.req.getContext().get(ComponentFields.class);</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>