Python - Querying a repeated property vs using Search API

40 views
Skip to first unread message

Devraj Mukherjee

unread,
Mar 13, 2015, 7:51:37 PM3/13/15
to google-a...@googlegroups.com
Hi all,

My application allows users to query via sets of tags (usual arbitrary strings), at present I am using a structured property in my  model to store the set of tags

tags = ndb.StringProperty(repeated=True)

and query it as follows

query = meddle.models.UserPhoto.query().filter(meddle.models.UserPhoto.user_key == user_profile.key)

for tag in tags:
    query.filter(myapp.models.UserPhoto.tags == tag)

I suspect ask the stored data grows this might not be the most efficient query to run, and have thus been wondering if we should explore the Search API to store indexes.

Am mostly looking for a confirmation on if I should go down the path of exploring the Search API or is there a better way in NDB to query arbitrary strings.

Thanks very much for any pointers.

Dev

Alex Martelli

unread,
Mar 14, 2015, 12:55:45 PM3/14/15
to google-a...@googlegroups.com
Per https://cloud.google.com/appengine/docs/python/ndb/queries#repeated_properties

    myapp.models.UserPhoto.tags.IN(tags)

would be an `OR` query (with its own limits, too), and what you want is instead an `AND` query; I don't think there's a materially faster way to compose the latter wrt what you're doing now.  Thus, I would indeed encourage you to explore if the Search API can better match your needs (within its own limits, such as the 10GB index size constraint).


Alex


--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/CANgV5UwQu%3D0cATKeWQF-cNJW1SF_AEEM5s-_UQ%2Brtw%3D9wOM2tA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages