Hi all,
I have a query to which I've just added a second order() call and the requisite indexes. It now looks like this:
Query<Post> postQuery = ofy.query(postType).filter("state", Post.State.LIVE)
.order("-score").order("-timestamp");
if (geoCells != null && geoCells.length > 0) {
postQuery.filter("geoCells in", geoCells);
}
if (category != null && !"".equals(category) && !"all".equals(category)) {
postQuery.filter("categories", category);
}
A toString() on the query before it's run looks like this:
kind=Post,ancestor=,
filter=^iEQUALOfferedPost,
filter=geoCellsIN[b5d75b, b5d75e, b5d75f, b5d771, b5d774, b5d775],
filter=stateEQUALLIVE,
sort=scoreDESCENDING,
sort=timestampDESCENDING
and I have the following indexes in datastore-indexes.xml:
<!-- / & /wanted, AJAX calls, category = all -->
<datastore-index kind="Post" ancestor="false" source="manual">
<property name="^i" direction="asc"/>
<property name="geoCells" direction="asc"/>
<property name="state" direction="asc"/>
<property name="score" direction="desc"/>
<property name="timestamp" direction="desc"/>
</datastore-index>
<!-- / & /wanted, AJAX calls -->
<datastore-index kind="Post" ancestor="false" source="manual">
<property name="^i" direction="asc"/>
<property name="categories" direction="asc"/>
<property name="geoCells" direction="asc"/>
<property name="state" direction="asc"/>
<property name="score" direction="desc"/>
<property name="timestamp" direction="desc"/>
</datastore-index>
The new property on the Post class is "score". I've been through and added a score value of 0 to all existing Post entities in the datastore, and did this *after* the indexes were there. The query runs without an "index needed" exception, but there are no results. Any ideas why? I can definitely sort by two properties in one query, right?
Cheers,
Eliot.