1
votes

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;
}

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?

Thanks.

2
Which approach did you choose? Please approve one of the answers if you've used them.tstorms
I'm actually still playing with it, that's why i still didn't accept an answer. I will go more deeply today inside the Level.INSTANCE suggestion to see if it really answer my needs, because as i wrote, i didn't see any influence when i tried it the last time. I will accept one of the answers tonight or tomorrow.gipouf

2 Answers

2
votes

The level attribute in the index definition annotation can be set to Level.INSTANCE. For more help please refer spring-data-neo4j documentation here

Here is an excerpt from the doc :

If a field is declared in a superclass but different indexes for subclasses are needed, the level attribute declares what will be used as index. Level.CLASS uses the class where the field was declared and Level.INSTANCE uses the class that is provided or of the actual entity instance.

0
votes

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.

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?