SortOptions.Builder (Google App Engine API for Java)

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 sort documents based on decreasing product rating and then within rating showing cheapest products based on price plus tax, sorting 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 and sorted.
       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();