简体   繁体   English

在Solr中使用ContentStreamUpdateRequest设置多值字段

[英]Set multivalued fields with ContentStreamUpdateRequest in Solr

I'm using SolrJ+SolrCell to index the contents of various Word/Excel/PDF files, but there are some fields (eg id, name) that I want to be able to set myself: 我正在使用SolrJ + SolrCell为各种Word / Excel / PDF文件的内容建立索引,但是我希望能够设置一些字段(例如id,name):

ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update/extract");
req.addFile(docFile, null);
req.setParam("literal.id", docProperties.getId());
req.setParam("literal.name", docProperties.getName());

I am not having any issues with normal fields, but I find that when I try using this same setParam method to set multivalued fields, only the last element in the input array is stored: 我对普通字段没有任何问题,但是我发现当我尝试使用相同的setParam方法设置多值字段时,仅存储输入数组中的最后一个元素:

if (docProperties.getCategories() != null) {
    for (String category : docProperties.getCategories()) {
        req.setParam("literal.categories", category);
    }
}

For example, if docProperties.getCategories() is ["News", "Computers", "Tech"], the only value stored in the multivalued category field is ["Tech"]. 例如,如果docProperties.getCategories()是[“ News”,“ Computers”,“ Tech”],则存储在多值类别字段中的唯一值是[“ Tech”]。 I'm actually not too surprised by this, since I don't think using the setParam method is the proper way to append values to a multivalued field. 实际上我对此并不感到惊讶,因为我认为使用setParam方法不是将值附加到多值字段的正确方法。

However, I am at a loss as to how to do this using available ContentStreamUpdateRequest methods. 但是,我不知道如何使用可用的ContentStreamUpdateRequest方法来执行此操作。 If I was working with a SolrInputDocument, then it'd be a simple matter of passing an array to the addField method. 如果我正在使用SolrInputDocument,那么将数组传递给addField方法addField简单了。

String[] categoriesArray = {"News", "Computers", "Tech"};
ArrayList<String> categories = new ArrayList<String>(Arrays.asList(categoriesArray));
doc.addField("categories", categories );

Is there a way to do this same sort of thing using ContentStreamUpdateRequest? 有没有一种方法可以使用ContentStreamUpdateRequest来做同样的事情?

http://wiki.apache.org/solr/ExtractingRequestHandler#SolrJ ,使用ModifiableSolrParams设置这些文字参数可用于多值字段。

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

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