MtasSolrComponentJoin.java.html
10.3 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?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>MtasSolrComponentJoin.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.util</a> > <span class="el_source">MtasSolrComponentJoin.java</span></div><h1>MtasSolrComponentJoin.java</h1><pre class="source lang-java linenums">package mtas.solr.handler.component.util;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
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.handler.component.ShardResponse;
import mtas.codec.util.CodecComponent.ComponentFields;
import mtas.codec.util.CodecComponent.ComponentJoin;
import mtas.solr.handler.component.MtasSolrSearchComponent;
/**
* The Class MtasSolrComponentJoin.
*/
@SuppressWarnings("deprecation")
public class MtasSolrComponentJoin implements MtasSolrComponent<ComponentJoin> {
/** The Constant log. */
<span class="fc" id="L28"> private static final Log log = LogFactory.getLog(MtasSolrComponentJoin.class);</span>
/** The Constant PARAM_MTAS_JOIN. */
public static final String PARAM_MTAS_JOIN = MtasSolrSearchComponent.PARAM_MTAS
+ ".join";
/** The Constant NAME_MTAS_JOIN_FIELD. */
public static final String NAME_MTAS_JOIN_FIELD = "field";
/**
* Instantiates a new mtas solr component join.
*
* @param searchComponent the search component
*/
<span class="fc" id="L42"> public MtasSolrComponentJoin(MtasSolrSearchComponent searchComponent) {</span>
<span class="fc" id="L43"> }</span>
/*
* (non-Javadoc)
*
* @see
* mtas.solr.handler.component.util.MtasSolrComponent#prepare(org.apache.solr.
* handler.component.ResponseBuilder,
* mtas.codec.util.CodecComponent.ComponentFields)
*/
public void prepare(ResponseBuilder rb, ComponentFields mtasFields)
throws IOException {
<span class="nc bnc" id="L55" title="All 2 branches missed."> if (rb.req.getParams().get(PARAM_MTAS_JOIN + "." + NAME_MTAS_JOIN_FIELD,</span>
null) != null) {
<span class="nc" id="L57"> Set<String> fields = new HashSet<>(Arrays.asList(rb.req.getParams()</span>
<span class="nc" id="L58"> .get(PARAM_MTAS_JOIN + "." + NAME_MTAS_JOIN_FIELD).split(",")));</span>
<span class="nc" id="L59"> String key = createKeyFromRequest(rb);</span>
<span class="nc" id="L60"> mtasFields.doJoin = true;</span>
<span class="nc" id="L61"> mtasFields.join = new ComponentJoin(fields, key);</span>
<span class="nc" id="L62"> rb.setNeedDocSet(true);</span>
}
<span class="nc" id="L65"> }</span>
/*
* (non-Javadoc)
*
* @see
* mtas.solr.handler.component.util.MtasSolrComponent#modifyRequest(org.apache
* .solr.handler.component.ResponseBuilder,
* org.apache.solr.handler.component.SearchComponent,
* org.apache.solr.handler.component.ShardRequest)
*/
public void modifyRequest(ResponseBuilder rb, SearchComponent who,
ShardRequest sreq) {
<span class="nc bnc" id="L78" title="All 2 branches missed."> if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="nc bnc" id="L79" title="All 2 branches missed."> && sreq.params.getBool(PARAM_MTAS_JOIN, false)) {</span>
<span class="nc bnc" id="L80" title="All 2 branches missed."> if ((sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) != 0) {</span>
// do nothing
} else {
// remove for other requests
<span class="nc" id="L84"> Set<String> keys = MtasSolrResultUtil</span>
<span class="nc" id="L85"> .getIdsFromParameters(rb.req.getParams(), PARAM_MTAS_JOIN);</span>
<span class="nc" id="L86"> sreq.params.remove(PARAM_MTAS_JOIN);</span>
<span class="nc bnc" id="L87" title="All 2 branches missed."> for (String key : keys) {</span>
<span class="nc" id="L88"> sreq.params.remove(PARAM_MTAS_JOIN + "." + key);</span>
<span class="nc" id="L89"> }</span>
}
}
<span class="nc" id="L92"> }</span>
/*
* (non-Javadoc)
*
* @see
* mtas.solr.handler.component.util.MtasSolrComponent#create(mtas.codec.util.
* CodecComponent.BasicComponent, java.lang.Boolean)
*/
public SimpleOrderedMap<Object> create(ComponentJoin join, Boolean encode)
throws IOException {
<span class="nc" id="L103"> MtasSolrJoinResult data = new MtasSolrJoinResult(join);</span>
<span class="nc" id="L104"> SimpleOrderedMap<Object> mtasJoinResponse = new SimpleOrderedMap<>();</span>
<span class="nc bnc" id="L105" title="All 2 branches missed."> if (encode) {</span>
<span class="nc" id="L106"> mtasJoinResponse.add("_encoded_data", MtasSolrResultUtil.encode(data));</span>
} else {
<span class="nc" id="L108"> mtasJoinResponse.add("data", data.rewrite());</span>
}
<span class="nc" id="L110"> return mtasJoinResponse;</span>
}
/*
* (non-Javadoc)
*
* @see
* mtas.solr.handler.component.util.MtasSolrComponent#finishStage(org.apache.
* solr.handler.component.ResponseBuilder)
*/
@SuppressWarnings("unchecked")
public void finishStage(ResponseBuilder rb) {
<span class="nc bnc" id="L122" title="All 4 branches missed."> if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
&& rb.stage == MtasSolrSearchComponent.STAGE_JOIN) {
<span class="nc bnc" id="L124" title="All 2 branches missed."> for (ShardRequest sreq : rb.finished) {</span>
<span class="nc bnc" id="L125" title="All 2 branches missed."> if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)</span>
<span class="nc bnc" id="L126" title="All 2 branches missed."> && sreq.params.getBool(PARAM_MTAS_JOIN, false)) {</span>
<span class="nc bnc" id="L127" title="All 2 branches missed."> for (ShardResponse shardResponse : sreq.responses) {</span>
<span class="nc" id="L128"> NamedList<Object> response = shardResponse.getSolrResponse()</span>
<span class="nc" id="L129"> .getResponse();</span>
try {
<span class="nc" id="L131"> Object data = response.findRecursive("mtas", "join");</span>
<span class="nc bnc" id="L132" title="All 4 branches missed."> if (data != null && data instanceof String) {</span>
<span class="nc" id="L133"> NamedList<Object> mtasResponse = (NamedList<Object>) response</span>
<span class="nc" id="L134"> .get("mtas");</span>
<span class="nc" id="L135"> mtasResponse.remove("join");</span>
<span class="nc" id="L136"> mtasResponse.add("join",</span>
<span class="nc" id="L137"> MtasSolrResultUtil.decode((String) data));</span>
}
<span class="nc" id="L139"> } catch (ClassCastException e) {</span>
<span class="nc" id="L140"> log.debug(e);</span>
// shouldn't happen
<span class="nc" id="L142"> }</span>
<span class="nc" id="L143"> }</span>
}
<span class="nc" id="L145"> }</span>
}
<span class="nc" id="L147"> }</span>
/*
* (non-Javadoc)
*
* @see
* mtas.solr.handler.component.util.MtasSolrComponent#distributedProcess(org.
* apache.solr.handler.component.ResponseBuilder,
* mtas.codec.util.CodecComponent.ComponentFields)
*/
@SuppressWarnings("unchecked")
public void distributedProcess(ResponseBuilder rb, ComponentFields mtasFields)
throws IOException {
// rewrite
<span class="nc" id="L161"> NamedList<Object> mtasResponse = null;</span>
try {
<span class="nc" id="L163"> mtasResponse = (NamedList<Object>) rb.rsp.getValues().get("mtas");</span>
<span class="nc" id="L164"> } catch (ClassCastException e) {</span>
<span class="nc" id="L165"> log.debug(e);</span>
<span class="nc" id="L166"> mtasResponse = null;</span>
<span class="nc" id="L167"> }</span>
<span class="nc bnc" id="L168" title="All 2 branches missed."> if (mtasResponse != null) {</span>
MtasSolrJoinResult mtasSolrJoinResult;
try {
<span class="nc" id="L171"> mtasSolrJoinResult = (MtasSolrJoinResult) mtasResponse.get("join");</span>
<span class="nc bnc" id="L172" title="All 2 branches missed."> if (mtasSolrJoinResult != null) {</span>
<span class="nc" id="L173"> mtasResponse.removeAll("join");</span>
<span class="nc" id="L174"> mtasResponse.add("join", mtasSolrJoinResult.rewrite());</span>
}
<span class="nc" id="L176"> } catch (ClassCastException e) {</span>
<span class="nc" id="L177"> log.debug(e);</span>
<span class="nc" id="L178"> mtasResponse.remove("join");</span>
<span class="nc" id="L179"> }</span>
}
<span class="nc" id="L181"> }</span>
/**
* Creates the key from request.
*
* @param rb the rb
* @return the string
*/
private String createKeyFromRequest(ResponseBuilder rb) {
<span class="nc" id="L190"> return rb.req.getParams().toQueryString();</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>