假设我有4张照片,并且我想返回一个列表,该列表首先在Rating desc上排序,第二个在RatingsCount desc上排序。 cypher查询下面给出了正确的结果:
MATCH (n:`Photo`) WHERE n.RatingsCount > 0 RETURN n.Rating, n.RatingsCount ORDER BY n.Rating DESC, n.RatingsCount DESC LIMIT 20
Id 1-Rating 9-Ratingscount 1
Id 3-Rating 7-Ratingscount 2
Id 2-Rating 7-Ratingscount 1
Id 4-Rating 2-Ratingscount 1
不幸的是我无法将其翻译为Neo4jClient。下面的查询给我一个按升序排名和Ratingscount降序排序的照片列表:
var query = await graphClient.Cypher
.Match("(photo:Photo)")
.Where((PhotoEntity photo) => photo.RatingsCount > 0);
.ReturnDistinct((photo) => new
{
Photo = photo.As<PhotoEntity>()
})
.OrderByDescending("photo.Rating", "photo.RatingsCount")
.Limit(20)
.ResultsAsync;
Id 4-Rating 2-Ratingscount 1
Id 3-Rating 7-Ratingscount 2
Id 2-Rating 7-Ratingscount 1
Id 1-Rating 9-Ratingscount 1
如果我更改了Rating和RatingsCount的顺序,我会以更奇怪的顺序得到照片:)我在这里做错了什么线索?
var query = await graphClient.Cypher
.Match("(photo:Photo)")
.Where((PhotoEntity photo) => photo.RatingsCount > 0);
.ReturnDistinct((photo) => new
{
Photo = photo.As<PhotoEntity>()
})
.OrderByDescending("photo.RatingsCount", "photo.Rating")
.Limit(20)
.ResultsAsync;
Id 1-Rating 9-Ratingscount 1
Id 2-Rating 7-Ratingscount 1
Id 4-Rating 2-Ratingscount 1
Id 3-Rating 7-Ratingscount 2
答案 0 :(得分:2)
我看了一下Neo4jClient的来源,OrderByDescending()
简单string.join()s
用逗号来表示其参数,并添加了“DESC&#39;在末尾。换句话说:它对除了最后一个属性之外的每个属性进行ASC排序。我同意这是违反直觉的,所以我倾向于避免它。
您可以改为使用OrderBy()
:
OrderBy("photo.RatingsCount DESC, photo.Rating DESC")