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

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

问题描述

我非常需要在Solr中进行条件更新,这在MySQL中很容易完成。

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

例如,


  • 我有100个文档,其唯一字段称为< id>

  • 我正在发布10个文档,其中一些文档可能是重复的< id> s,在这种情况下,Solr会使用相同的更新现有记录。 < id> s

  • 我有一个名为< dateCreated> 的字段,仅当新的< dateCreated> 比旧的< doc> >< dateCreated> (当然,这仅适用于重复的< id> s)

  • 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?

上下文正在努力应对导致多种多样的比赛条件

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. 放置适当的锁(关键部分)以获取存储的文档,比较日期并有条件地以线程安全的方式添加新文档。

  1. Write your own UpdateHandler and override addDoc to implement that checking.
  2. Put the appropriate locks (critical sections) in your client code in order to fetch the stored document, compare the dates, and conditionally add the new document in a thread-safe manner.

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

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

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

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