0

我在 CosmicMind/Graph 数据库中搜索实体时遇到了一些问题。这是代码,这很容易解释

//User 1
//data: 14 Febbraio 2017
//ora : 15:40
//name: Paolo

//User 2
//data: 14 Febbraio 2017
//ora : 12:40
//name: Ernesto

//User 3
//data: 13 Febbraio 2017
//ora : 16:40
//name: Paolo

/*Search Parameters*/
//dataSearch = 13 Febbraio 2017
//oraSearch = 16:40
//nameSearch = Paolo

var search = Search<Entity>(graph: graph).for(types: "Users").where(properties: (key: "data", value: dataSearch)).where(properties: (key:"ora", value: oraSearch)).where(properties: (key:"name", value: nameSearch))
    //returns [User1, User3]

我期待搜索 [User3],因为搜索参数与该实体一致,但是搜索返回 [User1, User3],就像忽略 dataSearch 和 oraSearch 参数,并且只有最后一个搜索参数 nameSearch 正在用于搜索。我究竟做错了什么?

4

2 回答 2

0

编辑:我“解决”了使用另一个参数来检索记录,一个字符串类型。它可以完美地用作 searchParameter,而不是 Date 类型。然后,我对数据进行了一些操作以隔离正确的结果。

也许我的 xcode 控制台可以帮助你,但首先我向你展示我的代码:

let search = Search<Entity>(graph: DataManager.shared.graph).for(types: DataManager.shared.entityType).where(properties: (key: "data", value: (DataManager.shared.datasource[0][0]["data"] as! Date)))
print("The date i am searching for->",DataManager.shared.datasource[0][0]["data"]!)
for (index,res) in search.sync().enumerated(){
    print("Result #\(index)->\(res["data"]!)")
}
print("Total results found->",search.sync().count)
print("But only 10 records meet the requirement, not 22")

The date i am searching for-> 2017-02-16 11:19:14 +0000
Result #0->2017-02-15 22:31:28 +0000
Result #1->2017-02-15 22:21:51 +0000
Result #2->2017-02-15 22:31:43 +0000
Result #3->2017-02-15 22:44:31 +0000
Result #4->2017-02-16 10:56:37 +0000
Result #5->2017-02-16 10:56:48 +0000
Result #6->2017-02-16 10:59:23 +0000
Result #7->2017-02-15 22:32:01 +0000
Result #8->2017-02-16 10:56:21 +0000
Result #9->2017-02-15 22:23:06 +0000
Result #10->2017-02-16 11:16:00 +0000
Result #11->2017-02-16 11:19:14 +0000
Result #12->2017-02-15 22:32:12 +0000
Result #13->2017-02-15 22:42:12 +0000
Result #14->2017-02-16 11:18:07 +0000
Result #15->2017-02-16 10:59:59 +0000
Result #16->2017-02-15 22:31:36 +0000
Result #17->2017-02-16 10:58:24 +0000
Result #18->2017-02-16 10:59:07 +0000
Result #19->2017-02-15 22:23:22 +0000
Result #20->2017-02-15 22:31:49 +0000
Result #21->2017-02-15 22:32:18 +0000
Total results found-> 22
But only 10 records meet the requirement, not 22
于 2017-02-16T14:51:04.313 回答
0

你有太多了where statements。他们正在用每一个连续的陈述代替自己。

这个:

.where(properties: (key: "data", value: dataSearch)).where(properties: (key:"ora", value: oraSearch)).where(properties: (key:"name", value: nameSearch)

应该:

.where(properties: (key: "data", value: dataSearch), (key:"ora", value: oraSearch), (key:"name", value: nameSearch))

或速记:

.where(properties: ("data", dataSearch), ("ora", oraSearch), ("name", nameSearch))

而已 :)

于 2017-02-14T18:05:13.723 回答