0
votes

I'm trying to implement a keyword/tags search for a certain entity type in GAE's datastore:

class Docs(db.Model):
    title = db.StringProperty()
    user = db.StringProperty()
    tags = db.StringListProperty()

I also wrote a very basic search function (using a fake list of tags, not the datastore values), that takes a query string and matches it to each set of tags. It ranks Docs based on how many query words match the tags. This is pretty much all I need it to do, except using the actual datastore.

I have no idea how to get the actual datastore values though. For my search function to work I need a list of all the entities in the datastore, which is impossible (?).

I also tried looking into GAE's experimental full-text search, and Relation Index Entities as a way to search the datastore without using the function I wrote. Neither was successful.

Any other ideas on how to search for entities based on tags?

1
The search api is probably a much better choice for implementing your requirements. You said you investigated it and it didn't work. In what way didn't it work ?Tim Hoffman
I couldn't figure out how to search lists of tags with the api. It also only handles 1000 searches/day...which is kind of small.kennysong
you can request a bigger quote - its early days for it. As for searching tags , they could just be a text field containing all the tags. There is a very detailed example code - code.google.com/p/google-app-engine-samples/source/browse/trunk/…Tim Hoffman
if you used a StringListProperty and you start trying to match for multiple tags you will end up with very expensive queries.Tim Hoffman
no but if you are querying for things that match 3 keywords then you are using the "IN" clause for querying string list properties. I think you need to do some reading of the docs.Tim Hoffman

1 Answers

1
votes

It's a very simple query, if you need to find all Docs with a tag "findme", it's simply:

num_results = 10
query = Docs.all().filter("tags in", "findme")
results = query.fetch(num_results) # get list of results

It's well documented: https://developers.google.com/appengine/docs/python/datastore/queries