SDN 2.0.0.RELEASE および Neo4j 1.5 でのインデックス作成/永続化に問題があります。
基本的に次のようなドメインクラス「Word」があります。
@NodeEntity
public class Word {
@GraphId
Long graphId;
@Indexed(indexType = IndexType.SIMPLE, indexName = "Word_wordString")
private String wordString;
@RelatedTo(direction = Direction.INCOMING, elementClass = Sentence.class, type = "HAS")
private Set<Sentence> sentences;
public Word() {
}
public Word(String wordString) {
setWordString(wordString);
}
}
私はこの方法で単語を永続化しています:
private void persistWord(Sentence sentence, Word word) {
System.out.println("checking index for wordString: "
+ word.getWordString());
Word existingWord = wordRepository.findByPropertyValue(
"wordString", word.getWordString());
if (existingWord != null) {
existingWord.addSentence(sentence);
existingWord.persist();
System.out.println("persisted already existing word "
+ existingWord);
} else {
word.persist();
System.out.println("persisted word " + word);
}
単語が既にグラフにあるかどうかを確認することになっています。そうであれば、wordRepository によって返されたオブジェクトのいくつかの属性を変更し、変更を永続化します (-> if (existingWord != null))。単語がまだグラフに含まれていない場合は、永続化されます (-> else)。
ただし、これにより、グラフに存在する場合でも、常にすべての単語に対して新しいノードが作成されます。つまり、persist() は常に新しいノードを作成します。グラフに同じ wordString を持つ 2 つの単語があると、リポジトリ メソッドは次をスローします。
More than one element in org.neo4j.index.impl.lucene.LuceneIndex$1@1181df3. First element is 'Node[45]' and the second element is 'Node[83]'
どうしたの?
また、IndexType.SIMPLE,IndexType.POINT と IndexType.FULLTEXT の違いは何だろうと思っています。(API や Good Relations ガイドにはありません)