用于部分文档更新的 solrj api [英] solrj api for partial document update

查看:24
本文介绍了用于部分文档更新的 solrj api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Solr 4 测试版已经发布,GA 版本即将推出.如此处所述,部分文档更新已经存在一段时间了:http://solr.pl/en/2012/07/09/solr-4-0-partial-documents-update/

Solr 4 beta is out, the GA version will follow soon. Partial document updates has been around for a while as explained here: http://solr.pl/en/2012/07/09/solr-4-0-partial-documents-update/

然而,我还没有想出如何用 solrj api 来做到这一点.

However, I haven't figured out how to do it with solrj api.

有谁知道 solrj 是否可行?或者 solrj 只是没有跟上这个功能的速度?

Does anyone knows if it is possible with solrj? Or is solrj just not up-to-speed with this feature?

更新:正如我在邮件列表中所描述的(见回复 此处),我发现在 solrj api 中, SolrInputField 的值可以是一个映射 - 它没有简单的值.如果是地图,solrj 会向字段的 xml 元素添加一个额外的 update 属性.例如,这段代码:

update: as I describe in the mailing list (see reply here), I found that in the solrj api, the value of a SolrInputField can be a map - it doesn't have to be a simple scalar value. If it is a map, solrj adds an additional update attribute to the field's xml element. For example, This code:

SolrInputDocument doc = new SolrInputDocument();
Map<String, String> partialUpdate = new HashMap<String, String>();
partialUpdate.put("set", "foo");
doc.addField("id", "test_123");
doc.addField("description", partialUpdate);

产生这个文件:

<doc boost="1.0">
    <field name="id">test_123</field>
    <field name="description" update="set">foo</field>
</doc>

在这个例子中,我对这个附加属性使用了set"这个词,但它不起作用.Solr 没有像我预期的那样更新该字段.根据这个链接:http://solr.pl/en/2012/07/09/solr-4-0-partial-documents-update/有效值为设置"和添加".

In this example I used the word "set" for this additional attribute, but it doesn't work. Solr doesn't update the field as I expected. According to this link: http://solr.pl/en/2012/07/09/solr-4-0-partial-documents-update/ valid values are "set" and "add".

有什么想法吗?

推荐答案

事实证明,上面问题中显示的代码片段确实有效.我第一次尝试时不知道出了什么问题,也许我只是忘记提交或我的架构配置错误.

As it turns out, the code snippet shown above in the question actually works. I don't know what was wrong the first time I tried it, perhaps I simply forgot to commit or my schema was misconfigured.

无论如何,这个问题非常本地化.但是,由于带有哈希映射的 api 的文档记录很差,我认为保留这个问题和答案可能是值得的.

In any case, this question is very localized. However, since the api with the hash map is so poorly documented, I thought maybe it is worth to keep this question and answer.

哈希映射的键可以是三个值之一:

The key of the hash map can be one of three values:

  • set - 设置字段.
  • add - 添加到多值字段.
  • inc - 增加一个字段.

在 solrj 单元测试中有此代码的示例,在名为 testUpdateField 的方法中.

There is an example of this code in the solrj unit tests, in a method called testUpdateField.

这篇关于用于部分文档更新的 solrj api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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