2013-03-11 6 views

답변

7

이 문제에 대해서는 ClientUtils.toQueryString을 권장합니다. 당신이이 이유로 Solrj 코드 자체에 의해 사용되는 것을 볼 수 있습니다 HttpSolrServer의 소스 코드 내에서

@Test 
public void solrQueryToURL() { 
    SolrQuery tmpQuery = new SolrQuery("some query"); 
    Assert.assertEquals("?q=some+query", ClientUtils.toQueryString(tmpQuery, false)); 
} 

.

public NamedList<Object> request(final SolrRequest request, final ResponseParser processor) throws SolrServerException, IOException { 

    // ... other code left out 

    if(SolrRequest.METHOD.GET == request.getMethod()) { 
    if(streams != null) { 
     throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "GET can't send streams!"); 
    } 
    method = new HttpGet(baseUrl + path + ClientUtils.toQueryString(params, false)); 

    // ... other code left out 

    } 
1

SolrJ (시험 버전 6.6.0)가 그 것이다 :

@Test 
public void solrQueryToURL() { 
    SolrQuery query = new SolrQuery("query"); 
    Assert.assertEquals("?q=query", query.toQueryString()); 
} 
관련 문제