query.setDescending(true) is not working(in latest libraries com.couchbase.lite:couchbase-lite-android:1.1.0)

63 views
Skip to first unread message

PRASANNA KUMAR

unread,
Jul 9, 2015, 7:03:47 AM7/9/15
to mobile-c...@googlegroups.com
Hi All,

setDescending method is not working query level

MY VIEW: I want to get documents with sorting lastmodified date for that i've wrote view here


 com.couchbase.lite.View viewTicketsPerStatusPagination = database.getView(String.format("%s/%s", D_DOCNAME, TICKETS_PER_STATUS_PAGINATION));
viewTicketsPerStatusPagination.setMap(new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {

Object type = document.get(TYPE);
String archived = (String) document.get(ARCHIVED);

try {
if (type != null && DOCTYPE_TICKET.equals(type) && archived == null) {
emitter.emit(new Object[]{document.get(PROJECT),((HashMap<String, String>) document.get(DATES)).get(LASTMODIFIEDDATE)},
Utility.getInstance().parsingTicket(document));
}
} catch (NullPointerException e) {
}
}
}, "3.3");
}

My Query:

com.couchbase.lite.View listMaps = AppConstants.database.getView(String.format("%s/%s", D_DOCNAME, TICKETS_PER_STATUS_PAGINATION));

Query queryGetGroupNames = listMaps.createQuery().toLiveQuery();
queryGetGroupNames.setStartKey(new Object[]{AppConstants.project_id});
queryGetGroupNames.setEndKey(new Object[]{AppConstants.project_id, new HashMap<String, Object>()});
    queryGetGroupNames.setDescending(true)// this is not working
queryGetGroupNames.setLimit(
20);
queryGetGroupNames.setSkip(
0);

QueryEnumerator result =
null;
try {
result = queryGetGroupNames.run();
}
catch (CouchbaseLiteException ex) {
}


for (Iterator<QueryRow> it = result; it.hasNext(); ) {
QueryRow row = it.next();

Alert.
getInstance().callLog("Ticket Documet information " + row.getValue());
}

Note:If setDescending(false) query is giving some of result but i want to do like setdescending(true) but query not giving any results even not showing any log information.

How we can solve this problem? or any suggestions.

Thank's in advance

Thank's
Prasanna 


 

Jens Alfke

unread,
Jul 9, 2015, 12:38:31 PM7/9/15
to mobile-c...@googlegroups.com
There’s a very common mistake people make with descending queries: the startKey has to be the higher key and the endKey the smaller key. Because the iteration will start at the end (highest keys.)

—Jens

PRASANNA KUMAR

unread,
Jul 10, 2015, 4:57:16 AM7/10/15
to mobile-c...@googlegroups.com
Thanks Jens it is working now
Reply all
Reply to author
Forward
0 new messages