pythongoogle-app-enginefull-text-searchgoogle-cloud-datastoregae-search

Should I use NDB or Search API for storing User model?


Suppose I have basic User model in ndb with following properties:

```

name = ndb.StringProperty(default='')
username = ndb.StringProperty(required=True)
email = ndb.StringProperty(default='')
active = ndb.BooleanProperty(default=True)
admin = ndb.BooleanProperty(default=False)
permissions = ndb.StringProperty(repeated=True)
verified = ndb.BooleanProperty(default=False)
token = ndb.StringProperty(default='')
password_hash = ndb.StringProperty(default='')
bio = ndb.StringProperty(default='')
location = ndb.StringProperty(default='')
facebook = ndb.StringProperty(default='')
twitter = ndb.StringProperty(default='')
gplus = ndb.StringProperty(default='')
github = ndb.StringProperty(default='')

```

Let's say I want to perform LIKE query on fields name username bio

I've read this answer about NDB and Search API and I'm not clear whether whether I should only store name username bio via Search API and rest in NDB and manually maintain their consistency, or should I store all properties via Search API, so retrieving data can be faster/simpler.

Thanks for any kind of suggestions :)


Solution

  • You should store any important data in Datastore. It has redundancy and resiliency - it is your "MASTER".

    You should then pass off data to Search for... wait for it... searching! That might include the ID of your Datastore record.

    You could then retrieve your full data object from Memcache or Datastore via batch gets if you need more fields than are present in the Search document.