Solr,如何在SolrJ中使用新的字段更新模式(原子更新) [英] Solr, how to use the new field update modes (atomic updates) with SolrJ

查看:518
本文介绍了Solr,如何在SolrJ中使用新的字段更新模式(原子更新)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Solr 4.x具有这个不错的新功能,可让您指定在对现有文档进行更新时如何更新multiValued字段.具体来说,您可以说更新文档是用新值替换多值字段的旧值,还是应该将新值附加到现有值上.

Solr 4.x has this nice new feature that lets you specify how, when doing an update on an existing document, the multiValued fields will be updated. Specifically, you can say if the update document will replace the old values of a multivalued field with the new ones, or if it should append the new values to the existing ones.

我已经使用请求处理程序尝试过此操作,如下所述:

I've tried this using the request handler, as described here:

http://wiki.apache.org/solr/UpdateXmlMessages#Optional_attributes_for_. 22field.22

我已经使用curl来发送xml,其中某些字段使用了update=add选项:

I've used curl to send xml where some fields used the update=add option:

<field name="skills" update="add">Python</field>

这按预期工作.

但是我无法通过Java API(SolrJ)做到这一点.

However I can't get how to do this the Java API (SolrJ).

如果我做这样的事情:

SolrInputDocument doc1 = new SolrInputDocument();
doc1.setField("ID_VENTE", "idv1");
doc1.setField("FACTURES_PRODUIT", "fp_initial");
solrServer.add(doc1);
solrServer.commit();

SolrInputDocument doc2 = new SolrInputDocument();
doc2.setField("ID_VENTE", "idv1");
doc2.setField("FACTURES_PRODUIT", "fp_2");    
solrServer.add(doc2);
solrServer.commit();

字段"FACTURES_PRODUIT"的值变为"fp_2"(初始值丢失). 我也尝试过:

The value for the field "FACTURES_PRODUIT" becomes "fp_2" (the initial value is lost). I've also tried:

doc2.addField("FACTURES_PRODUIT", "fp_2");  

,但结果是相同的.我还研究了 SolrInputField 类,但未找到与此类似的内容.

but the result is the same. I've also looked into the SolrInputField class but haven't found anything similar to this.

所以,我的问题是,如何通过附加(而不是替换)新值来使用Solr 4 Java API将值更新为multiValued字段?

So, my question is, how can I use the Solr 4 Java API to updated values into a multiValued field by appening (not replacing) the new values?

推荐答案

好,我在调试了一点SolrJ代码后解决了它.您必须这样做:

Ok, I solved it after debugging a bit the SolrJ code. You have to do this:

    SolrInputDocument doc2 = new SolrInputDocument();
    Map<String,String> fpValue2 = new HashMap<String, String>();
    fpValue2.put("add","fp2");        
    doc2.setField("FACTURES_PRODUIT", fpValue2);

这篇关于Solr,如何在SolrJ中使用新的字段更新模式(原子更新)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆