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
NameDescription
expressionFieldExpression

a named expression to compute and return in results

Returns
TypeDescription
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
NameDescription
expressionBuilderFieldExpression.Builder

a builder of named expressions to evaluate and return in results

Returns
TypeDescription
QueryOptions.Builder

this Builder

build()

public QueryOptions build()

Construct the final message.

Returns
TypeDescription
QueryOptions

the QueryOptions built from the parameters entered on this Builder

clearNumberFoundAccuracy()

public QueryOptions.Builder clearNumberFoundAccuracy()

Clears any accuracy requirement for Results#getNumberFound().

Returns
TypeDescription
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
NameDescription
cursorCursor

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
TypeDescription
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
NameDescription
cursorBuilderCursor.Builder

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

Returns
TypeDescription
QueryOptions.Builder

this Builder

setFieldsToReturn(String[] fields)

public QueryOptions.Builder setFieldsToReturn(String[] fields)

Specifies one or more fields to return in results.

Parameter
NameDescription
fieldsString[]

the names of fields to return in results

Returns
TypeDescription
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
NameDescription
fieldsToSnippetString[]

the names of fields to snippet in results

Returns
TypeDescription
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
NameDescription
limitint

the number of documents to return

Returns
TypeDescription
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
NameDescription
numberFoundAccuracyint

the minimum accuracy requirement

Returns
TypeDescription
QueryOptions.Builder

this Builder

setOffset(int offset)

public QueryOptions.Builder setOffset(int offset)

Sets the offset of the first result to return.

Parameter
NameDescription
offsetint

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

Returns
TypeDescription
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
NameDescription
idsOnlyboolean

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

Returns
TypeDescription
QueryOptions.Builder

this Builder

setSortOptions(SortOptions sortOptions)

public QueryOptions.Builder setSortOptions(SortOptions sortOptions)

Sets a SortOptions to sort documents with.

Parameter
NameDescription
sortOptionsSortOptions

specifies how to sort the documents in Results

Returns
TypeDescription
QueryOptions.Builder

this Builder

setSortOptions(SortOptions.Builder builder)

public QueryOptions.Builder setSortOptions(SortOptions.Builder builder)

Sets a SortOptions using a builder.

Parameter
NameDescription
builderSortOptions.Builder

a builder of a SortOptions

Returns
TypeDescription
QueryOptions.Builder

this Builder