1 // Copyright 2012 Google Inc. All Rights Reserved.
3 package com
.google
.appengine
.api
.search
;
6 * Assigns a document score based on term frequency.
8 * If you add a MatchScorer to a SortOptions as in the following code:
10 * SortOptions sortOptions = SortOptions.newBuilder()
11 * .setMatchScorer(MatchScorer.newBuilder())
14 * then this will sort the documents in descending score order. The scores
15 * will be positive. If you want to sort in ascending order, then use the
18 * SortOptions sortOptions = SortOptions.newBuilder()
19 * .setMatchScorer(MatchScorer.newBuilder())
21 * SortExpression.newBuilder()
22 * .setExpression(SortExpression.SCORE_FIELD_NAME)
23 * .setDirection(SortExpression.SortDirection.ASCENDING)
24 * .setDefaultValueNumeric(0.0))
27 * The scores in this case will be negative.
30 public class MatchScorer
{
33 * A builder that constructs {@link MatchScorer MatchScorers}.
34 * A MatchScorer will invoke a scorer on each search result. The
35 * following code illustrates building a match scorer to score documents:
38 * MatchScorer scorer = MatchScorer.newBuilder().build();
41 public static class Builder
{
47 * Builds a {@link MatchScorer} from the set values.
49 * @return a {@link MatchScorer} built from the set values
51 public MatchScorer
build() {
52 return new MatchScorer(this);
57 * Constructs a text sort specification using the values from the
60 MatchScorer(Builder builder
) {
64 * Copies the contents of the MatchScorer into a scorer
65 * spec protocol buffer.
67 * @return the protocol buffer builder with the contents of the MatchScorer
70 SearchServicePb
.ScorerSpec
.Builder
copyToScorerSpecProtocolBuffer() {
71 SearchServicePb
.ScorerSpec
.Builder builder
= SearchServicePb
.ScorerSpec
.newBuilder();
72 builder
.setScorer(SearchServicePb
.ScorerSpec
.Scorer
.MATCH_SCORER
);
77 * Creates and returns a MatchScorer Builder.
79 * @return a new {@link MatchScorer.Builder}. Set the parameters for scorer
80 * on the Builder, and use the {@link Builder#build()} method
81 * to create a concrete instance of MatchScorer
83 public static Builder
newBuilder() {
88 public String
toString() {
89 return "MatchScorer()";