Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / search / RescoringMatchScorer.java
blob646e891b1517ec3a7cfbd54b56dc579c57dfa7f0
1 // Copyright 2012 Google Inc. All Rights Reserved.
3 package com.google.appengine.api.search;
5 /**
6 * Assigns a document score based on term frequency weighted on document parts.
8 * If you add a MatchScorer to a SortOptions as in the following code:
9 * <pre>
10 * SortOptions sortOptions = SortOptions.newBuilder()
11 * .setMatchScorer(RescoringMatchScorer().newBuilder())
12 * .build();
13 * </pre>
14 * then this will sort the documents in descending score order. The scores will be
15 * positive. If you want to sort in ascending order, then use the following code:
16 * <pre>
17 * SortOptions sortOptions = SortOptions.newBuilder()
18 * .setMatchScorer(RescoringMatchScorer.newBuilder())
19 * .addSortExpression(
20 * SortExpression.newBuilder()
21 * .setExpression(SortExpression.SCORE_FIELD_NAME)
22 * .setDirection(SortExpression.SortDirection.ASCENDING)
23 * .setDefaultValueNumeric(0.0))
24 * .build();
25 * </pre>
26 * The scores in this case will be negative.
29 public final class RescoringMatchScorer extends MatchScorer {
31 /**
32 * A builder that constructs {@link RescoringMatchScorer RescoringMatchScorers}.
33 * A RescoringMatchScorer will invoke a scorer on each search result. The
34 * following code illustrates building a rescoring match scorer to score documents:
35 * <p>
36 * <pre>
37 * RescoringMatchScorer scorer = RescoringMatchScorer.newBuilder().build();
38 * </pre>
40 public static final class Builder extends MatchScorer.Builder {
42 private Builder() {
45 /**
46 * Builds a {@link RescoringMatchScorer} from the set values.
48 * @return a {@link RescoringMatchScorer} built from the set values
50 @Override
51 public RescoringMatchScorer build() {
52 return new RescoringMatchScorer(this);
56 /**
57 * Constructs a text sort specification using the values from the
58 * {@link Builder}.
60 private RescoringMatchScorer(Builder builder) {
61 super(MatchScorer.newBuilder());
64 /**
65 * Copies the contents of the RescoringMatchScorer into a scorer
66 * spec protocol buffer.
68 * @return the protocol buffer builder with the contents of the
69 * RescoringMatchScorer scoring information
71 @Override
72 SearchServicePb.ScorerSpec.Builder copyToScorerSpecProtocolBuffer() {
73 SearchServicePb.ScorerSpec.Builder builder = SearchServicePb.ScorerSpec.newBuilder();
74 builder.setScorer(SearchServicePb.ScorerSpec.Scorer.RESCORING_MATCH_SCORER);
75 return builder;
78 /**
79 * Creates and returns a RescoringMatchScorer Builder.
81 * @return a new {@link RescoringMatchScorer.Builder}. Set the parameters for scorer
82 * on the Builder, and use the {@link Builder#build()} method
83 * to create a concrete instance of RescoringMatchScorer
85 public static Builder newBuilder() {
86 return new Builder();
89 @Override
90 public String toString() {
91 return "RescoringMatchScorer()";