Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.google.appengine.api.search
Class SortOptions.Builder

    java.lang.Object
      com.google.appengine.api.search.SortOptions.Builder

Enclosing class:
  SortOptions

    public static final class SortOptions.Builder

extends java.lang.Object

A builder that constructs `SortOptionss`. A SortOptions will evaluate each of the `SortExpressions` on each search result and apply a sort order with priority given to the sort expressions from left to right. The following code illustrates creating a SortOptions specification to score documents based on decreasing product rating and then within rating scores showing cheapest products based on price plus tax, scoring at most 2000 documents.

       SortOptions sortOptions = SortOptions.newBuilder()
           .addSortExpression(SortExpression.newBuilder()
               .setExpression("rating")
               .setDirection(SortExpression.SortDirection.DESCENDING)
               .setDefaultValueNumeric(0))
           .addSortExpression(SortExpression.newBuilder()
               .setExpression("price + tax")
               .setDirection(SortExpression.SortDirection.ASCENDING)
               .setDefaultValueNumeric(99999999.00))
           .setLimit(1000)
           .build();

The following code fragment shows how the score from a `MatchScorer` can be used in an expression that combines the score with one thousandth of an "importance" field. At most 1000 documents are scored.

       SortOptions sortOptions = SortOptions.newBuilder()
           .setMatchScorer(MatchScorer.newBuilder())
           .addSortExpression(SortExpression.newBuilder()
               .setExpression(String.format(
                   "%s + (importance * .001)", SortExpression.SCORE_FIELD_NAME))
               .setDirection(SortExpression.SortDirection.DESCENDING)
               .setDefaultValueNumeric(0))
           .setLimit(1000)
           .build();

Method Summary
`SortOptions.Builder` | `addSortExpression(SortExpression.Builder builder)` Adds a `SortExpression` built from the builder to the list of sort expressions.
`SortOptions.Builder` | `addSortExpression(SortExpression sortExpression)` Adds a `SortExpression` to the list of sort expressions.
`SortOptions` | `build()` Builds a `SortOptions` from the set values.
`SortOptions.Builder` | `setLimit(int limit)` Sets the limit on the number of documents to score.
`SortOptions.Builder` | `setMatchScorer(MatchScorer.Builder builder)` Sets the matchScorer to the `MatchScorer` built from the builder.
`SortOptions.Builder` | `setMatchScorer(MatchScorer matchScorer)` Sets a `MatchScorer` or `RescoringMatchScorer` to base some `SortExpressions` on.
`SortOptions.Builder` | `setMatchScorer(RescoringMatchScorer.Builder builder)` Sets the matchScorer to the `RescoringMatchScorer` built from the builder.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### setLimit

    public SortOptions.Builder setLimit(int limit)

  Sets the limit on the number of documents to score.

  Parameters:
    `limit` - the maximum number of documents to score
  Returns:
    this builder
  Throws:
    `java.lang.IllegalArgumentException` - if the limit is out of range

### setMatchScorer

    public SortOptions.Builder setMatchScorer(MatchScorer matchScorer)

  Sets a `MatchScorer` or `RescoringMatchScorer` to base some `SortExpressions` on. The value of the matchScorer can be accessed by using the field name "_score".

  Parameters:
    `matchScorer` - the rescoring/match matchScorer to use in an expression built on "_score"
  Returns:
    this builder

### setMatchScorer

    public SortOptions.Builder setMatchScorer(MatchScorer.Builder builder)

  Sets the matchScorer to the `MatchScorer` built from the builder.

  Parameters:
    `builder` - a builder of a MatchScorer
  Returns:
    this builder
  See Also:
    `#setMatchScorer(MatchScorer)}`

### setMatchScorer

    public SortOptions.Builder setMatchScorer(RescoringMatchScorer.Builder builder)

  Sets the matchScorer to the `RescoringMatchScorer` built from the builder.

  Parameters:
    `builder` - a builder of a RescoringMatchScorer
  Returns:
    this builder
  See Also:
    `#setMatchScorer(MatchScorer)}`

### addSortExpression

    public SortOptions.Builder addSortExpression(SortExpression sortExpression)

  Adds a `SortExpression` to the list of sort expressions.

  Parameters:
    `sortExpression` - an expression to sort documents by
  Returns:
    this Builder

### addSortExpression

    public SortOptions.Builder addSortExpression(SortExpression.Builder builder)

  Adds a `SortExpression` built from the builder to the list of sort expressions.

  Parameters:
    `builder` - a builder of SortExpression to sort documents by
  Returns:
    this Builder

### build

    public SortOptions build()

  Builds a `SortOptions` from the set values.

  Returns:
    a `SortOptions` built from the set values

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD