34 |
34 |
import java.util.Map;
|
35 |
35 |
import java.util.Set;
|
36 |
36 |
|
|
37 |
import org.apache.commons.codec.net.URLCodec;
|
37 |
38 |
import org.apache.commons.logging.Log;
|
38 |
39 |
import org.apache.commons.logging.LogFactory;
|
39 |
40 |
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
|
... | ... | |
53 |
54 |
*
|
54 |
55 |
*/
|
55 |
56 |
public class HttpSolrQueryService extends SolrQueryService {
|
|
57 |
private static final String SELECTIONPHASE = "/select";
|
56 |
58 |
|
57 |
59 |
private String solrServerBaseURL = null;
|
58 |
60 |
private CommonsHttpSolrServer httpSolrServer = null;
|
... | ... | |
80 |
82 |
* @throws IOException
|
81 |
83 |
* @throws Exception
|
82 |
84 |
*/
|
83 |
|
public InputStream query(String query, Set<Subject>subjects) throws NotFound, IOException {
|
|
85 |
/*public InputStream query(String query, Set<Subject>subjects) throws NotFound, IOException {
|
84 |
86 |
StringBuffer accessFilter = generateAccessFilterParamsString(subjects);
|
85 |
87 |
if(accessFilter != null && accessFilter.length() != 0) {
|
86 |
88 |
query = solrServerBaseURL+"/select?"+query+"&"+FILTERQUERY+"="+accessFilter.toString();
|
... | ... | |
92 |
94 |
URL url = new URL(query);
|
93 |
95 |
|
94 |
96 |
return url.openStream();
|
95 |
|
}
|
|
97 |
}*/
|
96 |
98 |
|
97 |
99 |
/**
|
98 |
|
* Query the Solr server with specified query and user's identity. If the Subjects
|
99 |
|
* is null, there will be no access rules for the query. This is for the embedded solr server.
|
|
100 |
* Query the Solr server with specified query and user's identity.
|
|
101 |
* It is hard to transform the SolrQueryReponse object to the InputStream object for the HttpSolrServer
|
|
102 |
* since the transform needs the SolrCore. We have to open the solr url directly to get the InputStream.
|
100 |
103 |
* @param query the query params.
|
101 |
104 |
* @param subjects the user's identity which sent the query
|
102 |
105 |
* @return the response
|
|
106 |
* @throws IOException
|
|
107 |
* @throws NotFound
|
103 |
108 |
* @throws Exception
|
104 |
109 |
*/
|
105 |
|
public InputStream query(SolrParams query, Set<Subject>subjects) throws Exception {
|
106 |
|
throw new NotImplemented("0000", "HttpSolrQueryService - the method of query(SolrParams query, Set<Subject>subjects) is not for the HttpSolrQueryService. We donot need to implemente it");
|
|
110 |
public InputStream query(SolrParams query, Set<Subject>subjects) throws IOException, NotFound {
|
|
111 |
boolean xmlFormat = false;
|
|
112 |
String queryString = ClientUtils.toQueryString(query, xmlFormat);
|
|
113 |
log.info("==========HttpSolrQueryService.query - the query string after transforming from the SolrParams to the string "+queryString);
|
|
114 |
StringBuffer accessFilter = generateAccessFilterParamsString(subjects);
|
|
115 |
if(accessFilter != null && accessFilter.length() != 0) {
|
|
116 |
String accessStr = accessFilter.toString();
|
|
117 |
log.debug("==========HttpSolrQueryService.query - the access string is "+accessStr);
|
|
118 |
URLCodec urlCodec = new URLCodec();
|
|
119 |
accessStr = urlCodec.encode(accessStr, "UTF-8");
|
|
120 |
log.debug("==========HttpSolrQueryService.query - the access string after escape special characters string "+accessStr);
|
|
121 |
queryString = queryString+"&"+FILTERQUERY+"="+accessStr;
|
|
122 |
|
|
123 |
} else {
|
|
124 |
throw new NotFound("0000", "HttpSolrQueryService.query - There is no identity (even user public) for the user who issued the query");
|
|
125 |
}
|
|
126 |
|
|
127 |
|
|
128 |
//queryString = ClientUtils.escapeQueryChars(queryString);
|
|
129 |
queryString = solrServerBaseURL+SELECTIONPHASE+queryString;
|
|
130 |
log.info("==========HttpSolrQueryService.query - the final url for querying the solr http server is "+queryString);
|
|
131 |
URL url = new URL(queryString);
|
|
132 |
return url.openStream();
|
|
133 |
//throw new NotImplemented("0000", "HttpSolrQueryService - the method of query(SolrParams query, Set<Subject>subjects) is not for the HttpSolrQueryService. We donot need to implemente it");
|
107 |
134 |
}
|
108 |
135 |
|
109 |
136 |
|
Remove the query(String query) methods from SolrQueryService.java.