我遇到索引问题/使用SDN 2.0.0.RELEASE和Neo4j 1.5存在问题。persist()始终创建新节点
我有一个域类“字”基本上是这样的:
@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在图中,库方法抛出:
More than one element in [email protected] First element is 'Node[45]' and the second element is 'Node[83]'
这是怎么回事?
我也想知道IndexType.SIMPLE,IndexType.POINT和IndexType.FULLTEXT之间的区别是什么。 (这不是API或良好关系的指南)
我已经让我的WordRepository扩展了GraphRepository和NamedIndexRepository并使用了'wordRepository.findByPropertyValue(“Word_wordString”,“wordString”,word.getWordString());'来检查现有的单词。 代码与我原来的问题相同,除了检查索引的行外。会发生什么是,一个单词首次被持续存在时,索引将如预期返回null,新单词将被保留。第二次,索引按预期返回一个对象实例。然而,第三次索引抛出了与我原来的问题相同的例外。 – Tobias 2012-02-07 22:08:38
因此,我认为,坚持方法总是在索引中创建一个新节点和或条目!我会检查这些单词包含哪些字符,但为了测试目的,我们在初始设置时将它们全部修剪。 – Tobias 2012-02-07 22:12:49