gpt4 book ai didi

solr - 使用 setQueryType 通过 SolrJ 访问核心的默认处理程序

转载 作者:行者123 更新时间:2023-12-02 00:08:14 24 4
gpt4 key购买 nike

我在实例上有几个 Solr 核心,每个核心都有一个 StandardRequestHandler 和一些配置的自定义请求处理程序,例如:

<requestDispatcher handleSelect="true" >
<requestParsers enableRemoteStreaming="false" multipartUploadLimitInKB="2048" />
</requestDispatcher>
...
<requestHandler name="standard" class="solr.StandardRequestHandler" default="true" />
...
<requestHandler name="/custom" class="com.example.our.package.CustomHandler" />
...

我希望能够通过 SolrJ 访问它们,但是,我只能通过设置 HttpSolrServerbaseUrl 属性来实现> 对象。然而,这是不可取的,因为 HttpSolrServer 实例在多个线程之间共享,因此会出现竞争条件。另一个原因是团队的共识在于 HttpSolrServerSingleton - 为简单起见

我试过的是这样的:

HttpSolrServer server = new HttpSolrServer("http://URL_OF_SOLR:PORT/solr/");
SolrQuery query = new SolrQuery();
query.setQueryType("/core/custom");

这适用于自定义处理程序,但是在调用 /select 时失败并显示代码 400,至少对于我尝试过的 URLs (/core, /core/select, /core/, /core/standard)等

所以我的问题是:我应该如何定义此查询以正确引用核心的默认请求处理程序,仅使用 queryType 或其他一些 SolrParams 值?

最佳答案

您可以在 Solr 中使用 qt 参数来指定特定的请求处理程序,甚至是默认的 /select 处理程序。参见 CoreQueryParameters有关其工作原理的详细信息。 SolrJ 通过在 SolrQuery 类上使用 setRequestHandler 方法来支持这一点。

一些示例,假设您的 Solr 实例位于 http://localhost:8983/solr 并且您有两个名为 core0core1 .

  • http://localhost:8983/solr/core0/select?q=*:* 默认使用 /select
  • http://localhost:8983/sole/core1/select?q=*:*&qt=terms 这使用术语 requestHandler

最后,核心名称不应包含在 qt 参数 b/c 中,该参数旨在支持在核心中选择命名的 requestHandler。 Solr 实例的 Url 中应该有核心名称,因为每个核心都是它自己的 Solr 实例,因此应该这样对待,IMO。来自 SolrCore 维基页面:

Multiple cores let you have a single Solr instance with separate configurations and indexes, with their own config and schema for very different applications, but still have the convenience of unified administration.

所以定义多个HttpSolrServer实例。

 new HttpSolrServer(http://localhost:8983/solr/core0)
new HttpSolrServer(http://localhost:8983/solr/core1)

关于solr - 使用 setQueryType 通过 SolrJ 访问核心的默认处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17026530/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com