首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >persist()总是创建新节点

persist()总是创建新节点
EN

Stack Overflow用户
提问于 2012-02-01 00:00:38
回答 2查看 477关注 0票数 0

我在使用SDN2.0.RELEASE和Neo4j 1.5时遇到了索引/持久化问题。

我有一个域名类"Word“,它基本上看起来像这样:

代码语言:javascript
复制
@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);
}
}

我用这种方法持久化单词:

代码语言:javascript
复制
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))。如果单词还没有出现在图中,那么它就会被持久化(->否则)。

然而,这总是为每个单词创建一个新节点,即使它存在于图中。可以这么说,persist()总是创建一个新节点。在图中有两个单词具有相同的wordString后,存储库方法抛出:

代码语言:javascript
复制
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或良好关系指南中)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-02-20 08:06:27

好了,我找到问题了:

当我持久化单词时,我总是将它们添加到当前句子的“单词”集中,并设置单词的句子属性。我想这就是为什么有些词会被重复使用的原因。

票数 0
EN

Stack Overflow用户

发布于 2012-02-05 07:16:42

托拜厄斯

您能否检查一下,将索引名作为第一个参数并传入"Word_wordString“索引的findByPropertyValue是否会有所帮助。您的存储库还必须扩展NamedIndexRepository`。无论如何,存储库都应该自动考虑您的自定义索引名称。

您也可以尝试去掉单独的索引名,然后它将默认为简单的类名,也就是Word,它将被自动使用。

您使用的是什么类型的单词?它们只是字母数字字符还是其他字符,如空格、换行符等?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9082686

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档