xybrek xybrek - 24 days ago 7
Java Question

Setting Cursor for a GAE Search query

The document doesn't seem to elaborate on how to actually set a start cursor when performing a search like this:

Results<ScoredDocument> results = index.search(queryString);


Getting the cursor is easy:

results.getCursor().toWebSafeString()


But setting a start cursor for the
index.search
is not documented? Looking at the code I can see a
Query
object as another parameter for the
search
method, yet again there is no example on how to build a
Query
for search to which we can add the cursor.

Answer

Example can be found here: https://cloud.google.com/appengine/docs/java/javadoc/com/google/appengine/api/search/Query

QueryOptions options = QueryOptions.newBuilder()
     .setLimit(20)
     .setFieldsToSnippet("subject", "body")
     .setScorer(CustomScorer.newBuilder()
         .addSortExpression(SortExpression.newBuilder()
             .setExpression("author")
             .setDirection(SortDirection.DESCENDING)
             .setDefaultValue("")))
     .setCursor(responseCursor)
     .build();
 Query query = Query.newBuilder()
     .setOptions(options)
     .build("good story");