Domanda

I am having problems with indexing/persisting with SDN 2.0.0.RELEASE and Neo4j 1.5.

I have a domain class "Word" which basically looks like this:

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

I am persisting words with this method:

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

It's supposed to check if the word is already in the graph, if so i change some attributes on the object returned by the wordRepository, then persist the changes (-> if (existingWord != null)). If the word is not in the graph yet it is just persisted (-> else).

This however always creates a new node for every word, even when it exists in the graph. So to speak, persist() always creates a new node. After there are two words with the same wordString in the graph, the repository method throws:

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]'

What's going on?

I am also wondering what the difference between IndexType.SIMPLE,IndexType.POINT and IndexType.FULLTEXT is. (It's not in the API or the Good Relations guide)

È stato utile?

Soluzione 2

Alright, I found the problem:

When I persisted the words I always added them to the "words" Set of the current sentence and I set the sentence property of the Word. I think that was the reason why some words were persisted multiple times.

Altri suggerimenti

Tobias,

could you check if the findByPropertyValue that takes an index name as first parameter and pass in your "Word_wordString" index would help. Your repository has to extend then NamedIndexRepository` as well. The repository should take your custom-index name into account automatically anyway.

You might also try to leave off the separate index-name then it would default to the simple class name, aka Word which would be used automatically.

What kinds of words are you using are they just alphanumeric characters or other, chars like spaces, line-feed etc in there?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top