2014-09-11 301 views
0

我已經將freebase轉儲導入到neo4j。但目前我正面臨着由於db的大小而得到查詢的問題。雖然導入我剛剛創建節點索引並索引URI屬性索引爲每個節點。對於每個節點,我都添加了多個屬性,如label_en,type_content_type_en。在neo4j節點屬性值上添加索引

props.put(URI_PROPERTY, subject.stringValue()); 

Long subjectNode = db.createNode(props); 

tmpIndex.put(subject.stringValue(), subjectNode); 

nodeIndex.add(subjectNode, props); 

現在我的密碼查詢是這樣的。哪些超時。我無法在label_en屬性上添加索引。任何人都可以幫忙嗎?

match (n)-[r*0..1]->(a) where n.label_en=~'Hibernate.*' return n, a 

更新

BatchInserter db = BatchInserters.inserter("ttl.db", config); 
BatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProvider(db); 
BatchInserterIndex index = indexProvider.nodeIndex("ttlIndex", MapUtil.stringMap("type", "exact")); 

問題:當我在nodeindex添加節點i增加了財產URI

props.put(URI_PROPERTY, subject.stringValue()); 
Long subjectNode = db.createNode(props); 
nodeIndex.add(subjectNode, props); 

在代碼後,我又增加屬性到節點(命名爲label_en)。但我沒有添加或更新nodeindex。所以根據我的理解,lucene沒有將label_en屬性編入索引。我的圖形已經建好了,所以我試圖在我的節點的label_en屬性上添加索引,因爲我的查詢是在label_en上的。

回答

1

您的代碼示例中缺少您是如何創建的索引。但我很確定你在做什麼是使用基於Apache Lucene的遺留索引。

您的Cypher查詢正在使用正則表達式運算符=~。這不是你如何使用傳統索引;這似乎是迫使密碼忽略遺留索引,並讓java層在label_en屬性的每個可能值上運行該正則表達式。

相反,與Cypher你應該use a START clause and use the legacy indexing query language

對你來說,這將是這個樣子:

START n=node:my_index_name("label_en:Hibernate.*") 
MATCH (n)-[r*0..1]->(a) 
RETURN n, a; 

通知字符串label_en:Hibernate.* - 這是一個Lucene的查詢字符串,說要檢查屬性名的特定字符串。 Cypher/neo4j沒有解釋這一點;它傳遞給Lucene。

您的代碼沒有提供您的索引名稱。當您創建遺留索引時,必須將上面的my_index_name更改爲您命名的任何名稱。