Instead of counting the number of times a string has appeared at
querytime, just change to counting the number of times the string has
been input at input-time.

E.g. When your user puts in a string, search the datastore to see if
that string already appears in an entity. If so, set the count
property on that entity +1. If not, then add a new entity and set the
count property to 1. Then at query time, you can sort by the count
property, in addition to the date limitations.

On Aug 5, 6:20 am, Neo <[email protected]> wrote:
> Hi Hyperflame. Thanks for your reply. The problem is, between any given
> time period, there can be millions of such records. For each of such query,
> I will have to process those millions of records to get the top x entities.
> This is definitely very inefficient and not acceptable.
>
> -Neo
>
>
>
> On Thursday, August 2, 2012 7:12:12 AM UTC+5:30, hyperflame wrote:
>
> > Well, you could just use Google Cloud SQL if you really want a SQL
> > environment.
>
> > Otherwise ( this is just a quick example, obviously there are some
> > optimizations you could do). Also i'm typing this out on my phone, so
> > forgive me if I miss a semicolon or something.
>
> > To add a string to the datastore:
> > Entity record = new Entity("record");
> > record.setProperty("some_input", input_string);
> > record.setProperty("add_date", new Date());
> > datastore.put(record);
>
> > To search for strings in a given time period:
> > Query q = new Query("record");
> > Q.setFilter("add_date", FilterOperator.LESS_THAN,
> > some_date_that_you're_searching_for);
> > PreparedQuery pq = datastore.prepare(q);
>
> > And then you can pull out the top x entities out of pq as a List, then
> > extract their properties to find the string.
>
> > On Aug 1, 1:29 am, Neo <[email protected]> wrote:
> > > Suppose, In my website, I ask users to input some string. A user can
> > input
> > > string multiple times. Whenever any user inputs a string, I log it in
> > the
> > > database along with the time. Many strings can be same, even though
> > > inputted by different users. In the home page, I need to give the
> > interface
> > > such that any user can query for top n (say 50) strings in any time
> > period
> > > (say 10 Jan 2012 to 30 Jan 2012). If it was SQL, I could have written
> > query
> > > like:
>
> > > select string, count(*)
> > > from userStrings where day >= d1 and day <= d2
> > > group by string
> > > order by count(*) desc
> > > limit n
>
> > > How do I solve it in GAE environment? For each such user query, I can't
> > > process the record at query time - there can be millions of records.
>
> > > I am using JDO. My obvious goal is to minimize the app engine cost : CPU
> > +
> > > data.
>
> > > Thanks,

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to