java - The first sort property must be the same as the property to which the inequality filter is applied -


java.lang.illegalargumentexception: first sort property must same property inequality filter applied. in query first sort property vote inequality filter on createddate

i error when try run code below. there work around problem?

query query = new query("post");  long timeago = - timelimit; filter categoryfilter = new filterpredicate("postcategory", filteroperator.equal, category); filter createddatefilter = new filterpredicate("createddate", filteroperator.greater_than, timeago); filter compositefilter = compositefilteroperator.and(categoryfilter, createddatefilter); query.setfilter(compositefilter);  query.addsort("vote", sortdirection.descending);  list<entity> postsentitylist = datastore.prepare(query).aslist(fetchoptions.builder.withoffset(offset).limit(limit)); 

the code above trying reteive list of post entities based on category , created within last 24 hours. sort them how many votes have. has limit , offset pagination.

to avoid error, option add multiple sort orders below createddate first sort order:

.addsort("createddate", sortdirection.ascending)                 .addsort("vote", sortdirection.descending); 

but have limitation results not sorted respect second property , have additional sorting @ client side. please read earlier post understand behaviour


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -