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
Post a Comment