01: package org.apache.lucene.search;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * 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.index.IndexReader;
23:
24: /** Expert: Calculate query weights and build query scorers.
25: * <p>
26: * The purpose of Weight is to make it so that searching does not modify
27: * a Query, so that a Query instance can be reused. <br>
28: * Searcher dependent state of the query should reside in the Weight. <br>
29: * IndexReader dependent state should reside in the Scorer.
30: * <p>
31: * A <code>Weight</code> is used in the following way:
32: * <ol>
33: * <li>A <code>Weight</code> is constructed by a top-level query,
34: * given a <code>Searcher</code> ({@link Query#createWeight(Searcher)}).
35: * <li>The {@link #sumOfSquaredWeights()} method is called
36: * on the <code>Weight</code> to compute
37: * the query normalization factor {@link Similarity#queryNorm(float)}
38: * of the query clauses contained in the query.
39: * <li>The query normalization factor is passed to {@link #normalize(float)}.
40: * At this point the weighting is complete.
41: * <li>A <code>Scorer</code> is constructed by {@link #scorer(IndexReader)}.
42: * </ol>
43: */
44: public interface Weight extends java.io.Serializable {
45: /** The query that this concerns. */
46: Query getQuery();
47:
48: /** The weight for this query. */
49: float getValue();
50:
51: /** The sum of squared weights of contained query clauses. */
52: float sumOfSquaredWeights() throws IOException;
53:
54: /** Assigns the query normalization factor to this. */
55: void normalize(float norm);
56:
57: /** Constructs a scorer for this. */
58: Scorer scorer(IndexReader reader) throws IOException;
59:
60: /** An explanation of the score computation for the named document. */
61: Explanation explain(IndexReader reader, int doc) throws IOException;
62: }
|