Cerea,

This may help - I was doing something similiar and noticed different
behaviour between the dev server and live server. Specifically, the
dev server seemed to funciton as documented (however not as you
desire) and return everything that has a record either < or >, however
live seemed to operate more like the big table specs in that it does
an index scan from the lower bound up to the upper bound (therefor
only including items starting with "book" which should give you what
you want).

So if you're only experiencing your issue on the dev server, it may
well work on live. If you're experiencing it on live however I dont
think i can help

Good luck.


On Jul 4, 9:10 am, Bill <billk...@gmail.com> wrote:
> You could use your approach if each keyword were in a separate child
> entity where the parent is BlogPage.  The child entity would be like
> the Relation index described by Slatkin in his Google I/O talk, but in
> your case, you'd have a single StringProperty instead of a
> StringListProperty so you could do a prefix matching.
>
> class BlogKeyword:
>     # Parent is some BlogPage
>     keyword = StringProperty()
>
> Your proposed query would be modified to return keys then the parents:
>
> query = BlogKeyword.all(keys_only=True) \
>   .filter('keyword >= ', searchWord) \
>   .filter('keyword < ', searchWord + u"\ufffd") \
>   .order('keyword')
> ordered_post_keys = [key.parent() for key in query.fetch(100)]
>
> I don't think the way you've appended the counts to the keywords will
> work, because ordering will be via string comparison and '3' will
> evaluate as larger than '20'.  So you should pad the counts based on
> max # of digits for your counts, e.g., book_00020 not book_20.
>
> Having a separate entity per keyword seems wasteful, so I'll think
> about it more.
> -Bill
>
> On Jul 4, 12:50 am, Bill <billk...@gmail.com> wrote:
>
> > I think the answer is in the documentation for 
> > ListProperty:http://code.google.com/appengine/docs/python/datastore/typesandproper...
>
> > In particular: "list_property < value tests if any of the members of
> > the list are less than the given value,..."
>
> > So your inequality filters will succeed for that entity because one
> > member of the list will be >= searchWord and another member of the
> > list will be < searchWord.
>
> > As to your question on doing both substring matching + ordering, I'll
> > think about it and post if I come up with something.
> > -Bill
>
> > On Jul 3, 12:43 pm, cerea <peonl...@gmail.com> wrote:
>
> > > Hi,
>
> > > I'm new to app engine & coding in general, so any help or advice would
> > > be greatly appreciated.
>
> > > Background:
> > > I am making a blog and each page has a list of keywords stored in a
> > > db.StringListProperty. Those keywords will be used when someone
> > > searches the site. I also want each keyword to have an integer
> > > associated with it which hold the number of occurrences of that
> > > keyword in the page.
>
> > > My Attempt:
> > > I have code which populates a StringListProperty named 'keywords' when
> > > a page is created. It looks like this: ["books_20", "lotto_100",
> > > "wallet_2"], where "books" is the keyword and "20" is the number of
> > > occurrences. My goal was to be able to perform a query to filter out
> > > all pages that starts with a certain keyword, then order it by the
> > > number of occurrences. Here is an example of my query:
>
> > > query = BlogPage.all()
> > > # my attempt at substring matching
> > > # based on the tip 
> > > here:http://code.google.com/appengine/docs/python/datastore/queriesandinde...
> > > query = query.filter('keywords >= ', searchWord)
> > > query = query.filter('keywords < ', searchWord + u"\ufffd")
> > > query.order('keywords')
>
> > > Problem:
> > > The query doesn't work correctly. If I search for the word "cat" even
> > > though it's not in the list, the blog page containing ["books_20",
> > > "lotto_100", "wallet_2"] still gets returned. I'm sure there is a
> > > logic behind the query and what is returned, but I don't understand.
>
> > > Questions:
> > > Is there a way to perform substring matching on a StringListProperty
> > > and also have it ordered? And Is there a better approach to what I'm
> > > trying to accomplish?
>
> > > Thanks so much for taking the time to read my post.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to