Revision 7714
Added by Jing Tao over 11 years ago
metacat-common/src/main/java/edu/ucsb/nceas/metacat/common/query/HttpSolrQueryService.java | ||
---|---|---|
34 | 34 |
import java.util.Map; |
35 | 35 |
import java.util.Set; |
36 | 36 |
|
37 |
import org.apache.commons.logging.Log; |
|
38 |
import org.apache.commons.logging.LogFactory; |
|
37 | 39 |
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; |
38 |
import org.apache.solr.client.solrj.response.QueryResponse; |
|
40 |
|
|
39 | 41 |
import org.apache.solr.common.params.SolrParams; |
40 | 42 |
import org.apache.solr.schema.SchemaField; |
41 | 43 |
import org.dataone.cn.indexer.solrhttp.HTTPService; |
42 | 44 |
import org.dataone.cn.indexer.solrhttp.SolrDoc; |
43 | 45 |
import org.dataone.service.exceptions.NotFound; |
44 | 46 |
import org.dataone.service.exceptions.NotImplemented; |
45 |
import org.dataone.service.exceptions.UnsupportedType; |
|
46 | 47 |
import org.dataone.service.types.v1.Subject; |
47 | 48 |
|
48 |
import edu.ucsb.nceas.metacat.common.SolrQueryResponseTransformer; |
|
49 | 49 |
|
50 |
|
|
50 | 51 |
/** |
51 | 52 |
* The query service for the http solr server. |
52 | 53 |
* @author tao |
... | ... | |
56 | 57 |
|
57 | 58 |
private String solrServerBaseURL = null; |
58 | 59 |
private CommonsHttpSolrServer httpSolrServer = null; |
59 |
|
|
60 |
private static Log log = LogFactory.getLog(HttpSolrQueryService.class); |
|
60 | 61 |
/** |
61 | 62 |
* Constructor |
62 | 63 |
* @param httpSolrServer |
... | ... | |
70 | 71 |
} |
71 | 72 |
|
72 | 73 |
/** |
73 |
* Query the Solr server with specified query and user's identity. If the Subjects |
|
74 |
* is null, there will be no access rules for the query. This is the for the http solr server. |
|
74 |
* Query the Solr server with specified query string and the user's identity. This is the for the http solr server. |
|
75 |
* It is hard to transform the SolrQueryReponse object to the InputStream object for the HttpSolrServer |
|
76 |
* since the transform needs the SolrCore. We have to open the solr url directly to get the InputStream. |
|
75 | 77 |
* @param query the query string |
76 | 78 |
* @param subjects the user's identity which sent the query |
77 | 79 |
* @return the response |
... | ... | |
87 | 89 |
} else { |
88 | 90 |
throw new NotFound("0000", "HttpSolrQueryService.query - There is no identity (even user public) for the user who issued the query"); |
89 | 91 |
} |
92 |
log.info("==========HttpSolrQueryService.query - the final url for querying the solr http server is "+query); |
|
90 | 93 |
URL url = new URL(query); |
94 |
|
|
91 | 95 |
return url.openStream(); |
92 | 96 |
} |
93 | 97 |
|
metacat-common/src/main/java/edu/ucsb/nceas/metacat/common/query/SolrQueryService.java | ||
---|---|---|
34 | 34 |
|
35 | 35 |
import org.apache.commons.logging.Log; |
36 | 36 |
import org.apache.commons.logging.LogFactory; |
37 |
import org.apache.solr.client.solrj.response.QueryResponse; |
|
38 | 37 |
import org.apache.solr.common.params.AppendedSolrParams; |
39 | 38 |
import org.apache.solr.common.params.SolrParams; |
40 | 39 |
import org.apache.solr.common.util.NamedList; |
metacat-common/src/main/java/edu/ucsb/nceas/metacat/common/query/SolrQueryServiceController.java | ||
---|---|---|
36 | 36 |
import org.apache.solr.client.solrj.SolrServerException; |
37 | 37 |
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; |
38 | 38 |
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; |
39 |
import org.apache.solr.client.solrj.response.QueryResponse; |
|
40 | 39 |
import org.apache.solr.common.params.SolrParams; |
41 | 40 |
import org.apache.solr.core.CoreContainer; |
42 | 41 |
import org.dataone.service.exceptions.NotFound; |
... | ... | |
45 | 44 |
import org.dataone.service.types.v1.Subject; |
46 | 45 |
import org.xml.sax.SAXException; |
47 | 46 |
|
48 |
import edu.ucsb.nceas.metacat.common.SolrQueryResponseTransformer; |
|
49 | 47 |
import edu.ucsb.nceas.metacat.common.SolrServerFactory; |
50 | 48 |
|
51 | 49 |
/** |
52 |
* A class to handle the solr query. |
|
50 |
* A class to handle the solr query. It will call the SolrServerFactory to generate a SolrServer and |
|
51 |
* determine the type - the embedded or http solr server. |
|
53 | 52 |
* @author tao |
54 | 53 |
* |
55 | 54 |
*/ |
... | ... | |
93 | 92 |
return controller; |
94 | 93 |
} |
95 | 94 |
|
96 |
/** |
|
97 |
* Query the Solr server with specified query and user's identity. If the Subjects |
|
98 |
* is null, there will be no access rules for the query. This is the for the http solr server. |
|
99 |
* @param query the query string |
|
100 |
* @param subjects the user's identity which sent the query |
|
101 |
* @return the response |
|
102 |
* @throws NotImplemented |
|
103 |
* @throws IOException |
|
104 |
* @throws NotFound |
|
105 |
* @throws Exception |
|
106 |
*/ |
|
107 |
public InputStream query(String query, Set<Subject>subjects) throws NotImplemented, NotFound, IOException { |
|
108 |
if(isEmbeddedSolrServer) { |
|
109 |
throw new NotImplemented("0000", "SolrQueryServiceController - the method of query(String query, Set<Subject>subjects) is not for the EmbeddedSolrServer. We donot need to implemente it"); |
|
110 |
} else { |
|
111 |
return httpQueryService.query(query, subjects); |
|
112 |
} |
|
113 |
|
|
114 |
} |
|
95 |
|
|
115 | 96 |
|
116 | 97 |
/** |
117 |
* Query the Solr server with specified query and user's identity. If the Subjects |
|
118 |
* is null, there will be no access rules for the query. This is for the embedded solr server. |
|
119 |
* @param query the query params. |
|
120 |
* @param subjects the user's identity which sent the query |
|
121 |
* @return the response |
|
98 |
* Query the Solr server with specified query string or SolrParams and the user's identity. |
|
99 |
* @param query query string. It is for the HttpSolrQueryService. |
|
100 |
* @param params the SolrParam. It is for the EmbeddedSolrQueryService. |
|
101 |
* @param subjects |
|
102 |
* @return |
|
103 |
* @throws NotImplemented |
|
104 |
* @throws NotFound |
|
105 |
* @throws IOException |
|
106 |
* @throws SolrServerException |
|
122 | 107 |
* @throws SAXException |
123 |
* @throws IOException |
|
124 | 108 |
* @throws ParserConfigurationException |
125 |
* @throws SolrServerException |
|
126 | 109 |
* @throws UnsupportedType |
127 |
* @throws NotImplemented |
|
128 |
* @throws Exception |
|
129 | 110 |
*/ |
130 |
public InputStream query(SolrParams query, Set<Subject>subjects) throws UnsupportedType, ParserConfigurationException, IOException, SAXException, SolrServerException, NotImplemented {
|
|
111 |
public InputStream query(String query, SolrParams params,Set<Subject>subjects) throws NotImplemented, NotFound, IOException, UnsupportedType, ParserConfigurationException, SAXException, SolrServerException {
|
|
131 | 112 |
if(isEmbeddedSolrServer) { |
132 |
return embeddedQueryService.query(query, subjects);
|
|
113 |
return embeddedQueryService.query(params, subjects);
|
|
133 | 114 |
} else { |
134 |
throw new NotImplemented("0000", "QueryServiceController - the method of query(String query, Set<Subject>subjects) is not for the EmbeddedSolrServer. We donot need to implemente it");
|
|
115 |
return httpQueryService.query(query, subjects);
|
|
135 | 116 |
} |
117 |
|
|
136 | 118 |
} |
119 |
|
|
137 | 120 |
|
138 | 121 |
} |
Also available in: Unified diff
Use one query method in the SolrQueryServiceController.