Solr 条件添加/更新? [英] Solr conditional adds/updates?

查看:36
本文介绍了Solr 条件添加/更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当简单的需求,需要在 Solr 中进行条件更新,这在 MySQL 中很容易完成.

I have a fairly simple need to do a conditional update in Solr, which is easily accomplished in MySQL.

例如

  • 我有 100 个文档,其中有一个名为
  • 的唯一字段
  • 我要发布 10 个文档,其中一些可能是重复的 s,在这种情况下 Solr 将使用相同的 更新现有记录>s
  • 我有一个名为 的字段,如果新的 ,我只想更新 code> 比旧的 大(当然,这仅适用于重复的 )
  • I have 100 documents with a unique field called <id>
  • I am POSTing 10 documents, some of which may be duplicate <id>s, in which case Solr would update the existing records with the same <id>s
  • I have a field called <dateCreated> and I would like to only update a <doc> if the new <dateCreated> is greated than the old <dateCreated> (this applies to duplicate <id>s only, of course)

我怎样才能完成这样的事情?

How would I be able to accomplish such a thing?

上下文试图解决竞争条件,导致对同一 ID 进行多次添加但执行顺序错误.

The context is trying to combat race conditions resulting in multiple adds for the same ID but executing in the wrong order.

谢谢.

推荐答案

我想到了两种方法:

  1. 编写您自己的 UpdateHandler 并覆盖 addDoc 来实现该检查.
  2. 在您的客户端代码中放置适当的锁(关键部分),以便获取存储的文档、比较日期并以线程安全的方式有条件地添加新文档.

请记住,Solr 不是数据库,将其与 MySQL 进行比较是在比较苹果和橘子.

Remember that Solr is not a database, comparing it to MySQL is comparing apples and oranges.

这篇关于Solr 条件添加/更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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