0

我正在使用数据导入处理程序 (DIH) 在 solr 中创建文档。每个文档将有零个或多个附件。附件(例如 PDF、Word 文档等)的内容被解析(通过 Tika)并与附件的路径一起存储。附件的内容(和路径)没有存储在数据库中(我不想这样做)。

我目前有一个包含 DIH 所需的所有字段的模式。然后我还添加了一个附件内容和附件路径字段作为多值。但是,当我使用 Solrj 添加文档时,solr 只存储和索引一个附件(最后添加的一个)。这是代码:

        ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update/extract");
        up.setParam("literal.id", id);

        for (MultipartFile file : files) {
            // skip over files where the client didn't provided a filename
            if (file.getOriginalFilename().equals("")) {
                continue;
            }
            File destFile = new File(destPath, file.getOriginalFilename());
            try {
                file.transferTo(destFile);

                up.setParam("literal.attachmentPath", documentWebPath + acquisition.getId() + "/" + file.getOriginalFilename());
                up.addFile(destFile);   
            } catch (IOException ioe) {
                ioe.printStackTrace();   
            }               
        }
        try {
            up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);            
            solrServer.request(up);
        } catch (SolrServerException sse) {
            sse.printStackTrace();
        }catch (IOException ioe) {
            ioe.printStackTrace();   
        }

如何让 solr 存储多个附件(内容和路径)?还是有更好的方法来实现这一点?

4

1 回答 1

1

Solr 的限制是只能使用 API 索引一个文档。
如果您想要索引多个文档,您可以将它们作为一个 zip 文件(并应用patch)并将其编入索引。

于 2012-10-25T07:14:01.757 回答