MtasPreAnalyzedParser.java.html
6.86 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
116
<?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="nc" id="L26">public class MtasPreAnalyzedParser implements PreAnalyzedParser {</span>
/** The log. */
<span class="nc" 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="nc" id="L41"> ParseResult res = new ParseResult();</span>
// get MtasUpdateRequestProcessorResult
<span class="nc" id="L43"> StringBuilder sb = new StringBuilder();</span>
<span class="nc" id="L44"> char[] buf = new char[128];</span>
int cnt;
<span class="nc bnc" id="L46" title="All 2 branches missed."> while ((cnt = reader.read(buf)) > 0) {</span>
<span class="nc" id="L47"> sb.append(buf, 0, cnt);</span>
}
Iterator<MtasUpdateRequestProcessorResultItem> iterator;
try {
<span class="nc" id="L53"> MtasUpdateRequestProcessorResultReader result = new MtasUpdateRequestProcessorResultReader(</span>
<span class="nc" id="L54"> sb.toString());</span>
<span class="nc" id="L55"> iterator = result.getIterator();</span>
<span class="nc bnc" id="L56" title="All 4 branches missed."> if (iterator != null && iterator.hasNext()) {</span>
<span class="nc" id="L57"> res.str = result.getStoredStringValue();</span>
<span class="nc" id="L58"> res.bin = result.getStoredBinValue();</span>
<span class="nc" id="L59"> result.close();</span>
} else {
<span class="nc" id="L61"> res.str = null;</span>
<span class="nc" id="L62"> res.bin = null;</span>
<span class="nc" id="L63"> result.close();</span>
<span class="nc" id="L64"> return res;</span>
}
<span class="nc" id="L67"> parent.clearAttributes();</span>
<span class="nc bnc" id="L68" title="All 2 branches missed."> while (iterator.hasNext()) {</span>
<span class="nc" id="L69"> MtasUpdateRequestProcessorResultItem item = iterator.next();</span>
<span class="nc bnc" id="L70" title="All 2 branches missed."> if (item.tokenTerm != null) {</span>
<span class="nc" id="L71"> CharTermAttribute catt = parent.addAttribute(CharTermAttribute.class);</span>
<span class="nc" id="L72"> catt.append(item.tokenTerm);</span>
}
<span class="nc bnc" id="L74" title="All 2 branches missed."> if (item.tokenFlags != null) {</span>
<span class="nc" id="L75"> FlagsAttribute flags = parent.addAttribute(FlagsAttribute.class);</span>
<span class="nc" id="L76"> flags.setFlags(item.tokenFlags);</span>
}
<span class="nc bnc" id="L78" title="All 2 branches missed."> if (item.tokenPosIncr != null) {</span>
<span class="nc" id="L79"> PositionIncrementAttribute patt = parent</span>
<span class="nc" id="L80"> .addAttribute(PositionIncrementAttribute.class);</span>
<span class="nc" id="L81"> patt.setPositionIncrement(item.tokenPosIncr);</span>
}
<span class="nc bnc" id="L83" title="All 2 branches missed."> if (item.tokenPayload != null) {</span>
<span class="nc" id="L84"> PayloadAttribute p = parent.addAttribute(PayloadAttribute.class);</span>
<span class="nc" id="L85"> p.setPayload(new BytesRef(item.tokenPayload));</span>
}
<span class="nc bnc" id="L87" title="All 4 branches missed."> if (item.tokenOffsetStart != null && item.tokenOffsetEnd != null) {</span>
<span class="nc" id="L88"> OffsetAttribute offset = parent.addAttribute(OffsetAttribute.class);</span>
<span class="nc" id="L89"> offset.setOffset(item.tokenOffsetStart, item.tokenOffsetEnd);</span>
}
// capture state and add to result
<span class="nc" id="L92"> State state = parent.captureState();</span>
<span class="nc" id="L93"> res.states.add(state.clone());</span>
// reset for reuse
<span class="nc" id="L95"> parent.clearAttributes();</span>
<span class="nc" id="L96"> }</span>
<span class="nc" id="L97"> } catch (IOException e) {</span>
<span class="nc" id="L98"> log.error(e);</span>
<span class="nc" id="L99"> }</span>
<span class="nc" id="L100"> 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="L112"> 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>