1

我正在尝试向运行 Solr 的服务器发送查询,如下所示:

String solrServerUrl = //SomeBaseUrl
CommonsHttpSolrServer searchServer = new CommonsHttpSolrServer("http://"+solrServerUrl);
QueryResponse result = searchServer.query(query,SolrRequest.METHOD.POST);

在我发送到 Solr 服务器的查询请求中,我将 sessionId 字符串附加如下(用于记录目的):

String solrServerUrl = SomeBaseUrl.concat("?sessionId");

当我运行服务器时,出现以下异常:

嵌套异常是 java.lang.RuntimeException: solrj 的基 URL 无效。基本 URL 不得包含参数

有人能指出我如何将唯一的会话 ID 转发到 Solr 服务器,以便目标 Solr 服务器中设置的 tomcat 阀门选择会话 ID 以进行日志记录吗?

谢谢

4

1 回答 1

1

我认为实际CommonsHttpSolrServer代码不可能采用这种方式,无论您使用的是 POST 还是 GET 都没有关系(即使 rfeak 的评论看起来不错)。

在主CommonsHttpSolrServer构造函数中有这样的条件:

if( _baseURL.indexOf( '?' ) >=0 ) {
    throw new RuntimeException( "Invalid base url for solrj.  The base URL must not contain parameters: "+_baseURL );
}

I would try using the SolrQuery#setParam method. This way you might be able to add additional request parameters, which should just be ignored by the Solr request handler.

于 2011-12-12T19:30:01.113 回答