add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / highlighter / src / java / org / apache / lucene / search / highlight / Scorer.java
1 package org.apache.lucene.search.highlight;
2
3 /**
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 import java.io.IOException;
21
22 import org.apache.lucene.analysis.TokenStream;
23
24 /**
25  * A Scorer is responsible for scoring a stream of tokens. These token scores
26  * can then be used to compute {@link TextFragment} scores.
27  */
28 public interface Scorer {
29
30   /**
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()}.
33    * 
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.
38    * @throws IOException
39    */
40   public TokenStream init(TokenStream tokenStream) throws IOException;
41
42   /**
43    * Called when a new fragment is started for consideration.
44    * 
45    * @param newFragment the fragment that will be scored next
46    */
47   public void startFragment(TextFragment newFragment);
48
49   /**
50    * Called for each token in the current fragment. The {@link Highlighter} will
51    * increment the {@link TokenStream} passed to init on every call.
52    * 
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
55    *         fragment)
56    */
57   public float getTokenScore();
58
59   /**
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()}.
63    * 
64    */
65   public float getFragmentScore();
66
67 }