【发布时间】:2018-07-07 03:47:26
【问题描述】:
我正在尝试通过使用以下代码按时间和业力对热门帖子进行排序来对热门帖子进行排序:
FirebaseFirestore.getInstance().collection("topics")
.orderBy("time", com.google.firebase.firestore.Query.Direction.DESCENDING)
.whereGreaterThanOrEqualTo("time",(System.currentTimeMillis() % 1000)-1000*60*60*24*7)
.orderBy("karma", com.google.firebase.firestore.Query.Direction.DESCENDING).startAfter(currentDoc).limit(10).get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot documentSnapshots) {
for (DocumentSnapshot d : documentSnapshots.getDocuments()){
Topic topic = new Topic();
topic.setId(d.getId());
topic.setUsername(d.getString("username"));
topic.setCaption(d.getString("caption"));
topic.setPic(d.getString("pic"));
topic.setTime(d.getLong("time"));
topic.setType(d.getString("type"));
topic.setImage(d.getString("image"));
topics.add(topic);
if (topics.size()==documentSnapshots.size()){
currentDoc = d;
adapter.updateList(topics);
loading.setVisibility(View.GONE);
}
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
e.printStackTrace();
}
});
我在 Firestore 中添加了索引。但它不起作用。
我的意思是它显示 7 天前的帖子。但它不是按业力排序的。它显示按时间排序的 7 天前的帖子。如果我从查询中删除 orderBy("time") 。崩溃了。
需要帮助:(
【问题讨论】:
-
如果发生崩溃,总会有崩溃报告。您可以分享日志以供其他人了解。
标签: java android firebase google-cloud-firestore