Solr有条件的添加/更新?

编程入门 行业动态 更新时间:2024-10-23 17:24:03
本文介绍了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> 比旧的< 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.

谢谢。

推荐答案

我可以想到两种方式:

  • 编写自己的 UpdateHandler 并覆盖 addDoc 以实施该检查。
  • 放置适当的锁(关键部分)以获取存储的文档,比较日期并有条件地以线程安全的方式添加新文档。
  • Write your own UpdateHandler and override addDoc to implement that checking.
  • 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有条件的添加/更新?

    本文发布于:2023-10-23 06:00:05,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1520000.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:有条件   Solr

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!