1 // Copyright 2012 Google Inc. All Rights Reserved.
3 package com
.google
.appengine
.api
.search
;
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:
10 * SortOptions sortOptions = SortOptions.newBuilder()
11 * .setMatchScorer(RescoringMatchScorer.newBuilder())
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:
17 * SortOptions sortOptions = SortOptions.newBuilder()
18 * .setMatchScorer(RescoringMatchScorer.newBuilder())
20 * SortExpression.newBuilder()
21 * .setExpression(SortExpression.SCORE_FIELD_NAME)
22 * .setDirection(SortExpression.SortDirection.ASCENDING)
23 * .setDefaultValueNumeric(0.0))
26 * The scores in this case will be negative.
29 public final class RescoringMatchScorer
extends MatchScorer
{
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:
37 * RescoringMatchScorer scorer = RescoringMatchScorer.newBuilder().build();
40 public static final class Builder
extends MatchScorer
.Builder
{
46 * Builds a {@link RescoringMatchScorer} from the set values.
48 * @return a {@link RescoringMatchScorer} built from the set values
51 public RescoringMatchScorer
build() {
52 return new RescoringMatchScorer(this);
57 * Constructs a text sort specification using the values from the
60 private RescoringMatchScorer(Builder builder
) {
61 super(MatchScorer
.newBuilder());
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
72 SearchServicePb
.ScorerSpec
.Builder
copyToScorerSpecProtocolBuffer() {
73 SearchServicePb
.ScorerSpec
.Builder builder
= SearchServicePb
.ScorerSpec
.newBuilder();
74 builder
.setScorer(SearchServicePb
.ScorerSpec
.Scorer
.RESCORING_MATCH_SCORER
);
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() {
90 public String
toString() {
91 return "RescoringMatchScorer()";