Revision 7709
Added by Jing Tao about 11 years ago
src/edu/ucsb/nceas/metacat/index/MetacatSolrIndex.java | ||
---|---|---|
24 | 24 |
|
25 | 25 |
import java.io.ByteArrayInputStream; |
26 | 26 |
import java.io.ByteArrayOutputStream; |
27 |
import java.io.File; |
|
28 |
import java.io.FileInputStream; |
|
29 | 27 |
import java.io.IOException; |
30 | 28 |
import java.io.InputStream; |
31 | 29 |
import java.io.OutputStreamWriter; |
32 |
import java.io.StringWriter; |
|
33 | 30 |
import java.io.Writer; |
34 |
import java.net.MalformedURLException; |
|
35 | 31 |
import java.net.URL; |
36 | 32 |
import java.sql.SQLException; |
37 | 33 |
import java.util.ArrayList; |
38 |
import java.util.Collection; |
|
39 | 34 |
import java.util.Hashtable; |
40 | 35 |
import java.util.List; |
41 |
import java.util.Map; |
|
42 | 36 |
import java.util.Set; |
43 | 37 |
|
44 | 38 |
import javax.xml.parsers.ParserConfigurationException; |
... | ... | |
56 | 50 |
import org.apache.solr.common.params.SolrParams; |
57 | 51 |
import org.apache.solr.common.util.NamedList; |
58 | 52 |
import org.apache.solr.core.CoreContainer; |
59 |
import org.apache.solr.core.SolrConfig; |
|
60 | 53 |
import org.apache.solr.core.SolrCore; |
61 |
import org.apache.solr.request.LocalSolrQueryRequest; |
|
62 |
import org.apache.solr.response.CSVResponseWriter; |
|
63 |
import org.apache.solr.response.JSONResponseWriter; |
|
64 |
import org.apache.solr.response.PHPResponseWriter; |
|
65 |
import org.apache.solr.response.PHPSerializedResponseWriter; |
|
66 |
import org.apache.solr.response.PythonResponseWriter; |
|
67 |
import org.apache.solr.response.QueryResponseWriter; |
|
68 |
import org.apache.solr.response.RubyResponseWriter; |
|
69 |
import org.apache.solr.response.SolrQueryResponse; |
|
70 |
import org.apache.solr.response.VelocityResponseWriter; |
|
71 |
import org.apache.solr.response.XMLResponseWriter; |
|
72 |
import org.apache.solr.schema.IndexSchema; |
|
73 |
import org.apache.solr.schema.SchemaField; |
|
74 | 54 |
import org.apache.solr.servlet.SolrRequestParsers; |
75 |
import org.dataone.configuration.Settings; |
|
76 | 55 |
import org.dataone.service.types.v1.Subject; |
77 |
import org.dataone.service.types.v1_1.QueryEngineDescription; |
|
78 |
import org.dataone.service.types.v1_1.QueryField; |
|
79 | 56 |
import org.dataone.service.util.Constants; |
80 |
import org.xml.sax.InputSource; |
|
81 | 57 |
import org.xml.sax.SAXException; |
82 | 58 |
|
83 | 59 |
import edu.ucsb.nceas.metacat.DBTransform; |
84 |
import edu.ucsb.nceas.metacat.MetaCatServlet;
|
|
60 |
import edu.ucsb.nceas.metacat.common.SolrQueryResponseTransformer;
|
|
85 | 61 |
import edu.ucsb.nceas.metacat.common.SolrQueryResponseWriterFactory; |
86 | 62 |
import edu.ucsb.nceas.metacat.common.SolrServerFactory; |
87 | 63 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
... | ... | |
213 | 189 |
//reload the core before query. Only after reloading the core, the query result can reflect the change made in metacat-index module. |
214 | 190 |
coreContainer.reload(collectionName); |
215 | 191 |
|
192 |
SolrCore core = coreContainer.getCore(collectionName); |
|
193 |
SolrQueryResponseTransformer solrTransformer = new SolrQueryResponseTransformer(core); |
|
216 | 194 |
// handle normal and skin-based queries |
217 | 195 |
if (wt == null ||supportedWriterTypes.contains(wt)) { |
218 | 196 |
// just handle as normal solr query |
219 | 197 |
QueryResponse response = solrServer.query(solrParams); |
220 |
inputStream = transformResults(solrParams, response, wt); |
|
198 |
inputStream = solrTransformer.transformResults(solrParams, response, wt);
|
|
221 | 199 |
} |
222 | 200 |
else { |
223 | 201 |
// assume it is a skin name |
... | ... | |
228 | 206 |
ModifiableSolrParams msp = new ModifiableSolrParams(solrParams); |
229 | 207 |
msp.set(WT, wt); |
230 | 208 |
QueryResponse response = solrServer.query(msp); |
231 |
inputStream = transformResults(msp, response, wt); |
|
209 |
inputStream = solrTransformer.transformResults(msp, response, wt);
|
|
232 | 210 |
|
233 | 211 |
// apply the stylesheet (XML->HTML) |
234 | 212 |
DBTransform transformer = new DBTransform(); |
... | ... | |
325 | 303 |
} |
326 | 304 |
|
327 | 305 |
|
328 |
/* |
|
329 |
* Transform the Queryresponse to the InputStream |
|
330 |
*/ |
|
331 |
private InputStream transformResults(SolrParams request, QueryResponse response, String wt) throws SolrServerException, IOException { |
|
332 |
//InputStream stream = null; |
|
333 |
QueryResponseWriter writer = SolrQueryResponseWriterFactory.generateResponseWriter(wt); |
|
334 |
Writer results = new StringWriter(); |
|
335 |
SolrQueryResponse sResponse = new SolrQueryResponse(); |
|
336 |
sResponse.setAllValues(response.getResponse()); |
|
337 |
SolrCore core =coreContainer.getCore(collectionName); |
|
338 |
writer.write(results, new LocalSolrQueryRequest(core, request), sResponse); |
|
339 |
return new ByteArrayInputStream(results.toString().getBytes(MetaCatServlet.DEFAULT_ENCODING)); |
|
340 |
} |
|
341 |
|
|
306 |
|
|
342 | 307 |
|
343 | 308 |
} |
Also available in: Unified diff
Move the cod which transformed the query response to the inputstream to the metacat-common module.
Remove some obsoleted imports.