Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
how to order query by separate field
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Baron  
View profile  
 More options Oct 29, 8:53 pm
From: Baron <richar...@gmail.com>
Date: Thu, 29 Oct 2009 17:53:51 -0700 (PDT)
Local: Thurs, Oct 29 2009 8:53 pm
Subject: how to order query by separate field
Hello,

I have a model with over 1000 records and I want to select the top N
records on field A that satisfy conditions on field B. (For example
the youngest N records with a certain name.)

My concern is if I only filter on field B and order in code
afterwards, then I will miss some records not in the top 1000.

I was hoping to create an index so that the results are always ordered
by field A, but that doesn't seem to be possible.
Ideas?


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ryan baldwin  
View profile  
 More options Oct 29, 9:01 pm
From: ryan baldwin <ryanbald...@gmail.com>
Date: Thu, 29 Oct 2009 19:01:07 -0600
Local: Thurs, Oct 29 2009 9:01 pm
Subject: Re: [google-appengine] how to order query by separate field

I believe you can create an index that sorts by youngest, then by name, and
you should be good.  Assuming your "youngest" field is called "createdDate".

In app.yaml:

- kind: MyModel
  properties:
    - name: createdDate
      direction: asc

If I understand what I just typed, that will create an index on the MyModel
entity, ordering first by createdDate ascending then by A ascending.  You
could, I believe, then do the following:

MyModel.all().filter=('A =', 123).order(createdDate).fetch(limit=20)

That being said, I'm not sure if DataStore actually guarantees the order of
results... I assume so...?

- ryan.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ryan baldwin  
View profile  
 More options Oct 29, 9:02 pm
From: ryan baldwin <ryanbald...@gmail.com>
Date: Thu, 29 Oct 2009 19:02:00 -0600
Subject: Re: [google-appengine] how to order query by separate field

In my example I left out the sorts by A ascending because I later realised
it may not be necessary... I believe, however, that my index *does* sort by
createdDate ascending... I haven't written one in a long, long time, so my
apologies. ;)

- ryan.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Baron  
View profile  
 More options Nov 1, 6:48 pm
From: Baron <richar...@gmail.com>
Date: Sun, 1 Nov 2009 15:48:24 -0800 (PST)
Local: Sun, Nov 1 2009 6:48 pm
Subject: Re: how to order query by separate field
I found that if I used my query a few times on the development server
then your above code snippet was automatically inserted in my
index.yaml - neat! (not app.yaml)
Then when I uploaded to Google App Engine I got errors for a few
minutes while the index was building, but eventually it worked.

On Oct 30, 12:02 pm, ryan baldwin <ryanbald...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google