Stay organized with collections
Save and categorize content based on your preferences.
publicfinalclassQueryOptions
Represents options which control where and what in the search results to return, from restricting
the document fields returned to those given, and scoring and sorting the results, whilst
supporting pagination.
For example, the following options will return documents from search results for some given
query, returning up to 20 results including the fields 'author' and 'date-sent' as well as
snippeted fields 'subject' and 'body'. The results are sorted by 'author' in descending order,
getting the next 20 results from the responseCursor in the previously returned results, giving
back a single cursor in the Results to get the next batch of results after this.
Creates and returns a QueryOptions builder. Set the search request
parameters and use the Builder#build() method to create a concrete
instance of QueryOptions.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003e\u003ccode\u003eQueryOptions\u003c/code\u003e controls search result parameters, including fields to return, scoring, sorting, and pagination.\u003c/p\u003e\n"],["\u003cp\u003eYou can limit the number of results, specify fields to return or snippet, and sort results using the \u003ccode\u003eQueryOptions\u003c/code\u003e class.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003enewBuilder()\u003c/code\u003e static method provides a way to create and configure \u003ccode\u003eQueryOptions\u003c/code\u003e instances for search requests.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eQueryOptions\u003c/code\u003e supports pagination through the use of a cursor, allowing retrieval of subsequent sets of results.\u003c/p\u003e\n"],["\u003cp\u003eIt allows control over the accuracy of the found count, if set, and whether only document IDs are returned.\u003c/p\u003e\n"]]],[],null,["# Class QueryOptions (2.0.0)\n\n public final class QueryOptions\n\nRepresents options which control where and what in the search results to return, from restricting\nthe document fields returned to those given, and scoring and sorting the results, whilst\nsupporting pagination.\n\nFor example, the following options will return documents from search results for some given\nquery, returning up to 20 results including the fields 'author' and 'date-sent' as well as\nsnippeted fields 'subject' and 'body'. The results are sorted by 'author' in descending order,\ngetting the next 20 results from the responseCursor in the previously returned results, giving\nback a single cursor in the [Results](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.search.Results) to get the next batch of results after this. \n\n\n QueryOptions request = QueryOptions.newBuilder()\n .setLimit(20)\n .setFieldsToReturn(\"author\", \"date-sent\")\n .setFieldsToSnippet(\"subject\", \"body\")\n .setSortOptions(SortOptions.newBuilder().\n .addSortExpression(SortExpression.newBuilder()\n .setExpression(\"author\")\n .setDirection(SortExpression.SortDirection.DESCENDING)\n .setDefaultValue(\"\")))\n\n .setCursor(Cursor.newBuilder().build())\n .build();\n \nInheritance\n-----------\n\n[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e QueryOptions \n\nInherited Members\n-----------------\n\n[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) \n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)\n\nStatic Methods\n--------------\n\n### newBuilder()\n\n public static QueryOptions.Builder newBuilder()\n\nCreates and returns a [QueryOptions](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.search.QueryOptions) builder. Set the search request\nparameters and use the Builder#build() method to create a concrete\ninstance of QueryOptions.\n\n### newBuilder(QueryOptions request)\n\n public static QueryOptions.Builder newBuilder(QueryOptions request)\n\nCreates a builder from the given request.\n\nMethods\n-------\n\n### getCursor()\n\n public Cursor getCursor()\n\n### getExpressionsToReturn()\n\n public List\u003cFieldExpression\u003e getExpressionsToReturn()\n\n### getFieldsToReturn()\n\n public List\u003cString\u003e getFieldsToReturn()\n\n### getFieldsToSnippet()\n\n public List\u003cString\u003e getFieldsToSnippet()\n\n### getLimit()\n\n public int getLimit()\n\n### getNumberFoundAccuracy()\n\n public int getNumberFoundAccuracy()\n\nAny [Results#getNumberFound()](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.search.Results#com_google_appengine_api_search_Results_getNumberFound__) less than or equal to this\nsetting will be accurate.\n\n### getOffset()\n\n public int getOffset()\n\n### getSortOptions()\n\n public SortOptions getSortOptions()\n\n### hasNumberFoundAccuracy()\n\n public boolean hasNumberFoundAccuracy()\n\nReturns true iff there is an accuracy requirement set.\n\n### isReturningIdsOnly()\n\n public boolean isReturningIdsOnly()\n\n### toString()\n\n public String toString()\n\n**Overrides** \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--)"]]