My datastore has stored entities with a timestamp and relevance. I want to get the most relevant results from today, this week, month, or all time. The first sort would be timestamp, followed by relevance, pulling 10 at a time. However, this:
Filter timeMaxFilter = new FilterPredicate("timestamp",
FilterOperator.GREATER_THAN_OR_EQUAL,
getEarlierTimeStamp(Calendar.HOUR, -24));
if(timeFrame.equalsIgnoreCase("day")){
timeMaxFilter = new FilterPredicate("timestamp",
FilterOperator.GREATER_THAN_OR_EQUAL,
getEarlierTimeStamp(Calendar.HOUR, -24));
q.setFilter(timeMaxFilter);
}
PreparedQuery pq = datastore.prepare(q);
for (Entity result : pq.asList(withLimit(10).offset(10*pageNumber))) {
}
Generates this error message:
[INFO] java.lang.IllegalArgumentException: The first sort property must be the s
ame as the property to which the inequality filter is applied. In your query th
e first sort property is relevance but the inequality filter is on relevance.
[INFO] at com.google.appengine.api.datastore.DatastoreApiHelper.translateError(
DatastoreApiHelper.java:53)
I understand why- they reindex in order of timestamp, because they want to be able to return the query in flat time, so they require me to sort by timestamp first. However, I feel like they can't be putting such a strict requirement on their customers. I could probably pull back ALL results in order of relevance, and then pull off the top 10. However, that seems wasteful. Is there a better way? If not, how would I set a FilterOrder with no limit, meaning ALL of the entries so I could sort them on my end?
Thanks,
-Keith