Domanda

I am trying to mimic the normal behavior of an empty search on a collection. Usually and empty search should returns all entities. How can i do this with App Engines Full Text Search? Basically how do i return all documents in a given index without any search params?

The reason i can't just return the Datastore collection in this case is the Models have parents and this search is a global search not based on any of the ancestors.

As always thanks for any help with this.

È stato utile?

Soluzione

For instance (untested and very not optimum):

from google.appengine.api import search
...
def get_all_in_index(index_name):
    """Get all the docs in the given index."""
    results = []
    doc_index = search.Index(name=index_name)

    # looping because get_range by default returns up to 100 documents at a time
    while True:
        # Get a list of documents populating only the doc_id field and extract the ids.
        document_ids = [document.doc_id
                        for document in doc_index.get_range(ids_only=True)]
        if not document_ids:
            break
        # Get the documents for the given ids from the Index.
        results.append(doc_index.get_range(document_ids))
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top