MtasExtendedTermSpans.java.html
6.36 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
117
118
119
120
121
122
123
124
125
126
127
128
129
<?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>MtasExtendedTermSpans.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.search.spans.util</a> > <span class="el_source">MtasExtendedTermSpans.java</span></div><h1>MtasExtendedTermSpans.java</h1><pre class="source lang-java linenums">package mtas.search.spans.util;
import java.io.IOException;
import java.util.Collection;
import mtas.analysis.token.MtasPosition;
import mtas.codec.payload.MtasPayloadDecoder;
import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.Term;
import org.apache.lucene.payloads.PayloadSpanCollector;
import org.apache.lucene.search.spans.TermSpans;
/**
* The Class MtasExtendedTermSpans.
*/
public class MtasExtendedTermSpans extends TermSpans implements MtasSpans {
/** The mtas position. */
<span class="fc" id="L20"> protected MtasPosition mtasPosition = null;</span>
/** The assume single position. */
private boolean assumeSinglePosition;
/** The payload span collector. */
private PayloadSpanCollector payloadSpanCollector;
/**
* Instantiates a new mtas extended term spans.
*
* @param postings the postings
* @param term the term
*/
public MtasExtendedTermSpans(PostingsEnum postings, Term term) {
<span class="nc" id="L35"> this(postings, term, false);</span>
<span class="nc" id="L36"> }</span>
/**
* Instantiates a new mtas extended term spans.
*
* @param postings the postings
* @param term the term
* @param assumeSinglePosition the assume single position
*/
public MtasExtendedTermSpans(PostingsEnum postings, Term term,
boolean assumeSinglePosition) {
<span class="fc" id="L47"> super(null, postings, term, 1);</span>
<span class="fc" id="L48"> payloadSpanCollector = new PayloadSpanCollector();</span>
<span class="fc" id="L49"> this.assumeSinglePosition = assumeSinglePosition;</span>
<span class="fc" id="L50"> }</span>
/*
* (non-Javadoc)
*
* @see org.apache.lucene.search.spans.TermSpans#endPosition()
*/
@Override
public int endPosition() {
<span class="fc bfc" id="L59" title="All 2 branches covered."> if (assumeSinglePosition) {</span>
<span class="fc" id="L60"> return super.endPosition();</span>
} else {
<span class="fc" id="L62"> int status = super.endPosition();</span>
try {
<span class="fc" id="L64"> processEncodedPayload();</span>
<span class="fc bfc" id="L65" title="All 2 branches covered."> return (status != NO_MORE_POSITIONS) ? (mtasPosition.getEnd() + 1)</span>
: NO_MORE_POSITIONS;
<span class="fc" id="L67"> } catch (IOException e) {</span>
<span class="fc" id="L68"> return NO_MORE_POSITIONS;</span>
}
}
}
/**
* Gets the positions.
*
* @return the positions
*/
public int[] getPositions() {
int[] list;
<span class="nc bnc" id="L80" title="All 2 branches missed."> if (assumeSinglePosition) {</span>
<span class="nc" id="L81"> list = new int[1];</span>
<span class="nc" id="L82"> list[0] = super.startPosition();</span>
<span class="nc" id="L83"> return list;</span>
} else {
try {
<span class="nc" id="L86"> processEncodedPayload();</span>
<span class="nc" id="L87"> list = mtasPosition.getPositions();</span>
<span class="nc bnc" id="L88" title="All 2 branches missed."> if (list != null) {</span>
<span class="nc" id="L89"> return mtasPosition.getPositions();</span>
}
<span class="nc" id="L91"> } catch (IOException e) {</span>
// do nothing
<span class="nc" id="L93"> }</span>
<span class="nc" id="L94"> int start = super.startPosition();</span>
<span class="nc" id="L95"> int end = super.endPosition();</span>
<span class="nc" id="L96"> list = new int[end - start];</span>
<span class="nc bnc" id="L97" title="All 2 branches missed."> for (int i = start; i < end; i++)</span>
<span class="nc" id="L98"> list[i - start] = i;</span>
<span class="nc" id="L99"> return list;</span>
}
}
/**
* Process encoded payload.
*
* @throws IOException Signals that an I/O exception has occurred.
*/
private void processEncodedPayload() throws IOException {
<span class="pc bpc" id="L109" title="1 of 2 branches missed."> if (!readPayload) {</span>
<span class="fc" id="L110"> payloadSpanCollector.reset();</span>
<span class="fc" id="L111"> collect(payloadSpanCollector);</span>
<span class="fc" id="L112"> Collection<byte[]> originalPayloadCollection = payloadSpanCollector</span>
<span class="fc" id="L113"> .getPayloads();</span>
<span class="fc bfc" id="L114" title="All 2 branches covered."> if (originalPayloadCollection.iterator().hasNext()) {</span>
<span class="fc" id="L115"> byte[] payload = originalPayloadCollection.iterator().next();</span>
<span class="pc bpc" id="L116" title="1 of 2 branches missed."> if (payload == null) {</span>
<span class="nc" id="L117"> throw new IOException("no payload");</span>
}
<span class="fc" id="L119"> MtasPayloadDecoder payloadDecoder = new MtasPayloadDecoder();</span>
<span class="fc" id="L120"> payloadDecoder.init(startPosition(), payload);</span>
<span class="fc" id="L121"> mtasPosition = payloadDecoder.getMtasPosition();</span>
<span class="fc" id="L122"> } else {</span>
<span class="fc" id="L123"> throw new IOException("no payload");</span>
}
}
<span class="fc" id="L126"> }</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>