MtasPreAnalyzedParser.java.html
6.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?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>MtasPreAnalyzedParser.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.schema</a> > <span class="el_source">MtasPreAnalyzedParser.java</span></div><h1>MtasPreAnalyzedParser.java</h1><pre class="source lang-java linenums">package mtas.solr.schema;
import java.io.IOException;
import java.io.Reader;
import java.util.Iterator;
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.document.Field;
import org.apache.lucene.util.AttributeSource;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.AttributeSource.State;
import org.apache.solr.schema.PreAnalyzedField.ParseResult;
import org.apache.solr.schema.PreAnalyzedField.PreAnalyzedParser;
import mtas.solr.update.processor.MtasUpdateRequestProcessorResultItem;
import mtas.solr.update.processor.MtasUpdateRequestProcessorResultReader;
/**
* The Class MtasPreAnalyzedParser.
*/
<span class="fc" id="L26">public class MtasPreAnalyzedParser implements PreAnalyzedParser {</span>
/** The log. */
<span class="fc" id="L29"> private static Log log = LogFactory.getLog(MtasPreAnalyzedParser.class);</span>
/*
* (non-Javadoc)
*
* @see
* org.apache.solr.schema.PreAnalyzedField.PreAnalyzedParser#parse(java.io.
* Reader, org.apache.lucene.util.AttributeSource)
*/
@Override
public ParseResult parse(Reader reader, AttributeSource parent)
throws IOException {
<span class="fc" id="L41"> ParseResult res = new ParseResult();</span>
// get MtasUpdateRequestProcessorResult
<span class="fc" id="L44"> StringBuilder sb = new StringBuilder();</span>
<span class="fc" id="L45"> char[] buf = new char[128];</span>
int cnt;
<span class="fc bfc" id="L47" title="All 2 branches covered."> while ((cnt = reader.read(buf)) > 0) {</span>
<span class="fc" id="L48"> sb.append(buf, 0, cnt);</span>
}
Iterator<MtasUpdateRequestProcessorResultItem> iterator;
<span class="pc" id="L52"> try (</span>
<span class="fc" id="L53"> MtasUpdateRequestProcessorResultReader result = new MtasUpdateRequestProcessorResultReader(</span>
<span class="fc" id="L54"> sb.toString());) {</span>
<span class="fc" id="L55"> iterator = result.getIterator();</span>
<span class="pc bpc" id="L56" title="2 of 4 branches missed."> if (iterator != null && iterator.hasNext()) {</span>
<span class="fc" id="L57"> res.str = result.getStoredStringValue();</span>
<span class="fc" id="L58"> res.bin = result.getStoredBinValue();</span>
} else {
<span class="nc" id="L60"> res.str = null;</span>
<span class="nc" id="L61"> res.bin = null;</span>
<span class="nc" id="L62"> result.close();</span>
<span class="nc" id="L63"> return res;</span>
}
<span class="fc" id="L65"> parent.clearAttributes();</span>
<span class="fc bfc" id="L66" title="All 2 branches covered."> while (iterator.hasNext()) {</span>
<span class="fc" id="L67"> MtasUpdateRequestProcessorResultItem item = iterator.next();</span>
<span class="pc bpc" id="L68" title="1 of 2 branches missed."> if (item.tokenTerm != null) {</span>
<span class="fc" id="L69"> CharTermAttribute catt = parent.addAttribute(CharTermAttribute.class);</span>
<span class="fc" id="L70"> catt.append(item.tokenTerm);</span>
}
<span class="pc bpc" id="L72" title="1 of 2 branches missed."> if (item.tokenFlags != null) {</span>
<span class="nc" id="L73"> FlagsAttribute flags = parent.addAttribute(FlagsAttribute.class);</span>
<span class="nc" id="L74"> flags.setFlags(item.tokenFlags);</span>
}
<span class="fc bfc" id="L76" title="All 2 branches covered."> if (item.tokenPosIncr != null) {</span>
<span class="fc" id="L77"> PositionIncrementAttribute patt = parent</span>
<span class="fc" id="L78"> .addAttribute(PositionIncrementAttribute.class);</span>
<span class="fc" id="L79"> patt.setPositionIncrement(item.tokenPosIncr);</span>
}
<span class="pc bpc" id="L81" title="1 of 2 branches missed."> if (item.tokenPayload != null) {</span>
<span class="fc" id="L82"> PayloadAttribute p = parent.addAttribute(PayloadAttribute.class);</span>
<span class="fc" id="L83"> p.setPayload(new BytesRef(item.tokenPayload));</span>
}
<span class="pc bpc" id="L85" title="2 of 4 branches missed."> if (item.tokenOffsetStart != null && item.tokenOffsetEnd != null) {</span>
<span class="fc" id="L86"> OffsetAttribute offset = parent.addAttribute(OffsetAttribute.class);</span>
<span class="fc" id="L87"> offset.setOffset(item.tokenOffsetStart, item.tokenOffsetEnd);</span>
}
// capture state and add to result
<span class="fc" id="L90"> State state = parent.captureState();</span>
<span class="fc" id="L91"> res.states.add(state.clone());</span>
// reset for reuse
<span class="fc" id="L93"> parent.clearAttributes();</span>
<span class="fc" id="L94"> }</span>
<span class="pc bpc" id="L95" title="10 of 12 branches missed."> } catch (IOException e) {</span>
// ignore
<span class="nc" id="L97"> log.debug(e);</span>
<span class="fc" id="L98"> }</span>
<span class="fc" id="L99"> return res;</span>
}
/*
* (non-Javadoc)
*
* @see
* org.apache.solr.schema.PreAnalyzedField.PreAnalyzedParser#toFormattedString
* (org.apache.lucene.document.Field)
*/
@Override
public String toFormattedString(Field f) throws IOException {
<span class="nc" id="L111"> return this.getClass().getName() + " " + f.name();</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>