Is it possible to add index on existing relationships. More specifically I have a relationship called Relatadness with one property called score(score is double) and I want to index it (with java or through the web client). How can do that? thanks in advance
Asked
Active
Viewed 699 times
0
-
Which version of Neo4j are you using? Anything other then 2.0 you can manually index without any trouble. – Nicholas Sep 09 '13 at 14:26
-
Neo4j Stable Release 1.9.3 for windows..Could you please give me some instructions cause I can't find something that works properly anywhere. thank you for yuor answer. – Mary Sep 10 '13 at 12:03
1 Answers
1
Since you already have the relationships, you'll have to iterate through all of them. This code example will create an index called RelatadnessIndex
, and store the relationship in the index under a key of score
:
GlobalGraphOperations ggo = GlobalGraphOperations.at(db);
Index<Relationship> relatadnessIndex = db.index().forRelationships("RelatadnessIndex");
for (Relationship r : ggo.getAllRelationships()) {
if (r.getType().name().equals("Relatadness")) {
double score = (double) r.getProperty("score");
relatadnessIndex.add(r, "score", score);
}
}
Note that by default Neo4j/Lucene will index the value as a String, so doing numeric range searches won't work. If you want to have it stored as a Numeric, you'll need to change to add to be this:
relatadnessIndex.add(r, "score", new ValueContext( score ).indexNumeric() );

Nicholas
- 7,403
- 10
- 48
- 76