[google-appengine] Re: Complex tagging of items

2009-01-27 Thread Seronja

Here's where old good relational databases theory comes in.

How will I do it:
Create a model ``Tags'':
class Tags(db.Model):
  tag_name = db.StringProperty()
Create a model ``Items'':
class Items(db.Model):
  item_name = db.StringProperty()
And create a model  ``ItemTags''
class ItemTags(db.model):
  tag = db.ReferenceProperty(Tags)
  item = db.ReferenceProperty(Items)

So when you need to get items for some tags you first query the
``ItemTags'' for items with concrete tag(s) thgan by key you get
Items.

Cheers,
Serhiy

On Jan 24, 3:17 am, George Sudarkoff sudark...@gmail.com wrote:
 I have a bit of a problem coming up with an efficient data model/algo
 for a project I am working on:

 I have a few hundred items, each tagged with zero or more tags. I need
 to be able to fetch items that, for example, are tagged with tag1 AND
 (tag2 OR tag3) AND NOT tag4.

 Any help would be greatly appreciated!

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[google-appengine] Re: Complex tagging of items

2009-01-27 Thread George Sudarkoff



On Jan 25, 11:17 pm, ryan ryanb+appeng...@google.com wrote:
 On Jan 25, 11:43 am, Anthony acorc...@gmail.com wrote:

  If you store the tags as a StringList wouldn't this query work..

  WHERE tags = tag1 AND tags IN [tag2,tag3] AND tags != tag4

  From the docs it says the IN  != do run multiple queries behind the
  scenes so not sure if it will be as quick as running it in memory for
  a few hundred items, but if you need more than a few hundred items you
  are not going to be able to do it in memory before it starts timing
  out.

 good call, anthony! that query does indeed do what george wants, and
 you're right about how != and IN work behind the scenes.

 the problem with that query, unfortunately, is that it needs this
 index:

 - kind: Foo
   properties:
   - name: tags
   - name: tags
   - name: tags

 ...which is almost certain to explode on entities with any more than a
 handful of tags:

 http://code.google.com/appengine/docs/python/datastore/queriesandinde...

Very cool! On average I won't have more than 2-3 tags per item, so I
really think this solution might work! I'll try it and report back the
results.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[google-appengine] Re: Complex tagging of items

2009-01-27 Thread George Sudarkoff

This is what I have right now for simple 'tag1 OR tag2' cases. But how
do you efficiently retrieve items for 'tag1 AND (tag2 OR tag3) AND NOT
tag4' with this model?

On Jan 27, 12:59 am, Seronja ser...@oplakanets.com wrote:
 Here's where old good relational databases theory comes in.

 How will I do it:
 Create a model ``Tags'':
 class Tags(db.Model):
   tag_name = db.StringProperty()
 Create a model ``Items'':
 class Items(db.Model):
   item_name = db.StringProperty()
 And create a model  ``ItemTags''
 class ItemTags(db.model):
   tag = db.ReferenceProperty(Tags)
   item = db.ReferenceProperty(Items)

 So when you need to get items for some tags you first query the
 ``ItemTags'' for items with concrete tag(s) thgan by key you get
 Items.

 Cheers,
 Serhiy

 On Jan 24, 3:17 am, George Sudarkoff sudark...@gmail.com wrote:

  I have a bit of a problem coming up with an efficient data model/algo
  for a project I am working on:

  I have a few hundred items, each tagged with zero or more tags. I need
  to be able to fetch items that, for example, are tagged with tag1 AND
  (tag2 OR tag3) AND NOT tag4.

  Any help would be greatly appreciated!



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[google-appengine] Re: Complex tagging of items

2009-01-25 Thread Adam

taggable-mixin can help you with at least part of your problem.

http://code.google.com/p/taggable-mixin/

The kind of complex querying that you want to do can not be done with
the datastore's native querying capabilities; you'll have to get
results set and filter them in-memory.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[google-appengine] Re: Complex tagging of items

2009-01-25 Thread Anthony

If you store the tags as a StringList wouldn't this query work..

WHERE tags = tag1 AND tags IN [tag2,tag3] AND tags != tag4

From the docs it says the IN  != do run multiple queries behind the
scenes so not sure if it will be as quick as running it in memory for
a few hundred items, but if you need more than a few hundred items you
are not going to be able to do it in memory before it starts timing
out.

On Jan 24, 1:17 am, George Sudarkoff sudark...@gmail.com wrote:
 I have a bit of a problem coming up with an efficient data model/algo
 for a project I am working on:

 I have a few hundred items, each tagged with zero or more tags. I need
 to be able to fetch items that, for example, are tagged with tag1 AND
 (tag2 OR tag3) AND NOT tag4.

 Any help would be greatly appreciated!
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[google-appengine] Re: Complex tagging of items

2009-01-24 Thread Chris Tan

Since you only have a few hundred items, the easiest approach may be
to filter the results in memory after performing a preliminary
datastore query.  I would store the tag names in a StringListProperty
() on your model.

Hope this helps,
Chris

On Jan 23, 5:17 pm, George Sudarkoff sudark...@gmail.com wrote:
 I have a bit of a problem coming up with an efficient data model/algo
 for a project I am working on:

 I have a few hundred items, each tagged with zero or more tags. I need
 to be able to fetch items that, for example, are tagged with tag1 AND
 (tag2 OR tag3) AND NOT tag4.

 Any help would be greatly appreciated!
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---