/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using IndexReader = Lucene.Net.Index.IndexReader;
namespace Lucene.Net.Search
{
/// Expert: Calculate query weights and build query scorers.
///
/// The purpose of {@link Weight} is to ensure searching does not
/// modify a {@link Query}, so that a {@link Query} instance can be reused.
/// {@link Searcher} dependent state of the query should reside in the
/// {@link Weight}.
/// {@link IndexReader} dependent state should reside in the {@link Scorer}.
///
/// A Weight
is used in the following way:
///
/// - A
Weight
is constructed by a top-level query, given a
/// Searcher
({@link Query#CreateWeight(Searcher)}).
/// - The {@link #SumOfSquaredWeights()} method is called on the
///
Weight
to compute the query normalization factor
/// {@link Similarity#QueryNorm(float)} of the query clauses contained in the
/// query.
/// - The query normalization factor is passed to {@link #Normalize(float)}. At
/// this point the weighting is complete.
/// - A
Scorer
is constructed by {@link #Scorer(IndexReader,boolean,boolean)}.
///
///
///
/// 2.9
///
[Serializable]
public abstract class Weight
{
/// An explanation of the score computation for the named document.
///
///
/// sub-reader containing the give doc
///
///
///
/// an Explanation for the score
///
/// IOException
public abstract Explanation Explain(IndexReader reader, int doc);
/// The query that this concerns.
public abstract Query GetQuery();
/// The weight for this query.
public abstract float GetValue();
/// Assigns the query normalization factor to this.
public abstract void Normalize(float norm);
/// Returns a {@link Scorer} which scores documents in/out-of order according
/// to scoreDocsInOrder
.
///
/// NOTE: even if scoreDocsInOrder
is false, it is
/// recommended to check whether the returned Scorer
indeed scores
/// documents out of order (i.e., call {@link #ScoresDocsOutOfOrder()}), as
/// some Scorer
implementations will always return documents
/// in-order.
/// NOTE: null can be returned if no documents will be scored by this
/// query.
///
///
///
/// the {@link IndexReader} for which to return the {@link Scorer}.
///
/// specifies whether in-order scoring of documents is required. Note
/// that if set to false (i.e., out-of-order scoring is required),
/// this method can return whatever scoring mode it supports, as every
/// in-order scorer is also an out-of-order one. However, an
/// out-of-order scorer may not support {@link Scorer#NextDoc()}
/// and/or {@link Scorer#Advance(int)}, therefore it is recommended to
/// request an in-order scorer if use of these methods is required.
///
///
/// if true, {@link Scorer#Score(Collector)} will be called; if false,
/// {@link Scorer#NextDoc()} and/or {@link Scorer#Advance(int)} will
/// be called.
///
/// a {@link Scorer} which scores documents in/out-of order.
///
/// IOException
public abstract Scorer Scorer(IndexReader reader, bool scoreDocsInOrder, bool topScorer);
/// The sum of squared weights of contained query clauses.
public abstract float SumOfSquaredWeights();
/// Returns true iff this implementation scores docs only out of order. This
/// method is used in conjunction with {@link Collector}'s
/// {@link Collector#AcceptsDocsOutOfOrder() acceptsDocsOutOfOrder} and
/// {@link #Scorer(Lucene.Net.Index.IndexReader, boolean, boolean)} to
/// create a matching {@link Scorer} instance for a given {@link Collector}, or
/// vice versa.
///
/// NOTE: the default implementation returns false
, i.e.
/// the Scorer
scores documents in-order.
///
public virtual bool ScoresDocsOutOfOrder()
{
return false;
}
}
}