Project

General

Profile

« Previous | Next » 

Revision 7719

Added by Jing Tao over 11 years ago

Remove the query(String query) methods from SolrQueryService.java.

View differences:

metacat-common/src/main/java/edu/ucsb/nceas/metacat/common/query/EmbeddedSolrQueryService.java
92 92
     * @return the response
93 93
     * @throws Exception
94 94
     */
95
    public InputStream query(String query, Set<Subject>subjects) throws Exception {
95
    /*public InputStream query(String query, Set<Subject>subjects) throws Exception {
96 96
        throw new NotImplemented("0000", "EmbeddSolrQueryService - the method of  query(String query, Set<Subject>subjects) is not for the EmbeddedSolrServer. We donot need to implemente it");
97
    }
97
    }*/
98 98
    
99 99
    /**
100 100
     * Query the Solr server with specified query and user's identity. If the Subjects
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.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
    
metacat-common/src/main/java/edu/ucsb/nceas/metacat/common/query/SolrQueryService.java
82 82
     * @return the response
83 83
     * @throws Exception
84 84
     */
85
    public abstract InputStream query(String query, Set<Subject>subjects) throws Exception;
85
    //public abstract InputStream query(String query, Set<Subject>subjects) throws Exception;
86 86
    
87 87
    /**
88 88
     * Query the Solr server with specified query and user's identity. If the Subjects
metacat-common/src/main/java/edu/ucsb/nceas/metacat/common/query/SolrQueryServiceController.java
108 108
     * @throws ParserConfigurationException 
109 109
     * @throws UnsupportedType 
110 110
     */
111
    public InputStream query(String query, SolrParams params,Set<Subject>subjects) throws NotImplemented, NotFound, IOException, UnsupportedType, ParserConfigurationException, SAXException, SolrServerException  {
111
    public InputStream query(SolrParams params,Set<Subject>subjects) throws NotImplemented, NotFound, IOException, UnsupportedType, ParserConfigurationException, SAXException, SolrServerException  {
112 112
        if(isEmbeddedSolrServer) {
113 113
            return embeddedQueryService.query(params, subjects);
114 114
        } else {
115
            return httpQueryService.query(query, subjects);
115
            return httpQueryService.query(params, subjects);
116 116
        }
117 117
      
118 118
    }

Also available in: Unified diff