I'm writing a custom Solr component which is using a CloudSolrServer instance to execute an auxilary query on the distributed index. I'm fetching the Zookeeper url and the collection name from the solrconfig.xml configuration in the usual way:

String zookeeper = params.get(ZOOKEEPER_URL);
String collection = params.get(COLLECTION_NAME);

I would like to erase the Zookeeper url entry and the collection name entry from my solrconfig.xml file. Is it possible to fetch those values from somewhere else? I'm executing the auxilary query on the same collection that my component is running on. How do I get my collection name and its Zookeeper url from within the component code?

有帮助吗?

解决方案

The zookeeper url and the collection name can be fetched by using the rb (ResponseBuilder) parameter passed to each of the component's methods:

CoreDescriptor coreDescriptor = rb.req.getCore().getCoreDescriptor();

String collectionName = coreDescriptor.getCloudDescriptor().getCollectionName();

ZkController zkController = coreDescriptor.getCoreContainer().getZkController();

String zookeeperUrl = zkController.getZkServerAddress();

Assuming the custom component class extends SearchComponent, the rb parameter is passed to each of the component's public methods: prepare, process, distributedProcess, modifyRequest, handleResponses and finishStage.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top