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 SortSpec.Builder

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

Enclosing class:
  SortSpec

    public static final class SortSpec.Builder

extends java.lang.Object

A builder that constructs `SortSpecs`. There are two kinds of SortSpec: custom or scorer. In a custom SortSpec, the user must provide an expression. The expression can be as simple as a field name, or can be some other evaluable expression such as 'score + count(likes) * 0.1' which combines a scorer score with a count of the number of likes values times 0.1.

       SortSpec spec = SortSpec.newBuilder()
           .setType(ScorerType.CUSTOM)
           .setExpression("score + count(likes) * 0.1")
           .build()

A scoring SortSpec will invoke a scorer on each search result. The following code illustrates setting a match scorer to score documents, scoring at most 1000 documents.

       SortSpec spec = SortSpec.newBuilder()
           .setType(SortType.MATCH_SCORER)
           .setLimit(1000)
           .build()

Method Summary
`SortSpec` | `build()` Builds a `SortSpec` from the set values.
`SortSpec.Builder` | `setDefaultValue(java.lang.String defaultValue)` Sets the default value for the field for sorting purposes.
`SortSpec.Builder` | `setDefaultValueNumeric(double defaultValue)` Sets the default value for the field for sorting purposes.
`SortSpec.Builder` | `setExpression(java.lang.String expression)` Sets an expression to be evaluated for each document to sort by.
`SortSpec.Builder` | `setLimit(int limit)` Sets the limit on the number of documents to score.
`SortSpec.Builder` | `setSortDescending(boolean sortDescending)` Sets whether to sort descending or ascending order.
`SortSpec.Builder` | `setType(SortSpec.SortType type)` Sets the type of SortSpec to build.

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

Method Detail

### setType

    public SortSpec.Builder setType(SortSpec.SortType type)

  Sets the type of SortSpec to build.

  Parameters:
    `type` - the type of SortSpec to build
  Returns:
    this builder

### setLimit

    public SortSpec.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

### setExpression

    public SortSpec.Builder setExpression(java.lang.String expression)

  Sets an expression to be evaluated for each document to sort by.

  Parameters:
    `expression` - the expression to evaluate for each document to sort by
  Returns:
    this Builder
  Throws:
    `java.lang.IllegalArgumentException` - if the expression is invalid

### setSortDescending

    public SortSpec.Builder setSortDescending(boolean sortDescending)

  Sets whether to sort descending or ascending order.

  Parameters:
    `sortDescending` - whether to sort in descending order or not
  Returns:
    this Builder

### setDefaultValue

    public SortSpec.Builder setDefaultValue(java.lang.String defaultValue)

  Sets the default value for the field for sorting purposes. Must provide for text sorts.

  Parameters:
    `defaultValue` - the default value for the field
  Returns:
    this Builder
  Throws:
    `java.lang.IllegalArgumentException` - if the `defaultValue` is not valid

### setDefaultValueNumeric

    public SortSpec.Builder setDefaultValueNumeric(double defaultValue)

  Sets the default value for the field for sorting purposes. Must provide for numeric sorts.

  Parameters:
    `defaultValue` - the default value for the field
  Returns:
    this Builder

### build

    public SortSpec build()

  Builds a `SortSpec` from the set values.

  Returns:
    a `SortSpec` built from the set values
  Throws:
    `java.lang.IllegalArgumentException` - if the field name or default value is invalid

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