2016-12-27 251 views
1

現在我正在設計一個Neo4j數據庫系統,我必須能夠查詢一個節點中的Date屬性是否在提供的Date之前,等於或之後。Neo4j Cypher比較Cypher查詢日期

我應該如何存儲Date Neo4j的節點屬性的內部能夠例如基於簡單的運營商如==>做暗號查詢比較,<

是否還好存儲DateLong timestamp?它會以這種方式工作嗎?如果不是,請提出更好的決定。

修訂

查詢我已經沒有運氣嘗試:

MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User) WHERE id(parentD) = {decisionId} MATCH (childD)<-[:SET_FOR]-(filterValue153:Value)-[:SET_ON]->(filterCharacteristic153:Characteristic) WHERE id(filterCharacteristic153) = 153 WITH filterValue153, childD, ru, u WHERE (filterValue153.value = '60305027689736') 

MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User) WHERE id(parentD) = {decisionId} MATCH (childD)<-[:SET_FOR]-(filterValue153:Value)-[:SET_ON]->(filterCharacteristic153:Characteristic) WHERE id(filterCharacteristic153) = 153 WITH filterValue153, childD, ru, u WHERE (filterValue153.value = 'Mon Dec 27 22:35:56 EET 3880') 

filterValue153.value已存儲像java.util.Date對象Value.value節點屬性

@NodeEntity 
public class Value extends Authorable { 

    public final static String NODE_NAME = "Value"; 

    private final static String SET_FOR = "SET_FOR"; 
    private final static String SET_ON = "SET_ON"; 

    @Relationship(type = SET_FOR, direction = Relationship.OUTGOING) 
    private Decision decision; 

    @Relationship(type = SET_ON, direction = Relationship.OUTGOING) 
    private Characteristic characteristic; 

    private Object value; 

... 

} 

在數據庫級別爲Value節點我有一個fo llowing數據:

id: 848013 
value: 1482873001556 

修訂

此查詢工作正常

MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User) WHERE id(parentD) = {decisionId} MATCH (childD)<-[:SET_FOR]-(filterValue153:Value)-[:SET_ON]->(filterCharacteristic153:Characteristic) WHERE id(filterCharacteristic153) = 153 WITH filterValue153, childD, ru, u WHERE (filterValue153.value = 60305030539682) 

,但如何處理之前的日期1970年1月1日,00:00:00 GMT? 也可以運用=,>,<這個Cypher查詢日期?

回答

1

相關問題:

然而,這個問題可以追溯到到2012年。從那時起,我們有APOC與date/time conversion支持。這使您可以按照Javadoc of the SimpleDateFormat class中所述的格式轉換日期/時間值。

1970/01/01之前的日期將起作用,它們將簡單地用negative numbers表示。例如:

CALL apoc.date.parseDefault('1969-07-21 02:56:15', 's') 
YIELD value 

算術比較操作符(=<>< ...)將時間戳工作。

+0

感謝您的回答。我已經更新了我的問題,並提供了更多細節。你能告訴我做錯了什麼嗎?另外,請您舉一個例子說明如何使用新舊方法(使用APOC)來完成這項工作? – alexanoid

+0

如果您只是使用此查詢返回節點,您會得到什麼結果? 'MATCH(filterCharacteristic153:Characteristics)WHERE id(filterCharacteristic153)= 153 RETURN *' –

+0

我已經爲我的Neo4j添加了輸出值'Value'節點 – alexanoid