2013-05-02 106 views
2

我想知道如何使用自動索引進行範圍查找。如果我查詢類似Neo4j CYPHER用於範圍查找的node_auto_index

START age=node:node_auto_index(age<20 and age>10) RETURN age;

返回

Exception in thread "main" string literal or parameter expected. 

我也嘗試過類似

START age=node:node_auto_index(age = range(10,20)) 
RETURN age; 

但它看起來像它需要只是age = "15"或類似的東西。

任何想法請做什麼?

回答

3

狀態Lucene documentation該範圍語法如下:

age:[10 TO 20] 

所得查詢(但沒有測試此):

START age=node:node_auto_index("age:[10 TO 20]") 
RETURN age; 

以下讀取可能也有有趣的你:Range queries in Neo4j using Lucene query syntax

編輯:不知道它是否會工作爲你;看看這個github issue

+0

謝謝,語法現在可以,但是它不會返回任何結果,即使我只有1個節點創建了適當的年齡。 – JustUser 2013-05-02 07:52:06

+0

剔除github問題。這可能正是你正在經歷的。 – tstorms 2013-05-02 08:00:34

+0

你有這個工作嗎?我很高興看到你的解決方案。如果這對你有幫助,也請隨時批准這個答案。 – tstorms 2013-05-03 08:16:27

0

爲什麼不使用where子句,如下所示?

START node=node:node_auto_index(name='PersonName') 
where node.age > 20 and node.age <20 
RETURN node.age; 
+0

由於'*'符號 – JustUser 2013-05-02 07:49:27

+0

應該是'START node:node(*)'這個返回錯誤。 – tstorms 2013-05-02 08:01:18

+0

但是,它不使用索引,我需要使用,它呢? – JustUser 2013-05-02 08:17:45

0

在與Neo4J Technologies的Stefan Armbruster進行了一次研討會之後,出現了同樣的話題。

我們想出的最基本的解決方案是確保爲numeric屬性存儲的所有值具有相同的長度。因此,人們需要填充年齡屬性值如下,011,099,103 ......並且這些值被存儲爲字符串而不是數值。

做這一切應該從索引工作。