Search code examples
google-app-engineapp-engine-ndbdjangoappengine

ndb Query partial string matching


This seems like it should be an easy question. But the docs don't seem to answer it. Using the example from them, I want to do this:

Account.query(Account.title == "best")

Except I want to match partial strings as well. So in this scenario:

acct = Account(title="the best account in the world")

an ndb query with argument "best" would match the acct.

The only option I see at the moment is to loop through Account.query() and match each title with re.search module in python. This doesn't seem like a good solution.

Update: I am also looking at gql. Doing this:

acct = ndb.gql('SELECT * from Account WHERE title LIKE '%best%')

returns a Parse Error: Invalid WHERE Condition at symbol LIKE


Solution

  • GQL doesn't have wildcards matching, to achieve that you will need to use the full text search.