2013-01-16 94 views
0

我已經經歷了Neo4j的和Neo4j的C#客戶端指標工作..在Neo4j的

neo4jclient wiki幫助我與節點CRUD操作。但是維基到此爲止突然.. 戳我的周圍test methods in source code並設法瞭解關係並在線搜索以瞭解索引的工作原理。

到目前爲止,這裏就是我的,大致爲:

//create indexing on user and car 
client.CreateIndex("User", new IndexConfiguration() { Provider = IndexProvider.lucene, Type = IndexType.fulltext }, IndexFor.Node); 
client.CreateIndex("Car", new IndexConfiguration() { Provider = IndexProvider.lucene, Type = IndexType.fulltext }, IndexFor.Node); 

//create user 
client.Create(new User() { Name = "Dovakiin", Job = "Dragon Slayer" }); 
client.Create(new User() { Name = "Ulfric stormcloak", Job = "Imperial Slayer" }); 

//create Car 
client.Create(new Car() { Name = "Paarthurnax", Modal = 212 }); 

//User owns car relationship 
client.CreateRelationship(userRef, new Owns_CarRelationship(CarRef)); 

這是我現在停留。當我試圖尋找由名稱的用戶,我的密碼查詢返回結果爲零:

start u=node:User(Name="Dovakiin") return u; 

,我不明白爲什麼它返回零個節點時,明確

start n=node(*) return n; 

節目所有節點。

我是否在編制索引時缺少其他內容?或者這與索引無關?我不需要將每個節點添加到索引?

我試圖做的是選擇具有給定屬性的節點:Name = "Dovakiin"在這種情況下..我該如何選擇這個?

回答

3

爲了擴展ulkas的答案,如果你想啓用自動索引並發現文檔有點混亂(就像我第一次閱讀它一樣),這就是你如何設置它。

比方說,你想自動索引一些節點屬性;說,「名稱」和「工作」。開拓/conf/neo4j.properties文件,你會看到這樣的事情:

# Autoindexing 

# Enable auto-indexing for nodes, default is false 
#node_auto_indexing=true 

# The node property keys to be auto-indexed, if enabled 
#node_keys_indexable=name,age 

然後你必須編輯這個文件到以下幾點:

# Autoindexing 

# Enable auto-indexing for nodes, default is false 
node_auto_indexing=true 

# The node property keys to be auto-indexed, if enabled 
node_keys_indexable=name,job 

一旦做到這一點,爲了要使自動索引生效,您必須重新啓動neo4j。另外,請注意,任何現有的節點都不會被自動索引,這意味着您必須重新創建它們。如果你不想從頭開始,下面是一些關於如何更新他們的文檔:http://docs.neo4j.org/chunked/milestone/auto-indexing.html#auto-indexing-update-removal(我從來沒有嘗試過)。一旦

Node<User> myNode = client.QueryIndex<User>("node_auto_index", IndexFor.Node, "name:Dovakiin").First();, or 
Node<User> myNode = client.QueryIndex<User>("node_auto_index", IndexFor.Node, "job:Dragon Slayer").First(); 

你可以做同樣的事情與關係,以及,:用C#客戶

start n=node:node_auto_index(name="Dovakiin"), or 
start n=node:node_auto_index(job="Dragon Slayer") 

或者,像這樣:

然後你就可以開始尋找節點像這樣如你在/conf/neo4j.properties文件中設置它。你的做法與節點完全相同。

+0

謝謝!哇,這正是我想要的!從我上面評論ulkas的答案的鏈接SO問題,我設法添加節點索引手動,但更喜歡自動索引..是的,整個文檔是混淆,但我慢慢到達那裏! ('''Name:Parthurnax - immune-magic「'')這個名字沒有特別的理由,只是鍵入任何..然而,shell腳本返回節點OK,neo4jclient發生500錯誤。哦,我只是刪除unicode連字符並嘗試。再次感謝! – LocustHorde

+0

不客氣!但我仍然覺得@ulkas比我更好地回答了這個問題。他甚至提到了自動索引,但是我只是擴展了,因爲我第一次在neo4j.org上閱讀文檔時記得有點困惑。無論如何,我很高興你能開始工作,因爲我記得那讓我瘋狂! –

+0

@LocustHorde關於500錯誤,你可以在http://hg.readify.net/neo4jclient上提出一個問題,以便我們修復它嗎? –

2

必須manually add到索引中,一些節點像

client.indexRef1.addToIndex(nodeRef, 'name', 'Dovakiin') client.indexRef2.addToIndex(nodeRef, 'job', 'Dragon Slayer')

也有一個automatic indexing功能在Neo4j的情況下,你想要的節點自動添加到索引中。

+0

啊!我知道我錯過了一些東西!非常感謝,從你的回答,我搜索併到達這個http://stackoverflow.com/questions/12485986/neo4jclient-how-to-add-node-to-index它回答了我的問題。 – LocustHorde