2013-03-08 58 views
0

我已經創建了一個Java項目這樣一個嵌入式的Neo4j:的Cypher查詢找不到節點

graphDb = new GraphDatabaseFactory() 
      .newEmbeddedDatabaseBuilder("db") 
      .setConfig(GraphDatabaseSettings.node_keys_indexable, "movieId, userId, rating, genre") 
      .setConfig(GraphDatabaseSettings.node_auto_indexing, "true") 
      .newGraphDatabase(); 

我已驗證創建了索引,並且它有我所期望的名字:

Index<Node> index = graphDb.index().forNodes("movieId"); 
System.out.println("::: Verify Index Name :::"); 
System.out.println(index.getName()); 

控制檯顯示:

::: Verify Index Name ::: 
movieId 

我可以使用Java API

找到節點
ReadableIndex<Node> graphDbIndex = graphDb.index().getNodeAutoIndexer().getAutoIndex(); 
Node movie = graphDbIndex.get("movieId", 2).getSingle(); 
System.out.println("::: Get with Java API Result :::"); 
System.out.println("MovieId: " + movie.getProperty("movieId")); 
System.out.println("Title: " + movie.getProperty("title")) 

控制檯顯示

::: Get with Java API Result ::: 
MovieId: 2 
Title: Jumanji (1995) 

但是,當我嘗試用暗號是這樣的結果

ExecutionEngine engine = new ExecutionEngine(graphDb); 
ExecutionResult result = engine.execute("start movie=node:movieId(movieId='2') return movie, movie.title"); 
System.out.println("::: get with Cypher Result :::"); 
System.out.println(result); 

控制檯顯示

::: get with Cypher Result ::: 
+---------------------+ 
| movie | movie.title | 
+---------------------+ 
+---------------------+ 
0 row 
8 ms 

我做得非常錯誤或我只是錯過了一些明顯的東西?

謝謝。

+0

我想你混淆了索引的名字是'node_auto_index'索引的屬性名'「movieId,用戶id,分級,流派」'。 – 2013-03-10 09:10:24

回答

3

id是一個字符串嗎?嘗試像這樣與Lucene索引語法:

start movie=node:node_auto_index('movieId:2') 
return movie, movie.title 
+0

嘗試了您的建議,但仍返回0行'movieId:2'。 movieId值是長類型。 – C0deAttack 2013-03-08 01:02:25

+0

哦,我看到你正在使用自動索引器...更新了我的答案。 – 2013-03-08 01:04:46

+1

啊!謝謝,我現在有預期的結果。你能解釋爲什麼'movieId:2'有效,但是movieId ='2'不正確嗎? – C0deAttack 2013-03-08 01:06:51

相關問題