Google Groups

Re: [objectify-appengine] multiple calls to order() in a query


Jeff Schnitzer Mar 1, 2012 6:51 AM
Posted in group: objectify-appengine
Are there single-property indexes on all of those fields?  One annoying thing about GAE is that you need single-property indexes covering every single one of the fields in a multi-property index.

This makes writes for objects like this very expensive.

Jeff

On Thu, Mar 1, 2012 at 7:02 AM, Eliot Stock <1...@eliotstock.com> wrote:
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.