Revision 7620
Added by Jing Tao over 11 years ago
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java | ||
---|---|---|
41 | 41 |
|
42 | 42 |
import org.apache.commons.io.IOUtils; |
43 | 43 |
import org.apache.log4j.Logger; |
44 |
import org.apache.solr.client.solrj.SolrServerException; |
|
44 | 45 |
import org.dataone.client.CNode; |
45 | 46 |
import org.dataone.client.D1Client; |
46 | 47 |
import org.dataone.client.MNode; |
... | ... | |
104 | 105 |
import edu.ucsb.nceas.metacat.MetaCatServlet; |
105 | 106 |
import edu.ucsb.nceas.metacat.MetacatHandler; |
106 | 107 |
import edu.ucsb.nceas.metacat.dataone.hazelcast.HazelcastService; |
108 |
import edu.ucsb.nceas.metacat.index.MetacatSolrIndex; |
|
107 | 109 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
108 | 110 |
import edu.ucsb.nceas.metacat.shared.MetacatUtilException; |
109 | 111 |
import edu.ucsb.nceas.metacat.util.DocumentUtil; |
... | ... | |
141 | 143 |
implements MNAuthorization, MNCore, MNRead, MNReplication, MNStorage, MNQuery { |
142 | 144 |
|
143 | 145 |
private static final String PATHQUERY = "pathquery"; |
146 |
public static final String SOLRQUERY = "solrquery"; |
|
144 | 147 |
private static final String UUID_SCHEME = "UUID"; |
145 | 148 |
private static final String DOI_SCHEME = "DOI"; |
146 | 149 |
private static final String UUID_PREFIX = "urn:uuid:"; |
... | ... | |
1444 | 1447 |
public InputStream query(String engine, String query) throws InvalidToken, |
1445 | 1448 |
ServiceFailure, NotAuthorized, InvalidRequest, NotImplemented, |
1446 | 1449 |
NotFound { |
1447 |
if (engine.equals(PATHQUERY)) { |
|
1450 |
if (engine != null && engine.equals(PATHQUERY)) {
|
|
1448 | 1451 |
try { |
1449 | 1452 |
DBQuery queryobj = new DBQuery(); |
1450 | 1453 |
String user = Constants.SUBJECT_PUBLIC; |
... | ... | |
1467 | 1470 |
|
1468 | 1471 |
} |
1469 | 1472 |
|
1473 |
} else if (engine != null && engine.equals(SOLRQUERY)) { |
|
1474 |
System.out.println("The query is ==================================== \n"+query); |
|
1475 |
try { |
|
1476 |
MetacatSolrIndex solrIndex = new MetacatSolrIndex(); |
|
1477 |
return solrIndex.query(query); |
|
1478 |
} catch (Exception e) { |
|
1479 |
// TODO Auto-generated catch block |
|
1480 |
throw new ServiceFailure("Solr server error", e.getMessage()); |
|
1481 |
} |
|
1470 | 1482 |
} |
1471 | 1483 |
return null; |
1472 | 1484 |
} |
src/edu/ucsb/nceas/metacat/index/MetacatSolrIndex.java | ||
---|---|---|
29 | 29 |
import java.io.StringWriter; |
30 | 30 |
import java.io.Writer; |
31 | 31 |
|
32 |
import javax.xml.parsers.ParserConfigurationException; |
|
33 |
|
|
32 | 34 |
import org.apache.commons.logging.Log; |
33 | 35 |
import org.apache.commons.logging.LogFactory; |
34 | 36 |
import org.apache.solr.client.solrj.SolrServer; |
... | ... | |
50 | 52 |
import org.apache.solr.response.XMLResponseWriter; |
51 | 53 |
import org.apache.solr.servlet.SolrRequestParsers; |
52 | 54 |
import org.dataone.configuration.Settings; |
55 |
import org.xml.sax.SAXException; |
|
53 | 56 |
|
54 | 57 |
import edu.ucsb.nceas.metacat.MetaCatServlet; |
55 | 58 |
|
... | ... | |
83 | 86 |
|
84 | 87 |
/** |
85 | 88 |
* Constructor |
89 |
* @throws SAXException |
|
90 |
* @throws IOException |
|
91 |
* @throws ParserConfigurationException |
|
86 | 92 |
*/ |
87 |
public MetacatSolrIndex() throws Exception { |
|
93 |
public MetacatSolrIndex() throws ParserConfigurationException, IOException, SAXException {
|
|
88 | 94 |
generateEmbeddedServer(); |
89 | 95 |
} |
90 | 96 |
|
... | ... | |
92 | 98 |
/* |
93 | 99 |
* Generate the embedded solr server |
94 | 100 |
*/ |
95 |
private void generateEmbeddedServer() throws Exception { |
|
101 |
private void generateEmbeddedServer() throws ParserConfigurationException, IOException, SAXException {
|
|
96 | 102 |
String solrHomeDir = Settings.getConfiguration().getString(SOLR_HOME_PROPERTY_NAME); |
97 | 103 |
log.info("The configured solr home from properties is " + solrHomeDir); |
98 | 104 |
String configFileName = Settings.getConfiguration().getString(SOLR_CONFIG_FILE_NAME_PROPERTY_NAME); |
Also available in: Unified diff
Add code to handle solr query.