5

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

For example,

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

Thanks.

4

3 に答える 3

2

次の 2 つの方法が考えられます。

  1. 独自UpdateHandlerに記述してオーバーライドaddDocし、そのチェックを実装します。
  2. 適切なロック (クリティカル セクション) をクライアント コードに配置して、格納されたドキュメントをフェッチし、日付を比較し、新しいドキュメントをスレッド セーフな方法で条件付きで追加します。

Solr はデータベースではないことに注意してください。それを MySQL と比較することは、リンゴとオレンジを比較することです。

于 2009-08-15T03:34:03.917 に答える
1

このような本当にカスタムの追加ロジックを使用すると、独自のクライアント側アップデーターを作成する方がうまくいくことがわかりました。これにより、Solr の内部をいじる必要がなくなり、将来の更新が容易になります。これは間違いなく SolrJ で行うことができますが、Java 開発者でない場合は、おそらくお好みの言語のクライアント側ライブラリがあります... PHP、Python、Ruby、C# など...

rsolr Ruby gem ( http://github.com/mwmitchell/rsolr/tree/master ) を使用すると、カスタム ロード スクリプトを簡単にハックできます。

于 2009-08-18T20:42:29.090 に答える