索引多个类并确保文档唯一性

索引多个类并确保文档唯一性

本文介绍了SolrJ - 索引多个类并确保文档唯一性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用SolrJ来索引一组Java类。每个类实例由其id确定,该id在类中是唯一的。但是,通过使用Solr @Field批注从这些类生成Solr文档,事实证明此批注不保证存储在Solr索引中的已创建文档的唯一性(相同的id值可能属于多个类)。

I want to use SolrJ for indexing a set of Java classes. Each class instance is determined by its id which is unique within a class. However, by using the Solr @Field annotation for making Solr documents from these classes it turns out that this annotation doesn't guarantee uniqueness of the created documents stored in the Solr index (same id values may belong to multiple classes).

我尝试将注释方法与Solr UUID数据类型相结合,以便在solr模式中的指定字段中生成唯一的id值,但没有成功。

I tried combining the annotation approach with the Solr UUID data type for generating unique id values into a specified field in the solr schema, but with no success.

结果,我创建了一个简单的注释机制,与SolrJ没有太大的不同,它保证了多个类的唯一性。这是通过组合对象类名和它的id来获得一种UUID,然后存储在Solr模式中。

As a result, I created a simple annotation mechanism not so different from the SolrJ one, which guarantees uniqueness across multiple classes. This is done by combining object class name and its id to get a sort of UUID which is then stored in the Solr schema.

我不确定我是不是不要错过任何东西,所以我想知道上面描述的工作解决方案是否足够适合我的情况,或者是否有更清洁/更好的选择。

I'm not sure if I'm not missing something, so I would like to know if the working solution described above is good enough for my case or if there are any cleaner/better alternatives.

推荐答案

我认为这是一种有效的方法。我们在我们的位置做了类似的多个索引。例如,我们在数据库中有4种不同类型的项目,我们将它们加载到索引中的公共模式中,并且我们在数据库表id前面加上该类型的前两个唯一字母,以确保它是唯一的。

I think this is a valid approach. We are doing something similar with multiple indexes at our location. For example we have 4 different types of items in our database that we are loading into a common schema in the index and we prefix the database table id with the first two unique letters of the type to ensure that it will be unique.

同样,IMO,在一个索引中索引多个不同类型实际上是一个偏好而不是经验法则,如下面的链接所示

Also IMO, indexing multiple distinct types in one index is really a preference and not a rule of thumb as indicated in the links below




  • Single schema versus multiple schemas in solr for different document types
  • Running Multiple Indexes

这篇关于SolrJ - 索引多个类并确保文档唯一性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 20:24