title: Firestore query to sort posts by time and score
body: <p>I'm trying to sort out trending posts by sorting them by time and karma using the following code:</p>
  
  <pre><code>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&lt;QuerySnapshot&gt;() {
                      @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();
              }
          });
  </code></pre>
  
  <p>I added the Index in Firestore. But it's not working.</p>
  
  <p>I mean it's showing 7 days old posts. But it's not sorted by karma. It's showing 7 days old posts sorted by time. And if i remove the orderBy("time") from the query. It's crashing.</p>
  
  <p>Need Help :(</p>