使用SolrJ为丰富的文档建立索引-搜索处理程序的contentType不好

时间:2019-05-15 12:55:21

标签: maven solr solrj

我正在尝试使用SolrJ使用Solr为Word和PDF文档建立索引,但是我在互联网上找到的大多数示例都使用SolrServer类,我认为现在已经弃用了该类。 与Solr本身的连接正在工作,因为我可以将SolrInputDocuments添加到索引,但是由于出现异常,它不适用于丰富的文档。

public static void main(String[] args) throws IOException, SolrServerException {
    String urlString = "http://localhost:8983/solr/localDocs16";
    HttpSolrClient solr = new HttpSolrClient.Builder(urlString).build();

    //is working
    /for(int i=0;i<1000;++i) {
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("cat", "book");
        doc.addField("id", "book-" + i);
        doc.addField("name", "The Legend of the Hobbit part " + i);
        solr.add(doc);
        if(i%100==0) solr.commit();  // periodically flush
    }

    //is not working
    File file = new File("path\\testfile.pdf");

    ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("update/extract");

    req.addFile(file, "application/pdf");
    req.setParam("literal.id", "doc1");
    req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
    try{
        solr.request(req);
    }
    catch(Exception e){
        System.out.println(e.getClass().getName() + "message: " + e.getMessage());
    } finally{
        solr.commit();
    }
}

我正在使用Maven并创建了一个JAR文件,然后尝试从命令行运行该文件,并且收到了搜索处理程序:application / pdf 的 Bad contentType错误的RemoteSolrException消息:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".
SLF4J: Defaulting to no-operation MDCAdapter implementation.
SLF4J: See http://www.slf4j.org/codes.html#no_static_mdc_binder for further details.
RemoteSolrException message: Error from server at http://localhost:8983/solr/localDocs16: Bad contentType for search handler :application/pdf request={waitSearcher=true&literal.id=doc1&commit=true&softCommit=false&wt=javabin&version=2}

0 个答案:

没有答案