1 package org.apache.lucene.search.highlight;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.io.IOException;
22 import org.apache.lucene.analysis.TokenStream;
25 * A Scorer is responsible for scoring a stream of tokens. These token scores
26 * can then be used to compute {@link TextFragment} scores.
28 public interface Scorer {
31 * Called to init the Scorer with a {@link TokenStream}. You can grab references to
32 * the attributes you are interested in here and access them from {@link #getTokenScore()}.
34 * @param tokenStream the {@link TokenStream} that will be scored.
35 * @return either a {@link TokenStream} that the Highlighter should continue using (eg
36 * if you read the tokenSream in this method) or null to continue
37 * using the same {@link TokenStream} that was passed in.
40 public TokenStream init(TokenStream tokenStream) throws IOException;
43 * Called when a new fragment is started for consideration.
45 * @param newFragment the fragment that will be scored next
47 public void startFragment(TextFragment newFragment);
50 * Called for each token in the current fragment. The {@link Highlighter} will
51 * increment the {@link TokenStream} passed to init on every call.
53 * @return a score which is passed to the {@link Highlighter} class to influence the
54 * mark-up of the text (this return value is NOT used to score the
57 public float getTokenScore();
60 * Called when the {@link Highlighter} has no more tokens for the current fragment -
61 * the Scorer returns the weighting it has derived for the most recent
62 * fragment, typically based on the results of {@link #getTokenScore()}.
65 public float getFragmentScore();