<?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>MtasUpdateRequestProcessorFactory.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.update.processor</a> > <span class="el_source">MtasUpdateRequestProcessorFactory.java</span></div><h1>MtasUpdateRequestProcessorFactory.java</h1><pre class="source lang-java linenums">package mtas.solr.update.processor; import java.io.IOException; import java.io.Reader; import java.io.StringReader; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; import org.apache.lucene.analysis.tokenattributes.FlagsAttribute; import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; import org.apache.lucene.analysis.util.CharFilterFactory; import org.apache.lucene.analysis.util.ResourceLoader; import org.apache.lucene.util.BytesRef; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.SolrInputField; import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.SimpleOrderedMap; import org.apache.solr.core.SolrResourceLoader; import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.response.SolrQueryResponse; import org.apache.solr.schema.FieldType; import org.apache.solr.schema.SchemaField; import org.apache.solr.update.AddUpdateCommand; import org.apache.solr.update.processor.UpdateRequestProcessor; import org.apache.solr.update.processor.UpdateRequestProcessorFactory; import mtas.analysis.MtasTokenizer; import mtas.analysis.util.MtasCharFilterFactory; import mtas.analysis.util.MtasTokenizerFactory; import mtas.codec.util.CodecUtil; import mtas.solr.schema.MtasPreAnalyzedField; /** * A factory for creating MtasUpdateRequestProcessor objects. */ <span class="fc" id="L48">public class MtasUpdateRequestProcessorFactory</span> extends UpdateRequestProcessorFactory { /** The Constant log. */ <span class="fc" id="L52"> private static final Log log = LogFactory</span> <span class="fc" id="L53"> .getLog(MtasUpdateRequestProcessorFactory.class);</span> /** The config. */ <span class="fc" id="L56"> private MtasUpdateRequestProcessorConfig config = null;</span> /* * (non-Javadoc) * * @see * org.apache.solr.update.processor.UpdateRequestProcessorFactory#init(org. * apache.solr.common.util.NamedList) */ @Override @SuppressWarnings("rawtypes") public void init(NamedList args) { <span class="fc" id="L68"> super.init(args);</span> <span class="fc" id="L69"> }</span> /** * Inits the. * * @param req the req * @throws IOException Signals that an I/O exception has occurred. */ @SuppressWarnings("unchecked") private void init(SolrQueryRequest req) throws IOException { <span class="fc bfc" id="L79" title="All 2 branches covered."> if (config == null) {</span> // initialise <span class="fc" id="L81"> config = new MtasUpdateRequestProcessorConfig();</span> // required info <span class="fc" id="L83"> Map<String, FieldType> fieldTypes = req.getSchema().getFieldTypes();</span> <span class="fc" id="L84"> Map<String, SchemaField> fields = req.getSchema().getFields();</span> <span class="fc" id="L85"> SolrResourceLoader resourceLoader = req.getCore().getSolrConfig()</span> <span class="fc" id="L86"> .getResourceLoader();</span> // check fieldTypes // for (String name : fieldTypes.keySet()) { <span class="fc bfc" id="L89" title="All 2 branches covered."> for (Entry<String, FieldType> entry : fieldTypes.entrySet()) {</span> // only for MtasPreAnalyzedField <span class="fc bfc" id="L91" title="All 2 branches covered."> if (entry.getValue() instanceof MtasPreAnalyzedField) {</span> <span class="fc" id="L92"> MtasPreAnalyzedField mpaf = (MtasPreAnalyzedField) entry.getValue();</span> <span class="fc" id="L93"> config.fieldTypeDefaultConfiguration.put(entry.getKey(),</span> mpaf.defaultConfiguration); <span class="fc" id="L95"> config.fieldTypeConfigurationFromField.put(entry.getKey(),</span> mpaf.configurationFromField); <span class="fc" id="L97"> config.fieldTypeNumberOfTokensField.put(entry.getKey(),</span> mpaf.setNumberOfTokens); <span class="fc" id="L99"> config.fieldTypeNumberOfPositionsField.put(entry.getKey(),</span> mpaf.setNumberOfPositions); <span class="fc" id="L101"> config.fieldTypeSizeField.put(entry.getKey(), mpaf.setSize);</span> <span class="fc" id="L102"> config.fieldTypeErrorField.put(entry.getKey(), mpaf.setError);</span> <span class="fc" id="L103"> config.fieldTypePrefixField.put(entry.getKey(), mpaf.setPrefix);</span> <span class="pc bpc" id="L104" title="1 of 2 branches missed."> if (mpaf.followIndexAnalyzer == null</span> <span class="pc bpc" id="L105" title="1 of 2 branches missed."> || !fieldTypes.containsKey(mpaf.followIndexAnalyzer)) {</span> <span class="nc" id="L106"> throw new IOException(</span> <span class="nc" id="L107"> entry.getKey() + " can't follow " + mpaf.followIndexAnalyzer);</span> } else { <span class="fc" id="L109"> FieldType fieldType = fieldTypes.get(mpaf.followIndexAnalyzer);</span> <span class="fc" id="L110"> SimpleOrderedMap<?> analyzer = null;</span> <span class="fc" id="L111"> Object tmpObj1 = fieldType.getNamedPropertyValues(false)</span> <span class="fc" id="L112"> .get(FieldType.INDEX_ANALYZER);</span> <span class="pc bpc" id="L113" title="3 of 4 branches missed."> if (tmpObj1 != null && tmpObj1 instanceof SimpleOrderedMap) {</span> <span class="nc" id="L114"> analyzer = (SimpleOrderedMap<?>) tmpObj1;</span> } <span class="pc bpc" id="L116" title="1 of 2 branches missed."> if (analyzer == null) {</span> <span class="fc" id="L117"> Object tmpObj2 = fieldType.getNamedPropertyValues(false)</span> <span class="fc" id="L118"> .get(FieldType.ANALYZER);</span> <span class="pc bpc" id="L119" title="2 of 4 branches missed."> if (tmpObj2 != null && tmpObj2 instanceof SimpleOrderedMap) {</span> <span class="fc" id="L120"> analyzer = (SimpleOrderedMap<?>) tmpObj2;</span> } } <span class="pc bpc" id="L123" title="1 of 2 branches missed."> if (analyzer == null) {</span> <span class="nc" id="L124"> throw new IOException("no analyzer");</span> } else { // charfilters <span class="fc" id="L127"> ArrayList<SimpleOrderedMap<Object>> listCharFilters = null;</span> <span class="fc" id="L128"> SimpleOrderedMap<Object> configTokenizer = null;</span> try { <span class="fc" id="L130"> listCharFilters = (ArrayList<SimpleOrderedMap<Object>>) analyzer</span> <span class="fc" id="L131"> .findRecursive(FieldType.CHAR_FILTERS);</span> ; <span class="fc" id="L133"> configTokenizer = (SimpleOrderedMap<Object>) analyzer</span> <span class="fc" id="L134"> .findRecursive(FieldType.TOKENIZER);</span> <span class="nc" id="L135"> } catch (ClassCastException e) {</span> <span class="nc" id="L136"> throw new IOException(</span> "could not cast charFilters and/or tokenizer from analyzer", e); <span class="fc" id="L139"> }</span> <span class="pc bpc" id="L140" title="2 of 4 branches missed."> if (listCharFilters != null && !listCharFilters.isEmpty()) {</span> <span class="fc" id="L141"> CharFilterFactory[] charFilterFactories = new CharFilterFactory[listCharFilters</span> <span class="fc" id="L142"> .size()];</span> <span class="fc" id="L143"> int number = 0;</span> <span class="fc bfc" id="L144" title="All 2 branches covered."> for (SimpleOrderedMap<Object> configCharFilter : listCharFilters) {</span> <span class="fc" id="L145"> String className = null;</span> <span class="fc" id="L146"> Map<String, String> args = new HashMap<>();</span> <span class="fc" id="L147"> Iterator<Map.Entry<String, Object>> it = configCharFilter</span> <span class="fc" id="L148"> .iterator();</span> // get className and args <span class="fc bfc" id="L150" title="All 2 branches covered."> while (it.hasNext()) {</span> <span class="fc" id="L151"> Map.Entry<String, Object> obj = it.next();</span> <span class="pc bpc" id="L152" title="1 of 2 branches missed."> if (obj.getValue() instanceof String) {</span> <span class="fc bfc" id="L153" title="All 2 branches covered."> if (obj.getKey().equals(FieldType.CLASS_NAME)) {</span> <span class="fc" id="L154"> className = (String) obj.getValue();</span> } else { <span class="fc" id="L156"> args.put(obj.getKey(), (String) obj.getValue());</span> } } <span class="fc" id="L159"> }</span> <span class="pc bpc" id="L160" title="1 of 2 branches missed."> if (className != null) {</span> try { <span class="fc" id="L162"> Class<?> cls = Class.forName((String) className);</span> <span class="pc bpc" id="L163" title="1 of 2 branches missed."> if (cls.isAssignableFrom(MtasCharFilterFactory.class)) {</span> <span class="fc" id="L164"> Class<?>[] types = { Map.class, ResourceLoader.class };</span> <span class="fc" id="L165"> Constructor<?> cnstr = cls.getConstructor(types);</span> <span class="fc" id="L166"> Object cff = cnstr.newInstance(args, resourceLoader);</span> <span class="pc bpc" id="L167" title="1 of 2 branches missed."> if (cff instanceof MtasCharFilterFactory) {</span> <span class="fc" id="L168"> charFilterFactories[number] = (MtasCharFilterFactory) cff;</span> <span class="fc" id="L169"> number++;</span> } else { <span class="nc" id="L171"> throw new IOException(</span> className + " is no MtasCharFilterFactory"); } <span class="fc" id="L174"> } else {</span> <span class="nc" id="L175"> Class<?>[] types = { Map.class };</span> <span class="nc" id="L176"> Constructor<?> cnstr = cls.getConstructor(types);</span> <span class="nc" id="L177"> Object cff = cnstr.newInstance(args);</span> <span class="nc bnc" id="L178" title="All 2 branches missed."> if (cff instanceof CharFilterFactory) {</span> <span class="nc" id="L179"> charFilterFactories[number] = (CharFilterFactory) cff;</span> <span class="nc" id="L180"> number++;</span> } else { <span class="nc" id="L182"> throw new IOException(</span> className + " is no CharFilterFactory"); } } <span class="nc" id="L186"> } catch (ClassNotFoundException | InstantiationException</span> | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException e) { <span class="nc" id="L189"> throw new IOException(e);</span> <span class="fc" id="L190"> }</span> } else { <span class="nc" id="L192"> throw new IOException("no className");</span> } <span class="fc" id="L194"> }</span> <span class="fc" id="L195"> config.fieldTypeCharFilterFactories.put(entry.getKey(),</span> charFilterFactories); <span class="fc" id="L197"> } else {</span> <span class="nc" id="L198"> config.fieldTypeCharFilterFactories.put(entry.getKey(), null);</span> } <span class="pc bpc" id="L200" title="1 of 2 branches missed."> if (configTokenizer != null) {</span> <span class="fc" id="L201"> String className = null;</span> <span class="fc" id="L202"> Map<String, String> args = new HashMap<>();</span> <span class="fc" id="L203"> Iterator<Map.Entry<String, Object>> it = configTokenizer</span> <span class="fc" id="L204"> .iterator();</span> // get className and args <span class="fc bfc" id="L206" title="All 2 branches covered."> while (it.hasNext()) {</span> <span class="fc" id="L207"> Map.Entry<String, Object> obj = it.next();</span> <span class="pc bpc" id="L208" title="1 of 2 branches missed."> if (obj.getValue() instanceof String) {</span> <span class="fc bfc" id="L209" title="All 2 branches covered."> if (obj.getKey().equals(FieldType.CLASS_NAME)) {</span> <span class="fc" id="L210"> className = (String) obj.getValue();</span> } else { <span class="fc" id="L212"> args.put(obj.getKey(), (String) obj.getValue());</span> } } <span class="fc" id="L215"> }</span> <span class="pc bpc" id="L216" title="1 of 2 branches missed."> if (className != null) {</span> try { <span class="fc" id="L218"> Class<?> cls = Class.forName((String) className);</span> <span class="fc" id="L219"> Class<?>[] types = { Map.class, ResourceLoader.class };</span> <span class="fc" id="L220"> Constructor<?> cnstr = cls.getConstructor(types);</span> <span class="fc" id="L221"> Object cff = cnstr.newInstance(args, resourceLoader);</span> <span class="pc bpc" id="L222" title="1 of 2 branches missed."> if (cff instanceof MtasTokenizerFactory) {</span> <span class="fc" id="L223"> config.fieldTypeTokenizerFactory.put(entry.getKey(),</span> (MtasTokenizerFactory) cff); } else { <span class="nc" id="L226"> throw new IOException(</span> className + " is no MtasTokenizerFactory"); } <span class="nc" id="L229"> } catch (ClassNotFoundException | InstantiationException</span> | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException e) { <span class="nc" id="L232"> throw new IOException(e);</span> <span class="fc" id="L233"> }</span> } else { <span class="nc" id="L235"> throw new IOException("no className");</span> } } } } } <span class="fc" id="L242"> }</span> <span class="fc bfc" id="L243" title="All 2 branches covered."> for (Entry<String, SchemaField> entry : fields.entrySet()) {</span> <span class="pc bpc" id="L244" title="1 of 2 branches missed."> if (entry.getValue().getType() != null</span> && config.fieldTypeTokenizerFactory <span class="fc bfc" id="L246" title="All 2 branches covered."> .containsKey(entry.getValue().getType().getTypeName())) {</span> <span class="fc" id="L247"> config.fieldMapping.put(entry.getKey(),</span> <span class="fc" id="L248"> entry.getValue().getType().getTypeName());</span> } <span class="fc" id="L250"> }</span> } <span class="fc" id="L252"> }</span> /* * (non-Javadoc) * * @see * org.apache.solr.update.processor.UpdateRequestProcessorFactory#getInstance( * org.apache.solr.request.SolrQueryRequest, * org.apache.solr.response.SolrQueryResponse, * org.apache.solr.update.processor.UpdateRequestProcessor) */ @Override public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next) { try { <span class="fc" id="L267"> init(req);</span> <span class="nc" id="L268"> } catch (IOException e) {</span> <span class="nc" id="L269"> log.error(e);</span> <span class="fc" id="L270"> }</span> <span class="fc" id="L271"> return new MtasUpdateRequestProcessor(next, config);</span> } } class MtasUpdateRequestProcessor extends UpdateRequestProcessor { /** The log. */ <span class="fc" id="L279"> private static Log log = LogFactory.getLog(MtasUpdateRequestProcessor.class);</span> private MtasUpdateRequestProcessorConfig config; public MtasUpdateRequestProcessor(UpdateRequestProcessor next, MtasUpdateRequestProcessorConfig config) { <span class="fc" id="L285"> super(next);</span> <span class="fc" id="L286"> this.config = config;</span> <span class="fc" id="L287"> }</span> @Override public void processAdd(AddUpdateCommand cmd) throws IOException { <span class="pc bpc" id="L291" title="2 of 4 branches missed."> if (config != null && config.fieldMapping.size() > 0) {</span> // get document <span class="fc" id="L293"> SolrInputDocument doc = cmd.getSolrInputDocument();</span> // loop over configurations <span class="fc bfc" id="L295" title="All 2 branches covered."> for (String field : config.fieldMapping.keySet()) {</span> <span class="fc" id="L296"> SolrInputField originalValue = doc.get(field);</span> <span class="fc" id="L297"> String fieldType = config.fieldMapping.get(field);</span> <span class="fc" id="L298"> CharFilterFactory[] charFilterFactories = config.fieldTypeCharFilterFactories</span> <span class="fc" id="L299"> .get(fieldType);</span> <span class="fc" id="L300"> MtasTokenizerFactory tokenizerFactory = config.fieldTypeTokenizerFactory</span> <span class="fc" id="L301"> .get(config.fieldMapping.get(field));</span> MtasUpdateRequestProcessorSizeReader sizeReader; <span class="fc bfc" id="L303" title="All 2 branches covered."> if (originalValue != null</span> <span class="pc bpc" id="L304" title="1 of 2 branches missed."> && originalValue.getValue() instanceof String) {</span> <span class="fc" id="L305"> MtasUpdateRequestProcessorResultWriter result = null;</span> try { <span class="fc" id="L307"> String storedValue = (String) originalValue.getValue();</span> // create reader <span class="fc" id="L309"> Reader reader = new StringReader(storedValue);</span> // configuration <span class="fc" id="L311"> String configuration = config.fieldTypeDefaultConfiguration</span> <span class="fc" id="L312"> .get(fieldType);</span> <span class="pc bpc" id="L313" title="1 of 2 branches missed."> if (config.fieldTypeConfigurationFromField.get(fieldType) != null) {</span> <span class="fc" id="L314"> Object obj = doc.getFieldValue(</span> <span class="fc" id="L315"> config.fieldTypeConfigurationFromField.get(fieldType));</span> <span class="pc bpc" id="L316" title="1 of 2 branches missed."> if (obj != null) {</span> <span class="fc" id="L317"> configuration = obj.toString();</span> } } // charFilterFactories <span class="pc bpc" id="L321" title="1 of 2 branches missed."> if (charFilterFactories != null) {</span> <span class="fc bfc" id="L322" title="All 2 branches covered."> for (CharFilterFactory charFilterFactory : charFilterFactories) {</span> <span class="pc bpc" id="L323" title="1 of 2 branches missed."> if (charFilterFactory instanceof MtasCharFilterFactory) {</span> <span class="fc" id="L324"> reader = ((MtasCharFilterFactory) charFilterFactory)</span> <span class="fc" id="L325"> .create(reader, configuration);</span> } else { <span class="nc" id="L327"> reader = charFilterFactory.create(reader);</span> } <span class="pc bpc" id="L329" title="1 of 2 branches missed."> if (reader == null) {</span> <span class="nc" id="L330"> throw new IOException(</span> <span class="nc" id="L331"> "charFilter " + charFilterFactory.getClass().getName()</span> + " returns null"); } } } <span class="fc" id="L337"> sizeReader = new MtasUpdateRequestProcessorSizeReader(reader);</span> // tokenizerFactory <span class="fc" id="L340"> result = new MtasUpdateRequestProcessorResultWriter(storedValue);</span> <span class="fc" id="L341"> int numberOfPositions = 0;</span> <span class="fc" id="L342"> int numberOfTokens = 0;</span> <span class="fc" id="L343"> Set<String> prefixes = new HashSet<>();</span> try { <span class="fc" id="L345"> MtasTokenizer tokenizer = tokenizerFactory.create(configuration);</span> <span class="fc" id="L346"> tokenizer.setReader(sizeReader);</span> <span class="fc" id="L347"> tokenizer.reset();</span> // attributes <span class="fc" id="L349"> CharTermAttribute termAttribute = tokenizer</span> <span class="fc" id="L350"> .getAttribute(CharTermAttribute.class);</span> <span class="fc" id="L351"> OffsetAttribute offsetAttribute = tokenizer</span> <span class="fc" id="L352"> .getAttribute(OffsetAttribute.class);</span> <span class="fc" id="L353"> PositionIncrementAttribute positionIncrementAttribute = tokenizer</span> <span class="fc" id="L354"> .getAttribute(PositionIncrementAttribute.class);</span> <span class="fc" id="L355"> PayloadAttribute payloadAttribute = tokenizer</span> <span class="fc" id="L356"> .getAttribute(PayloadAttribute.class);</span> <span class="fc" id="L357"> FlagsAttribute flagsAttribute = tokenizer</span> <span class="fc" id="L358"> .getAttribute(FlagsAttribute.class);</span> <span class="fc bfc" id="L360" title="All 2 branches covered."> while (tokenizer.incrementToken()) {</span> <span class="fc" id="L361"> String term = null;</span> <span class="fc" id="L362"> Integer offsetStart = null;</span> <span class="fc" id="L363"> Integer offsetEnd = null;</span> <span class="fc" id="L364"> Integer posIncr = null;</span> <span class="fc" id="L365"> Integer flags = null;</span> <span class="fc" id="L366"> BytesRef payload = null;</span> <span class="pc bpc" id="L367" title="1 of 2 branches missed."> if (termAttribute != null) {</span> <span class="fc" id="L368"> term = termAttribute.toString();</span> <span class="fc" id="L369"> prefixes.add(CodecUtil.termPrefix(term));</span> } <span class="pc bpc" id="L371" title="1 of 2 branches missed."> if (offsetAttribute != null) {</span> <span class="fc" id="L372"> offsetStart = offsetAttribute.startOffset();</span> <span class="fc" id="L373"> offsetEnd = offsetAttribute.endOffset();</span> } <span class="pc bpc" id="L375" title="1 of 2 branches missed."> if (positionIncrementAttribute != null) {</span> <span class="fc" id="L376"> posIncr = positionIncrementAttribute.getPositionIncrement();</span> } else { <span class="nc" id="L378"> posIncr = 0;</span> } <span class="pc bpc" id="L380" title="1 of 2 branches missed."> if (payloadAttribute != null) {</span> <span class="fc" id="L381"> payload = payloadAttribute.getPayload();</span> } <span class="pc bpc" id="L383" title="1 of 2 branches missed."> if (flagsAttribute != null) {</span> <span class="nc" id="L384"> flags = flagsAttribute.getFlags();</span> } <span class="fc" id="L386"> numberOfTokens++;</span> <span class="fc" id="L387"> numberOfPositions += posIncr;</span> <span class="fc" id="L388"> result.addItem(term, offsetStart, offsetEnd, posIncr, payload,</span> flags); // System.out.print(term+" "); <span class="fc" id="L391"> }</span> // update field <span class="fc" id="L394"> doc.remove(field);</span> <span class="pc bpc" id="L395" title="1 of 2 branches missed."> if (result.getTokenNumber() > 0) {</span> <span class="fc" id="L396"> doc.addField(field, result.getFileName());</span> } } finally { <span class="pc" id="L399"> result.close();</span> <span class="fc" id="L400"> }</span> // update size <span class="fc" id="L402"> setFields(doc, config.fieldTypeSizeField.get(fieldType),</span> <span class="fc" id="L403"> sizeReader.getTotalReadSize());</span> // update numberOfPositions <span class="fc" id="L405"> setFields(doc,</span> <span class="fc" id="L406"> config.fieldTypeNumberOfPositionsField.get(fieldType),</span> <span class="fc" id="L407"> numberOfPositions);</span> // update numberOfTokens <span class="fc" id="L409"> setFields(doc, config.fieldTypeNumberOfTokensField.get(fieldType),</span> <span class="fc" id="L410"> numberOfTokens);</span> // update prefixes <span class="fc" id="L412"> setFields(doc, config.fieldTypePrefixField.get(fieldType),</span> prefixes); <span class="nc" id="L414"> } catch (IOException e) {</span> <span class="nc" id="L415"> log.info(e);</span> // update error <span class="nc" id="L417"> doc.addField(config.fieldTypeErrorField.get(fieldType),</span> <span class="nc" id="L418"> e.getMessage());</span> // update size <span class="nc" id="L420"> setFields(doc, config.fieldTypeSizeField.get(fieldType), 0);</span> // update numberOfPositions <span class="nc" id="L422"> setFields(doc,</span> <span class="nc" id="L423"> config.fieldTypeNumberOfPositionsField.get(fieldType), 0);</span> // update numberOfTokens <span class="nc" id="L425"> setFields(doc, config.fieldTypeNumberOfTokensField.get(fieldType),</span> <span class="nc" id="L426"> 0);</span> // update prefixes <span class="nc" id="L428"> removeFields(doc, config.fieldTypePrefixField.get(fieldType));</span> <span class="nc bnc" id="L429" title="All 2 branches missed."> if (result != null) {</span> <span class="nc" id="L430"> result.forceCloseAndDelete();</span> <span class="nc" id="L431"> doc.remove(field);</span> } <span class="fc" id="L433"> }</span> } <span class="fc" id="L435"> }</span> } // pass it up the chain <span class="fc" id="L439"> super.processAdd(cmd);</span> <span class="fc" id="L440"> }</span> private void removeFields(SolrInputDocument doc, String fieldNames) { <span class="nc bnc" id="L443" title="All 2 branches missed."> if (fieldNames != null) {</span> <span class="nc" id="L444"> String[] tmpFields = fieldNames.split(",");</span> <span class="nc bnc" id="L445" title="All 2 branches missed."> for (int i = 0; i < tmpFields.length; i++) {</span> <span class="nc" id="L446"> doc.removeField(tmpFields[i]);</span> } } <span class="nc" id="L449"> }</span> private void setFields(SolrInputDocument doc, String fieldNames, Object value) { <span class="pc bpc" id="L453" title="1 of 2 branches missed."> if (fieldNames != null) {</span> <span class="fc" id="L454"> String[] tmpFields = fieldNames.split(",");</span> <span class="fc bfc" id="L455" title="All 2 branches covered."> for (int i = 0; i < tmpFields.length; i++) {</span> <span class="pc bpc" id="L456" title="1 of 2 branches missed."> if (!tmpFields[i].trim().isEmpty()) {</span> <span class="fc" id="L457"> doc.addField(tmpFields[i].trim(), value);</span> } } } <span class="fc" id="L461"> }</span> } class MtasUpdateRequestProcessorConfig { HashMap<String, CharFilterFactory[]> fieldTypeCharFilterFactories; HashMap<String, MtasTokenizerFactory> fieldTypeTokenizerFactory; HashMap<String, String> fieldMapping; HashMap<String, String> fieldTypeDefaultConfiguration; HashMap<String, String> fieldTypeConfigurationFromField; HashMap<String, String> fieldTypeNumberOfTokensField; HashMap<String, String> fieldTypeNumberOfPositionsField; HashMap<String, String> fieldTypeSizeField; HashMap<String, String> fieldTypeErrorField; HashMap<String, String> fieldTypePrefixField; <span class="fc" id="L478"> MtasUpdateRequestProcessorConfig() {</span> <span class="fc" id="L479"> fieldMapping = new HashMap<>();</span> <span class="fc" id="L480"> fieldTypeCharFilterFactories = new HashMap<>();</span> <span class="fc" id="L481"> fieldTypeTokenizerFactory = new HashMap<>();</span> <span class="fc" id="L482"> fieldTypeDefaultConfiguration = new HashMap<>();</span> <span class="fc" id="L483"> fieldTypeConfigurationFromField = new HashMap<>();</span> <span class="fc" id="L484"> fieldTypeNumberOfTokensField = new HashMap<>();</span> <span class="fc" id="L485"> fieldTypeNumberOfPositionsField = new HashMap<>();</span> <span class="fc" id="L486"> fieldTypeSizeField = new HashMap<>();</span> <span class="fc" id="L487"> fieldTypeErrorField = new HashMap<>();</span> <span class="fc" id="L488"> fieldTypePrefixField = new HashMap<>();</span> <span class="fc" id="L489"> }</span> } class MtasUpdateRequestProcessorSizeReader extends Reader { Reader reader; long totalReadSize; <span class="fc" id="L498"> public MtasUpdateRequestProcessorSizeReader(Reader reader) {</span> <span class="fc" id="L499"> this.reader = reader;</span> <span class="fc" id="L500"> totalReadSize = 0;</span> <span class="fc" id="L501"> }</span> public int read(char[] cbuf, int off, int len) throws IOException { <span class="fc" id="L504"> int read = reader.read(cbuf, off, len);</span> <span class="fc" id="L505"> totalReadSize += read;</span> <span class="fc" id="L506"> return read;</span> } public void close() throws IOException { <span class="nc" id="L510"> reader.close();</span> <span class="nc" id="L511"> }</span> public long getTotalReadSize() { <span class="fc" id="L514"> return totalReadSize;</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>