Class QueryOptions.Builder (2.0.0)

public static final class QueryOptions.Builder

A builder which constructs QueryOptions objects.

Inheritance

java.lang.Object > QueryOptions.Builder

Methods

addExpressionToReturn(FieldExpression expression)

public QueryOptions.Builder addExpressionToReturn(FieldExpression expression)

Adds a FieldExpression to return in search results.

Parameter
Name Description
expression FieldExpression

a named expression to compute and return in results

Returns
Type Description
QueryOptions.Builder

this Builder

addExpressionToReturn(FieldExpression.Builder expressionBuilder)

public QueryOptions.Builder addExpressionToReturn(FieldExpression.Builder expressionBuilder)

Adds a FieldExpression build from the given expressionBuilder to return in search results. Snippets will be returned as fields with the same names in ScoredDocument#getExpressions().

Parameter
Name Description
expressionBuilder FieldExpression.Builder

a builder of named expressions to evaluate and return in results

Returns
Type Description
QueryOptions.Builder

this Builder

build()

public QueryOptions build()

Construct the final message.

Returns
Type Description
QueryOptions

the QueryOptions built from the parameters entered on this Builder

clearNumberFoundAccuracy()

public QueryOptions.Builder clearNumberFoundAccuracy()

Clears any accuracy requirement for Results#getNumberFound().

Returns
Type Description
QueryOptions.Builder

setCursor(Cursor cursor)

public QueryOptions.Builder setCursor(Cursor cursor)

Sets the cursor. The cursor is obtained from either a Results or one of the individual ScoredDocuments.

This is illustrated from the following code fragment:


 Cursor cursor = Cursor.newBuilder().build();

 SearchResults results = index.search(
     Query.newBuilder()
         .setOptions(QueryOptions.newBuilder()
             .setLimit(20)
             .setCursor(cursor)
             .build())
         .build("some query"));

 // If the Cursor is built without setPerResult(true), then
 // by default a single Cursor is returned with the
 // Results.
 cursor = results.getCursor();

 for (ScoredDocument result : results) {
     // If you set Cursor.newBuilder().setPerResult(true)
     // then a cursor is returned with each result.
     result.getCursor();
 }
Parameter
Name Description
cursor Cursor

use a cursor returned from a previous set of search results as a starting point to retrieve the next set of results. This can get you better performance, and also improves the consistency of pagination through index updates

Returns
Type Description
QueryOptions.Builder

this Builder

setCursor(Cursor.Builder cursorBuilder)

public QueryOptions.Builder setCursor(Cursor.Builder cursorBuilder)

Sets a cursor built from the builder. See Also: #setCursor(Cursor)

Parameter
Name Description
cursorBuilder Cursor.Builder

a Cursor.Builder that is used to build a Cursor.

Returns
Type Description
QueryOptions.Builder

this Builder

setFieldsToReturn(String[] fields)

public QueryOptions.Builder setFieldsToReturn(String[] fields)

Specifies one or more fields to return in results.

Parameter
Name Description
fields String[]

the names of fields to return in results

Returns
Type Description
QueryOptions.Builder

this Builder

setFieldsToSnippet(String[] fieldsToSnippet)

public QueryOptions.Builder setFieldsToSnippet(String[] fieldsToSnippet)

Specifies one or more fields to snippet in results. Snippets will be returned as fields with the same names in ScoredDocument#getExpressions().

Parameter
Name Description
fieldsToSnippet String[]

the names of fields to snippet in results

Returns
Type Description
QueryOptions.Builder

this Builder

setLimit(int limit)

public QueryOptions.Builder setLimit(int limit)

Sets the limit on the number of documents to return in Results.

Parameter
Name Description
limit int

the number of documents to return

Returns
Type Description
QueryOptions.Builder

this Builder

setNumberFoundAccuracy(int numberFoundAccuracy)

public QueryOptions.Builder setNumberFoundAccuracy(int numberFoundAccuracy)

Sets the accuracy requirement for Results#getNumberFound(). If set, getNumberFound() will be accurate up to at least that number. For example, when set to 100, any getNumberFound() <= 100 is accurate. This option may add considerable latency / expense, especially when used with Builder#setFieldsToReturn(String...).

Parameter
Name Description
numberFoundAccuracy int

the minimum accuracy requirement

Returns
Type Description
QueryOptions.Builder

this Builder

setOffset(int offset)

public QueryOptions.Builder setOffset(int offset)

Sets the offset of the first result to return.

Parameter
Name Description
offset int

the offset into all search results to return the limit amount of results

Returns
Type Description
QueryOptions.Builder

this Builder

setReturningIdsOnly(boolean idsOnly)

public QueryOptions.Builder setReturningIdsOnly(boolean idsOnly)

Sets whether or not the search should return documents or document IDs only. This setting is incompatible with #addExpressionToReturn(FieldExpression) and with #setFieldsToReturn(String...) methods.

Parameter
Name Description
idsOnly boolean

whether or not only IDs of documents are returned by search request

Returns
Type Description
QueryOptions.Builder

this Builder

setSortOptions(SortOptions sortOptions)

public QueryOptions.Builder setSortOptions(SortOptions sortOptions)

Sets a SortOptions to sort documents with.

Parameter
Name Description
sortOptions SortOptions

specifies how to sort the documents in Results

Returns
Type Description
QueryOptions.Builder

this Builder

setSortOptions(SortOptions.Builder builder)

public QueryOptions.Builder setSortOptions(SortOptions.Builder builder)

Sets a SortOptions using a builder.

Parameter
Name Description
builder SortOptions.Builder

a builder of a SortOptions

Returns
Type Description
QueryOptions.Builder

this Builder