简体   繁体   English

从solrj获取请求URL

[英]Get request url from solrj

I am using to solrj to query an index and at times kick off a reindex. 我正在使用solrj查询索引,有时会启动重新索引。

We are having some server issues, so I want to verify the url solrj is constructing. 我们遇到了一些服务器问题,因此我想验证url solrj是否正在构建。 This is what I have tried: 这是我尝试过的:

public void indexSolr() throws SolrServerException, IOException {
    HttpSolrServer solr = new HttpSolrServer(solrIndexPath);
    logger.info("Indexing cp solr at " + solrIndexPath);

    // reindex to pickup new articles
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("qt", "/" + solrDataImportPath);
    params.set("command", "full-import");
    params.set("clean", "true");
    params.set("commit", "true");
    QueryResponse response = solr.query(params);
    logger.info("index url: " + response.getRequestUrl());
}

The problem is in that last line. 问题出在最后一行。 getRequestUrl() is always null. getRequestUrl()始终为null。 I know solrj is indeed calling solr, because it does in fact kick off an index request (most of the time). 我知道solrj确实在调用solr,因为它实际上启动了索引请求(大部分时间)。

How can I intercept or retrieve the url solrj is constructing for my request? 如何截获或检索solrj为我的请求构造的URL?

As described in How can I transform SolrQuery(SOLRJ) to URL? 我如何将SolrQuery(SOLRJ)转换为URL中所述。 you can use ClientUtils.toQueryString for this matter. 您可以为此使用ClientUtils.toQueryString

In the javadoc you can see that this helper methods accepts SolrParams as input, which is what you have. 在javadoc中,您可以看到此辅助方法接受SolrParams作为输入,这就是您所拥有的。 To get the full URL you will need to concatenate this with the solrIndexPath you have in your code sample. 要获取完整的URL,您需要将其与代码示例中的solrIndexPath连接起来。

System.out.println(solrIndexPath + ClientUtils.toQueryString(params, false));

should do the trick. 应该可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM