Class QueryOptions.Builder

  • Enclosing class:
    QueryOptions

    public static final class QueryOptions.Builder
    extends Object
    A builder which constructs QueryOptions objects.
    • Method Detail

      • setLimit

        public QueryOptions.Builder setLimit​(int limit)
        Sets the limit on the number of documents to return in Results.
        Parameters:
        limit - the number of documents to return
        Returns:
        this Builder
        Throws:
        IllegalArgumentException - if numDocumentsToReturn is not within acceptable range
      • setCursor

        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 {@link Cursor} is returned with the
         // {@link 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();
         }
        Parameters:
        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:
        this Builder
      • setNumberFoundAccuracy

        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 setFieldsToReturn(String...).
        Parameters:
        numberFoundAccuracy - the minimum accuracy requirement
        Returns:
        this Builder
        Throws:
        IllegalArgumentException - if the accuracy is not within acceptable range
      • setFieldsToReturn

        public QueryOptions.Builder setFieldsToReturn​(String... fields)
        Specifies one or more fields to return in results.
        Parameters:
        fields - the names of fields to return in results
        Returns:
        this Builder
        Throws:
        IllegalArgumentException - if any of the field names is invalid
      • setFieldsToSnippet

        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().
        Parameters:
        fieldsToSnippet - the names of fields to snippet in results
        Returns:
        this Builder
        Throws:
        IllegalArgumentException - if any of the field names is invalid
      • addExpressionToReturn

        public QueryOptions.Builder addExpressionToReturn​(FieldExpression expression)
        Adds a FieldExpression to return in search results.
        Parameters:
        expression - a named expression to compute and return in results
        Returns:
        this Builder
      • build

        public QueryOptions build()
        Construct the final message.
        Returns:
        the QueryOptions built from the parameters entered on this Builder
        Throws:
        IllegalArgumentException - if the search request is invalid