Spring Data Neo4j-索引和继承 [英] Spring Data Neo4j - Indexing and Inheritance

查看:306
本文介绍了Spring Data Neo4j-索引和继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我说我有以下数据模型:

Lets say i have the following data model:

public class A {

    @Indexed(indexType = IndexType.FULLTEXT, indexName = "property1")
    String property1;
}

public class B extends A {

    @Indexed(indexType = IndexType.FULLTEXT, indexName = "property2")
    String property2;
}

我可以告诉Spring框架以不同的索引名称对B类的property1进行索引吗? 如果没有,您将在这种情况下怎么办?我的意思是,如果只有少数几个类都扩展了相同的基类,但同时又应索引这些类从基类继承的所有属性,该怎么办.我只能为基类中的索引注释这些属性,这是非常有限的.我该怎么办?

Can i tell the Spring framework to index property1 of class B under a different index name? If not, what would you do in such case? I mean, what would you do if you have few classes that all extends the same base class, but in the same time, all the properties that those classes inherit form the base class should be indexed. I can annotate those properties for indexing only in the base class, and it is very limiting. What can i do?

谢谢.

推荐答案

我认为这是不可能的.您的property1将始终在索引property1中建立索引.能够在单个字段上指定多个索引可能会解决您的问题,但目前尚无法解决.不久前,我为此提出了一个问题,但尚未实现.

I don't think that's possible. Your property1 will always be indexed in index property1. Being able to specify multiple indexes on a single field would probably fix your issue, but it's currently not possible. A while ago, I've raised an issue for this, but it's not yet implemented.

如果您确实希望使用域(实体)对象方法,则还可以选择域实体方法.它与Spring或Spring Data Neo4j无关,但也可以解决问题.通过以这种方式手动处理实体,您还可以自己管理索引,从而获得所需的所有灵活性.

If you really want a domain (entity) object approach, you could also opt for the domain entity approach. It's not related to Spring or Spring Data Neo4j, but it also does the trick. By manually handling your entities this way, you could also manage the indexes yourself, thus gaining all the flexibility you want.

只是一个问题,为什么要为每个子类指定一个不同的索引?

Just a question, why would you want to specify a different index per subclass?

这篇关于Spring Data Neo4j-索引和继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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