Omair Shamshir
Omair Shamshir

Reputation: 2136

Google App engine Search API Cursor not not updating

I am using cursors to get results from GAE Full text search API. The roblem is that the cursor remains same in each iteration:

cursor = search.Cursor()
files_options = search.QueryOptions(
    limit=5,
    cursor=cursor,
    returned_fields='state'
)

files_dict = {}
query = search.Query(query_string=text_to_search, options=files_options)
index = search.Index(name='title')
while cursor != None:
    results = index.search(query)
    cursor = results.cursor

The cursor never become None even when the search returns only 18 results

Upvotes: 1

Views: 476

Answers (1)

Victor M. Alvarez
Victor M. Alvarez

Reputation: 396

The problem is that you getting the same 5 results over and over again. Every time you do results = index.search(query) inside your loop, you're retrieving the first five results because your query options specify a limit of 5 and empty cursor. You need to create a new query starting a the new cursor on every iteration.

cursor = search.Cursor()
index = search.Index(name='title')

while cursor != None:
    options = search.QueryOptions(limit=5, cursor=cursor, returned_fields='state'))
    results = index.search(search.Query(query_string=text_to_search, options=options))
    cursor = results.cursor

Take a look at the introduction section of this page: https://developers.google.com/appengine/docs/python/search/queryclass

Upvotes: 3

Related Questions