您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何将SolrQuery(SOLRJ)转换为URL?

如何将SolrQuery(SOLRJ)转换为URL?

对于此问题,我建议使用ClientUtils.toQueryString

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

在源代码HttpSolrServer你可以看到,这是使用的Solrj代码本身这个原因。

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

  }
Solr 2022/1/1 18:27:55 有403人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶