Reputation: 35346
I have this search code that is quite bugging me,
if(webSafeCursor != null && !webSafeCursor.isEmpty()){
Cursor cursor = Cursor.newBuilder().build(webSafeCursor);
QueryOptions options = QueryOptions.newBuilder()
.setLimit(10)
.setFieldsToSnippet("content")
.setCursor(cursor)
.build();
query = Query.newBuilder()
.setOptions(options)
.build(queryString);
}
Results<ScoredDocument> results = null;
if(query != null){
results = index.search(query);
} else {
results = index.search(queryString);
}
results.getCursor(); // NULL!
}
The problem here is that the results
returned is 20 items while it is clear in the QueryOptions
that the limit is 10.
What could be wrong in this code?
And another thing is the query result do not emit a Cursor, whereas it is clear (by manually checking) that the query should return more than 20 items, and that should return a Cursor? Or is this the correct behavior?
Upvotes: 0
Views: 93
Reputation: 91
Well, as far as I can tell from your code, your queryOptions are only used if you pass in a non-empty cursor. So, if you didn't already have a cursor you won't be getting one either. Add a closing brace after
Cursor cursor = Cursor.newBuilder().build(webSafeCursor);
and I think you'll get the behavior you want (after balancing the braces elsewhere, of course).
Upvotes: 2