Getting the Zookeeper URL and Solr Collection Name from the Solr Component Code

I am writing a custom Solr component that uses an instance of CloudSolrServer to perform an auxiliary query on a distributed index. I am collecting the Zookeeper url and collection name from the configuration in the solrconfig.xmlusual way:

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

I would like to remove the Zookeeper url entry and the collection name entry from my file solrconfig.xml. Is it possible to get these values ​​from another place? I execute a helper request in the same collection in which my component is running. How to get the name of my collection and its Zookeeper url from component code?

+4
source share
1 answer

The zookeeper URL and collection name can be obtained using the rb( ResponseBuilder) parameter passed to each of the component methods:

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

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

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

String zookeeperUrl = zkController.getZkServerAddress();

Assuming that the user component class expands SearchComponent, the parameter rbis transmitted to each of the public methods of the component: prepare, process, distributedProcess, modifyRequest, handleResponsesand finishStage.

+4
source

All Articles