gae-search

How can I include the doc_id field in results returned by Google App Engine search?


I have a set of fields indexed by GAE search and can get results thus:

options = search.QueryOptions(returned_fields=['ID', 'firstname', 'lastname']}
query = search.Query('firstname:moe')

This gets me results returned and I can access data in the two name fields. But ID isn't included. I've tried 'doc_id" as well.

How can I get each doc ID with each result?


Solution

  • The doc_id isn't "just another field"; it's a separate attribute of the Document object. Try like this:

    search_results = index.search(query);
    for doc in search_result.results:
        d = doc.doc_id