简体   繁体   English

Spring-data-solr 数据导入处理程序调用

[英]Spring-data-solr data import handler call

I'm using spring-data-solr and have data import handler(DIH) in solr.我正在使用spring-data-solr并在 solr 中有数据导入处理程序(DIH) How can I call DIH by repository or SolrTemplate, or some else?如何通过存储库或 SolrTemplate 或其他方式调用 DIH?

I'd recommend a Custom Respository using SolrCallback to execute desired request. 我建议使用SolrCallback自定义存储SolrCallback来执行所需的请求。

    @Override
    public SolrResponse dataImport(final String command) {

      return solrTemplate.execute(new SolrCallback<SolrResponse>() {

        @Override
        public SolrResponse doInSolr(SolrServer solrServer) throws SolrServerException, IOException {
          return new SolrRequest(METHOD.GET, "/dataimport?command=" + command) {

            //..skipped some methods to shorten

            @Override
            public SolrResponse process(SolrServer server) throws SolrServerException, IOException {
              SolrResponseBase response = new SolrResponseBase();
              response.setResponse(server.request(this));
              return response;
            }

          }.process(solrServer);

        }
      });
    }

If someone else is struggling to get the DIH working in the current version (Solr 8.11) - this is what worked for me (be sure to adapt the core name):如果其他人正在努力让 DIH 在当前版本(Solr 8.11)中工作 - 这对我有用(一定要调整核心名称):

        solrTemplate.execute(new SolrCallback<SolrResponse>() {
            @Override
            public SolrResponse doInSolr(SolrClient solrClient) throws SolrServerException, IOException {

                SolrRequest<SolrResponse> solrRequest = new SolrRequest<>(SolrRequest.METHOD.GET, "/<core_name>/dataimport?command=full-import&commit=true&clean=true") {
                    @Override
                    public SolrParams getParams() {
                        return null;
                    }

                    @Override
                    protected SolrResponse createResponse(SolrClient solrClient) {
                        SolrResponseBase response = new SolrResponseBase();
                        try {
                            response.setResponse(solrClient.request(this));
                        } catch (SolrServerException | IOException e) {
                            throw new RuntimeException(e);
                        }
                        return response;
                    }
                };

                solrRequest.setResponseParser(new DelegationTokenResponse.JsonMapResponseParser());
                return solrRequest.process(solrClient);

            }
        });

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

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