use crate::core::document::{
binary_range_field_range_query, lat_lon_doc_values_box_query, lat_lon_doc_values_query,
lat_lon_point_distance_feature_query, sorted_numeric_doc_values_range_query,
sorted_numeric_doc_values_set_query, sorted_set_doc_values_range_query,
xy_doc_values_point_in_geometry_query,
};
use crate::core::geo::geometry::Geometry;
use crate::core::geo::lat_lon_geometry::{LatLonGeometryEnumComponent2D, LatLonGeometryType};
use crate::core::geo::xy_geometry::{XYGeometryEnum, XYGeometryType};
use crate::core::index::doc_values::NumericDocValuesEnum3WithEmpty;
use crate::core::index::doc_values::{
BinaryDocValuesWithEmpty, SortedDocValuesWithEmpty, SortedNumericDocValuesEnum3WithEmpty,
};
use crate::core::index::impacts_enum::ImpactsEnumEnum2;
use crate::core::index::singleton_sorted_numeric_doc_values::SingletonSortedNumericDocValues;
use crate::core::index::singleton_sorted_set_doc_values::SingletonSortedSetDocValues;
use crate::core::index::slow_impacts_enum::SlowImpactsEnum;
use crate::core::index::sorted_numeric_doc_values::SortedNumericDocValues;
use crate::core::index::sorted_set_doc_values::SortedSetDocValues;
use crate::core::index::sorted_set_doc_values_writer::SortedSetDocValuesEnum2;
use crate::core::search::approximation_disi::ApproximationBitSetAccess;
use crate::core::search::approximation_disi::ApproximationDISI;
use crate::core::search::block_max_conjunction_scorer::BlockMaxConjunctionScorer;
use crate::core::search::boolean_scorer_supplier::FilterScorerImpl;
use crate::core::search::conjunction_scorer::ConjunctionScorer;
use crate::core::search::constant_score_scorer::ConstantScoreScorer;
use crate::core::search::disjunction_disi_approximation::DisjunctionDISIApproximation;
use crate::core::search::disjunction_max_scorer::DisjunctionMaxScorer;
use crate::core::search::disjunction_scorer::DisjunctionScorer;
use crate::core::search::disjunction_sum_scorer::DisjunctionSumScorer;
use crate::core::search::doc_id_set_iterator::{
AllDISI, BitSetIteratorAccess, DocIdSetIterator, DocIdSetIteratorExtensions, EmptyDISI,
};
use crate::core::search::doc_id_set_iterator::{
DocIdSetIteratorEnum2, DocIdSetIteratorEnum4, DocIdSetIteratorEnum5,
};
use crate::core::search::doc_values_range_iterator::DocValuesRangeIterator;
use crate::core::search::exact_phrase_matcher::ExactPhraseMatcher;
use crate::core::search::multi_phrase_query::MultiPhrasePostingsEnum;
use crate::core::search::phrase_scorer::PhraseScorer;
use crate::core::search::phrase_weight::SimScorerType;
use crate::core::search::req_excl_scorer::ReqExclScorer;
use crate::core::search::req_opt_sum_scorer::ReqOptSumScorer;
use crate::core::search::scorable::{ChildScorable, Scorable};
use crate::core::search::scorer::{Scorer, ScorerEnum2, ScorerEnum3, ScorerEnum4, TwoPhaseState};
use crate::core::search::scorer_types::{LeafScorerTypes, ScorerTypes};
use crate::core::search::similarities_impl::similarities::SimilaritySimScorer;
use crate::core::search::sloppy_phrase_matcher::SloppyPhraseMatcher;
use crate::core::search::term_query::TermQuerySimScorer;
use crate::core::search::term_scorer::{ImpactsTermState, PostingsTermState, TermScorer};
use crate::core::search::two_phase_iterator::TwoPhaseIteratorEnum2;
use crate::core::search::two_phase_iterator::{
TwoPhaseIterator, TwoPhaseIteratorAsDocIdSetIterator,
};
use crate::core::search::wand_scorer::WANDScorer;
use crate::core::search::{
abstract_knn_vector_query, abstract_vector_similarity_query, doc_values_rewrite_method,
index_sort_sorted_numeric_doc_values_range_query, lru_query_cache,
};
use crate::core::util::bit_set_iterator::BitSetIterator;
use crate::core::util::doc_id_set_builder::OwnedDocIdSetBuilderIterator;
use crate::core::util::error::lucene_error::Result;
use crate::core::util::fixed_bit_set::FixedBitSet;
use crate::sandbox::search::term_automaton_scorer::TermAutomatonScorer;
use std::sync::Arc;
pub struct BuiltinQueryScorer<ST: ScorerTypes> {
inner: Box<dyn ScorerDispatch<ST>>,
}
pub trait IntoQueryScorer<ST: ScorerTypes> {
fn into_query_scorer(self) -> BuiltinQueryScorer<ST>;
fn into_query_scorer_from_box(self: Box<Self>) -> BuiltinQueryScorer<ST>
where
Self: Sized,
{
(*self).into_query_scorer()
}
}
trait ScorerDispatch<ST: ScorerTypes>: DocIdSetIterator {
fn score(&mut self) -> Result<f32>;
fn smoothing_score(&mut self, doc: i32) -> Result<f32>;
fn set_min_competitive_score(&mut self, min: f32) -> Result<()>;
fn scorable_cost(&self) -> Result<i64>;
fn get_children(&mut self) -> Result<Vec<ChildScorable<QueryChildScorable<'_, ST>>>>;
fn scoring_doc_id(&mut self) -> Result<i32>;
fn advance_shallow(&mut self, target: i32) -> Result<i32>;
fn default_advance_shallow(&mut self, target: i32) -> Result<i32>;
fn get_max_score(&mut self, upto: i32) -> Result<f32>;
fn default_cost(&mut self) -> Result<i64>;
fn has_two_phase_iterator(&self) -> TwoPhaseState;
fn matches(&mut self) -> Result<bool>;
fn match_cost(&self) -> f32;
fn approximation_doc_id(&self) -> i32;
fn approximation_cost(&self) -> Result<i64>;
fn approximation_next_doc(&mut self) -> Result<i32>;
fn approximation_advance(&mut self, target: i32) -> Result<i32>;
fn approximation_slow_advance(&mut self, target: i32) -> Result<i32>;
fn approximation_is_bit_iter(&self) -> bool;
fn approximation_get(&self, index: usize) -> Result<bool>;
fn approximation_set_doc_id(&mut self, doc: i32) -> Result<()>;
fn approximation_bit_set_length(&self) -> Result<usize>;
fn into_default_bulk(self: Box<Self>) -> DefaultQueryBulkScorer<ST>;
#[cfg(test)]
fn kind(&self) -> crate::core::search::scorer::ScorerKind;
}
macro_rules! scorer_dispatch {
($ty:ty, $variant:ident, $owner:ident, $bulk:expr) => {
impl<ST: ScorerTypes> ScorerDispatch<ST> for $ty {
fn score(&mut self) -> Result<f32> {
Scorable::score(self)
}
fn smoothing_score(&mut self, doc: i32) -> Result<f32> {
Scorable::smoothing_score(self, doc)
}
fn set_min_competitive_score(&mut self, min: f32) -> Result<()> {
Scorable::set_min_competitive_score(self, min)
}
fn scorable_cost(&self) -> Result<i64> {
Scorable::cost(self)
}
fn get_children(&mut self) -> Result<Vec<ChildScorable<QueryChildScorable<'_, ST>>>> {
Scorable::get_children(self).map(|children| {
children
.into_iter()
.map(|child| ChildScorable {
child: child.child.into_query_child(),
relationship: child.relationship,
})
.collect()
})
}
fn scoring_doc_id(&mut self) -> Result<i32> {
Scorer::scoring_doc_id(self)
}
fn advance_shallow(&mut self, target: i32) -> Result<i32> {
Scorer::advance_shallow(self, target)
}
fn default_advance_shallow(&mut self, target: i32) -> Result<i32> {
Scorer::default_advance_shallow(self, target)
}
fn get_max_score(&mut self, upto: i32) -> Result<f32> {
Scorer::get_max_score(self, upto)
}
fn default_cost(&mut self) -> Result<i64> {
Scorer::default_cost(self)
}
fn has_two_phase_iterator(&self) -> TwoPhaseState {
Scorer::has_two_phase_iterator(self)
}
fn matches(&mut self) -> Result<bool> {
TwoPhaseIterator::matches(self)
}
fn match_cost(&self) -> f32 {
TwoPhaseIterator::match_cost(self)
}
fn approximation_doc_id(&self) -> i32 {
ApproximationDISI::approx_doc_id(self)
}
fn approximation_cost(&self) -> Result<i64> {
ApproximationDISI::approx_cost(self)
}
fn approximation_next_doc(&mut self) -> Result<i32> {
ApproximationDISI::approx_next_doc(self)
}
fn approximation_advance(&mut self, target: i32) -> Result<i32> {
ApproximationDISI::approx_advance(self, target)
}
fn approximation_slow_advance(&mut self, target: i32) -> Result<i32> {
ApproximationDISI::approx_slow_advance(self, target)
}
fn approximation_is_bit_iter(&self) -> bool {
ApproximationBitSetAccess::approx_is_bit_iter(self)
}
fn approximation_get(&self, index: usize) -> Result<bool> {
ApproximationBitSetAccess::approx_get(self, index)
}
fn approximation_set_doc_id(&mut self, doc: i32) -> Result<()> {
ApproximationBitSetAccess::approx_set_doc_id(self, doc)
}
fn approximation_bit_set_length(&self) -> Result<usize> {
ApproximationBitSetAccess::approx_bit_set_length(self)
}
fn into_default_bulk(self: Box<Self>) -> DefaultQueryBulkScorer<ST> {
let $owner = self;
DefaultQueryBulkScorer::$variant($bulk)
}
#[cfg(test)]
fn kind(&self) -> crate::core::search::scorer::ScorerKind {
Scorer::kind(self)
}
}
};
}
macro_rules! scorer_nodes {
(boxed { $( $(#[$attrs:meta])* $variant:ident: $ty:ty, )+ }
inline { $( $inline:ident: $inline_ty:ty, )+ }) => {
pub(crate) enum DefaultQueryBulkScorer<ST: ScorerTypes> {
#[cfg(test)] Fixture(crate::core::search::weight::DefaultBulkScorer<Box<dyn crate::test_framework::core::search::test_scorer::TestScorer>>),
$( $(#[$attrs])* $variant(crate::core::search::weight::DefaultBulkScorer<Box<$ty>>), )+
$( $inline(crate::core::search::weight::DefaultBulkScorer<$inline_ty>), )+
}
impl<ST: ScorerTypes> crate::core::search::bulk_scorer::BulkScorer for DefaultQueryBulkScorer<ST> {
fn score<CLC: crate::core::search::leaf_collector::LeafCollector, AB: crate::core::util::bits::Bits + ?Sized>(&mut self, collector: &mut CLC, accept_docs: Option<&AB>, min: i32, max: i32) -> Result<i32> {
match self { $( $(#[$attrs])* Self::$variant(scorer) => scorer.score(collector, accept_docs, min, max), )+ $( Self::$inline(scorer) => scorer.score(collector, accept_docs, min, max), )+ #[cfg(test)] Self::Fixture(scorer) => scorer.score(collector, accept_docs, min, max), }
}
fn cost(&mut self) -> Result<i64> { match self { $( $(#[$attrs])* Self::$variant(scorer) => scorer.cost(), )+ $( Self::$inline(scorer) => scorer.cost(), )+ #[cfg(test)] Self::Fixture(scorer) => scorer.cost(), } }
#[cfg(test)]
fn kind(&self) -> crate::core::search::bulk_scorer::BulkScorerKind { crate::core::search::bulk_scorer::BulkScorerKind::Default }
}
impl<ST: ScorerTypes> BuiltinQueryScorer<ST> {
pub(crate) fn into_default_bulk(self) -> DefaultQueryBulkScorer<ST> {
self.inner.into_default_bulk()
}
}
$( $(#[$attrs])* scorer_dispatch!($ty, $variant, owner, crate::core::search::weight::DefaultBulkScorer::new(owner)); )+
$( scorer_dispatch!($inline_ty, $inline, owner, crate::core::search::weight::DefaultBulkScorer::new(*owner)); )+
#[cfg(test)]
scorer_dispatch!(Box<dyn crate::test_framework::core::search::test_scorer::TestScorer>, Fixture, owner, crate::core::search::weight::DefaultBulkScorer::new(*owner));
$( $(#[$attrs])* impl<ST: ScorerTypes> IntoQueryScorer<ST> for $ty {
fn into_query_scorer(self) -> BuiltinQueryScorer<ST> {
BuiltinQueryScorer { inner: Box::new(self) }
}
fn into_query_scorer_from_box(self: Box<Self>) -> BuiltinQueryScorer<ST> {
BuiltinQueryScorer { inner: self }
}
} )+
$( impl<ST: ScorerTypes> IntoQueryScorer<ST> for $inline_ty {
fn into_query_scorer(self) -> BuiltinQueryScorer<ST> {
BuiltinQueryScorer { inner: Box::new(self) }
}
fn into_query_scorer_from_box(self: Box<Self>) -> BuiltinQueryScorer<ST> {
BuiltinQueryScorer { inner: self }
}
} )+
};
}
type OwnedSortedNumeric<ST> = SortedNumericDocValuesEnum3WithEmpty<
<ST as ScorerTypes>::SortedNumeric,
SingletonSortedNumericDocValues<<ST as ScorerTypes>::Numeric>,
>;
type OwnedSortedSet<ST> = SortedSetDocValuesEnum2<
<ST as ScorerTypes>::SortedSet,
SingletonSortedSetDocValues<SortedDocValuesWithEmpty<<ST as ScorerTypes>::Sorted>>,
>;
type SingletonNumeric<ST> = <OwnedSortedNumeric<ST> as SortedNumericDocValues>::NumericDocValues;
type SingletonSorted<ST> = <OwnedSortedSet<ST> as SortedSetDocValues>::SortedDocValues;
type NumericRangeTwoPhase<ST> = TwoPhaseIteratorEnum2<
sorted_numeric_doc_values_range_query::TwoPhaseIterator3<SingletonNumeric<ST>>,
sorted_numeric_doc_values_range_query::TwoPhaseIterator4<OwnedSortedNumeric<ST>>,
>;
type NumericSetTwoPhase<ST> = TwoPhaseIteratorEnum2<
sorted_numeric_doc_values_set_query::TwoPhaseIterator1<SingletonNumeric<ST>>,
sorted_numeric_doc_values_set_query::TwoPhaseIterator2<OwnedSortedNumeric<ST>>,
>;
type SortedRangeTwoPhase<ST> = TwoPhaseIteratorEnum2<
sorted_set_doc_values_range_query::TwoPhaseIterator5<SingletonSorted<ST>>,
sorted_set_doc_values_range_query::TwoPhaseIterator6<OwnedSortedSet<ST>>,
>;
type SortedTermSetTwoPhase<ST> = TwoPhaseIteratorEnum2<
doc_values_rewrite_method::SingletonTermSetTwoPhaseIterator<SingletonSorted<ST>>,
doc_values_rewrite_method::SortedSetTermSetTwoPhaseIterator<OwnedSortedSet<ST>>,
>;
type DistanceValues<ST> = NumericDocValuesEnum3WithEmpty<
lat_lon_point_distance_feature_query::NumericDocValuesImpl<<ST as ScorerTypes>::SortedNumeric>,
<ST as ScorerTypes>::Numeric,
>;
type FieldExistsIterator<ST> = DocIdSetIteratorEnum4<
<ST as ScorerTypes>::ByteIterator,
<ST as ScorerTypes>::FloatIterator,
<ST as ScorerTypes>::Norm,
DocIdSetIteratorEnum5<
<ST as ScorerTypes>::Numeric,
<ST as ScorerTypes>::Binary,
<ST as ScorerTypes>::Sorted,
<ST as ScorerTypes>::SortedNumeric,
<ST as ScorerTypes>::SortedSet,
>,
>;
type BlendedIterator<ST> = DisjunctionDISIApproximation<
ConstantScoreScorer<
crate::core::search::constant_score_scorer::DisiState<
DocIdSetIteratorEnum2<OwnedDocIdSetBuilderIterator, <ST as ScorerTypes>::Posting>,
>,
>,
>;
scorer_nodes! {
boxed {
#[cfg(test)] SharedBitSet: ConstantScoreScorer<crate::core::search::constant_score_scorer::DisiState<BitSetIterator<Arc<FixedBitSet>>>>,
#[cfg(test)] SharedBitSetTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopDisiState<BitSetIterator<Arc<FixedBitSet>>>>,
#[cfg(test)] BlockScore: crate::test_framework::core::search::block_score_query_wrapper::BlockScoreScorer,
#[cfg(test)] RandomApproximation: crate::test_framework::core::search::random_approximation_query::RandomApproximationScorer<BuiltinQueryScorer<ST>>,
#[cfg(test)] MaxScoreWrapper: crate::test_framework::core::search::query::MaxScoreWrapperScorer<BuiltinQueryScorer<ST>>,
#[cfg(test)] Asserting: crate::test_framework::core::search::asserting_scorer::AssertingScorer,
#[cfg(test)] Fake: crate::test::core::search::test_boolean2_scorer_supplier::FakeScorer,
Synonym: crate::core::search::synonym_query::SynonymScorer<ST, ST::Similarity>,
SynonymTerm: crate::core::search::synonym_query::SynonymTermScorer<ST, ST::Similarity>,
BoostedSynonymTerm: crate::core::search::synonym_query::FreqBoostTermScorer<ST, ST::Similarity>,
PhraseExact: PhraseScorer<ExactPhraseMatcher<ImpactsEnumEnum2<ST::Impacts, SlowImpactsEnum<ST::Posting>>, Arc<SimScorerType<ST::Similarity>>>, ST::Norm, false>,
PhraseSloppy: PhraseScorer<SloppyPhraseMatcher<ImpactsEnumEnum2<ST::Impacts, SlowImpactsEnum<ST::Posting>>, Arc<SimScorerType<ST::Similarity>>>, ST::Norm, false>,
PhraseTopExact: PhraseScorer<ExactPhraseMatcher<ImpactsEnumEnum2<ST::Impacts, SlowImpactsEnum<ST::Posting>>, Arc<SimScorerType<ST::Similarity>>, true>, ST::Norm, true>,
PhraseTopSloppy: PhraseScorer<SloppyPhraseMatcher<ImpactsEnumEnum2<ST::Impacts, SlowImpactsEnum<ST::Posting>>, Arc<SimScorerType<ST::Similarity>>>, ST::Norm, true>,
MultiPhraseExact: PhraseScorer<ExactPhraseMatcher<SlowImpactsEnum<MultiPhrasePostingsEnum<ST::Posting>>, Arc<SimScorerType<ST::Similarity>>>, ST::Norm, false>,
MultiPhraseSloppy: PhraseScorer<SloppyPhraseMatcher<SlowImpactsEnum<MultiPhrasePostingsEnum<ST::Posting>>, Arc<SimScorerType<ST::Similarity>>>, ST::Norm, false>,
MultiPhraseTopExact: PhraseScorer<ExactPhraseMatcher<SlowImpactsEnum<MultiPhrasePostingsEnum<ST::Posting>>, Arc<SimScorerType<ST::Similarity>>, true>, ST::Norm, true>,
MultiPhraseTopSloppy: PhraseScorer<SloppyPhraseMatcher<SlowImpactsEnum<MultiPhrasePostingsEnum<ST::Posting>>, Arc<SimScorerType<ST::Similarity>>>, ST::Norm, true>,
SpatialSet: ConstantScoreScorer<crate::core::search::constant_score_scorer::DisiState<DocIdSetIteratorEnum2<EmptyDISI, BitSetIterator<FixedBitSet>>>>,
SpatialSetTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopDisiState<DocIdSetIteratorEnum2<EmptyDISI, BitSetIterator<FixedBitSet>>>>,
CachedSet: ConstantScoreScorer<crate::core::search::constant_score_scorer::DisiState<lru_query_cache::CacheAndCountDISI>>,
CachedSetTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopDisiState<lru_query_cache::CacheAndCountDISI>>,
CachedSetOrEmpty: ConstantScoreScorer<crate::core::search::constant_score_scorer::DisiState<lru_query_cache::DISI>>,
CachedSetOrEmptyTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopDisiState<lru_query_cache::DISI>>,
SortedRangeIterator: ConstantScoreScorer<crate::core::search::constant_score_scorer::DisiState<sorted_numeric_doc_values_range_query::DISI>>,
SortedRangeIteratorTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopDisiState<sorted_numeric_doc_values_range_query::DISI>>,
IndexSortedIterator: ConstantScoreScorer<crate::core::search::constant_score_scorer::DisiState<index_sort_sorted_numeric_doc_values_range_query::IteratorAndCountDisi<SingletonNumeric<ST>>>>,
IndexSortedIteratorTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopDisiState<index_sort_sorted_numeric_doc_values_range_query::IteratorAndCountDisi<SingletonNumeric<ST>>>>,
FieldExists: ConstantScoreScorer<crate::core::search::constant_score_scorer::DisiState<FieldExistsIterator<ST>>>,
FieldExistsTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopDisiState<FieldExistsIterator<ST>>>,
BlendedTerms: ConstantScoreScorer<crate::core::search::constant_score_scorer::DisiState<BlendedIterator<ST>>>,
BlendedTermsTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopDisiState<BlendedIterator<ST>>>,
BinaryRange: ConstantScoreScorer<crate::core::search::constant_score_scorer::TpiState<binary_range_field_range_query::BinaryRangeFieldRangeTPI<BinaryDocValuesWithEmpty<ST::Binary>>>>,
BinaryRangeTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopTpiState<binary_range_field_range_query::BinaryRangeFieldRangeTPI<BinaryDocValuesWithEmpty<ST::Binary>>>>,
LatLonBox: ConstantScoreScorer<crate::core::search::constant_score_scorer::TpiState<lat_lon_doc_values_box_query::LatLonDocValuesBoxTwoPhaseIterator<ST::SortedNumeric>>>,
LatLonBoxTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopTpiState<lat_lon_doc_values_box_query::LatLonDocValuesBoxTwoPhaseIterator<ST::SortedNumeric>>>,
LatLonShape: ConstantScoreScorer<crate::core::search::constant_score_scorer::TpiState<lat_lon_doc_values_query::LatLonDocValuesTwoPhaseIterator<ST::SortedNumeric, Arc<LatLonGeometryType<LatLonGeometryEnumComponent2D>>>>>,
LatLonShapeTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopTpiState<lat_lon_doc_values_query::LatLonDocValuesTwoPhaseIterator<ST::SortedNumeric, Arc<LatLonGeometryType<LatLonGeometryEnumComponent2D>>>>>,
XYShape: ConstantScoreScorer<crate::core::search::constant_score_scorer::TpiState<xy_doc_values_point_in_geometry_query::XYDocValuesPointInGeometryTPI<ST::SortedNumeric, Arc<XYGeometryType<<XYGeometryEnum as Geometry>::Component2D>>>>>,
XYShapeTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopTpiState<xy_doc_values_point_in_geometry_query::XYDocValuesPointInGeometryTPI<ST::SortedNumeric, Arc<XYGeometryType<<XYGeometryEnum as Geometry>::Component2D>>>>>,
NumericRange: ConstantScoreScorer<crate::core::search::constant_score_scorer::TpiState<NumericRangeTwoPhase<ST>>>,
NumericRangeTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopTpiState<NumericRangeTwoPhase<ST>>>,
NumericRangeWithSkip: ConstantScoreScorer<crate::core::search::constant_score_scorer::TpiState<DocValuesRangeIterator<NumericRangeTwoPhase<ST>, ST::Skipper>>>,
NumericRangeWithSkipTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopTpiState<DocValuesRangeIterator<NumericRangeTwoPhase<ST>, ST::Skipper>>>,
NumericSet: ConstantScoreScorer<crate::core::search::constant_score_scorer::TpiState<NumericSetTwoPhase<ST>>>,
NumericSetTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopTpiState<NumericSetTwoPhase<ST>>>,
SortedRange: ConstantScoreScorer<crate::core::search::constant_score_scorer::TpiState<SortedRangeTwoPhase<ST>>>,
SortedRangeTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopTpiState<SortedRangeTwoPhase<ST>>>,
SortedRangeWithSkip: ConstantScoreScorer<crate::core::search::constant_score_scorer::TpiState<DocValuesRangeIterator<SortedRangeTwoPhase<ST>, ST::Skipper>>>,
SortedRangeWithSkipTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopTpiState<DocValuesRangeIterator<SortedRangeTwoPhase<ST>, ST::Skipper>>>,
SortedTerms: ConstantScoreScorer<crate::core::search::constant_score_scorer::TpiState<SortedTermSetTwoPhase<ST>>>,
SortedTermsTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopTpiState<SortedTermSetTwoPhase<ST>>>,
SortedTermsWithSkip: ConstantScoreScorer<crate::core::search::constant_score_scorer::TpiState<DocValuesRangeIterator<SortedTermSetTwoPhase<ST>, ST::Skipper>>>,
SortedTermsWithSkipTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopTpiState<DocValuesRangeIterator<SortedTermSetTwoPhase<ST>, ST::Skipper>>>,
DistanceFeature: lat_lon_point_distance_feature_query::DistanceScorer<ST::PointValues, DistanceValues<ST>>,
VectorMatches: abstract_knn_vector_query::ScorerImpl,
FilteredVectors: abstract_vector_similarity_query::ScorerImpl<abstract_vector_similarity_query::FilteredDocIdSetIteratorImpl1<crate::core::search::vector_scorer::VectorScorerEnum2<ST::ByteScorer, ST::FloatScorer>, crate::core::util::bit_set::SparseFixedBitSetBitSet>>,
VectorScores: abstract_vector_similarity_query::ScorerImpl<abstract_vector_similarity_query::DocsIteratorImpl>,
TermAutomaton: TermAutomatonScorer<ST::Posting, SimilaritySimScorer<ST::Similarity>, ST::Norm>,
TermPostings: TermScorer<PostingsTermState<ST::Posting, Arc<TermQuerySimScorer<ST::Similarity>>>, ST::Norm>,
TermImpacts: TermScorer<ImpactsTermState<ST::Impacts, Arc<TermQuerySimScorer<ST::Similarity>>>, ST::Norm>,
TermCompetitive: TermScorer<crate::core::search::impacts_disi::SourceImpactsDISI<ST::Impacts, Arc<TermQuerySimScorer<ST::Similarity>>>, ST::Norm>,
BuiltSet: ConstantScoreScorer<crate::core::search::constant_score_scorer::DisiState<OwnedDocIdSetBuilderIterator>>,
BuiltSetTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopDisiState<OwnedDocIdSetBuilderIterator>>,
BitSet: ConstantScoreScorer<crate::core::search::constant_score_scorer::DisiState<BitSetIterator<FixedBitSet>>>,
BitSetTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopDisiState<BitSetIterator<FixedBitSet>>>,
ConstantIterator: ConstantScoreScorer<crate::core::search::constant_score_scorer::DisiState<BuiltinQueryScorer<ST>>>,
ConstantIteratorTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopDisiState<BuiltinQueryScorer<ST>>>,
ConstantTwoPhase: ConstantScoreScorer<crate::core::search::constant_score_scorer::TpiState<BuiltinQueryScorer<ST>>>,
ConstantTwoPhaseTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopTpiState<BuiltinQueryScorer<ST>>>,
Conjunction: ConjunctionScorer<crate::core::search::conjunction_disi::ConjunctionDISI<crate::core::search::conjunction_disi::ScorerDisi<BuiltinQueryScorer<ST>>>>,
BitSetConjunction: ConjunctionScorer<crate::core::search::conjunction_disi::BitSetConjunctionDISI<crate::core::search::conjunction_disi::ScorerDisi<BuiltinQueryScorer<ST>>>>,
ConjunctionTwoPhase: ConjunctionScorer<TwoPhaseIteratorAsDocIdSetIterator<crate::core::search::conjunction_disi::ConjunctionTwoPhaseIterator<crate::core::search::conjunction_disi::ConjunctionDISI<crate::core::search::conjunction_disi::ScorerDisi<BuiltinQueryScorer<ST>>>>>>,
BitSetConjunctionTwoPhase: ConjunctionScorer<TwoPhaseIteratorAsDocIdSetIterator<crate::core::search::conjunction_disi::ConjunctionTwoPhaseIterator<crate::core::search::conjunction_disi::BitSetConjunctionDISI<crate::core::search::conjunction_disi::ScorerDisi<BuiltinQueryScorer<ST>>>>>>,
BlockMaxConjunction: BlockMaxConjunctionScorer<crate::core::search::block_max_conjunction_scorer::DocIdSetIteratorImpl<BuiltinQueryScorer<ST>>>,
BlockMaxConjunctionTwoPhase: BlockMaxConjunctionScorer<TwoPhaseIteratorAsDocIdSetIterator<crate::core::search::block_max_conjunction_scorer::TwoPhaseIteratorImpl<BuiltinQueryScorer<ST>>>>,
DisjunctionSum: DisjunctionScorer<DisjunctionDISIApproximation<BuiltinQueryScorer<ST>>, DisjunctionSumScorer>,
DisjunctionSumTwoPhase: DisjunctionScorer<crate::core::search::two_phase_iterator::TwoPhaseIteratorAsDocIdSetIterator<crate::core::search::disjunction_scorer::TwoPhase<BuiltinQueryScorer<ST>>>, DisjunctionSumScorer>,
DisjunctionMax: DisjunctionScorer<DisjunctionDISIApproximation<BuiltinQueryScorer<ST>>, DisjunctionMaxScorer>,
DisjunctionMaxTwoPhase: DisjunctionScorer<crate::core::search::two_phase_iterator::TwoPhaseIteratorAsDocIdSetIterator<crate::core::search::disjunction_scorer::TwoPhase<BuiltinQueryScorer<ST>>>, DisjunctionMaxScorer>,
WandTopScores: WANDScorer<BuiltinQueryScorer<ST>, true>,
WandExhaustive: WANDScorer<BuiltinQueryScorer<ST>, false>,
RequiredOptional: ReqOptSumScorer<crate::core::search::req_opt_sum_scorer::DocIdSetIteratorImpl<BuiltinQueryScorer<ST>, BuiltinQueryScorer<ST>>>,
RequiredOptionalTwoPhase: ReqOptSumScorer<TwoPhaseIteratorAsDocIdSetIterator<crate::core::search::req_opt_sum_scorer::TwoPhaseIteratorImpl<BuiltinQueryScorer<ST>, BuiltinQueryScorer<ST>>>>,
RequiredExcludedFirst: ReqExclScorer<crate::core::search::req_excl_scorer::TwoPhaseIteratorImpl1<BuiltinQueryScorer<ST>, BuiltinQueryScorer<ST>>>,
RequiredExcludedLast: ReqExclScorer<crate::core::search::req_excl_scorer::TwoPhaseIteratorImpl2<BuiltinQueryScorer<ST>, BuiltinQueryScorer<ST>>>,
Filter: FilterScorerImpl<BuiltinQueryScorer<ST>>,
}
inline {
MatchAll: ConstantScoreScorer<crate::core::search::constant_score_scorer::DisiState<AllDISI>>,
MatchAllTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopDisiState<AllDISI>>,
Empty: ConstantScoreScorer<crate::core::search::constant_score_scorer::DisiState<EmptyDISI>>,
EmptyTop: ConstantScoreScorer<crate::core::search::constant_score_scorer::TopDisiState<EmptyDISI>>,
}
}
impl<ST: ScorerTypes> BuiltinQueryScorer<ST> {
pub fn new<S: IntoQueryScorer<ST>>(scorer: S) -> Self {
scorer.into_query_scorer()
}
}
#[cfg(test)]
impl<ST: ScorerTypes> IntoQueryScorer<ST>
for Box<dyn crate::test_framework::core::search::test_scorer::TestScorer>
{
fn into_query_scorer(self) -> BuiltinQueryScorer<ST> {
BuiltinQueryScorer {
inner: Box::new(self),
}
}
}
impl<ST: ScorerTypes> IntoQueryScorer<ST> for BuiltinQueryScorer<ST> {
fn into_query_scorer(self) -> BuiltinQueryScorer<ST> {
self
}
}
impl<ST: ScorerTypes, S: IntoQueryScorer<ST>> IntoQueryScorer<ST> for Box<S> {
fn into_query_scorer(self) -> BuiltinQueryScorer<ST> {
S::into_query_scorer_from_box(self)
}
fn into_query_scorer_from_box(self: Box<Self>) -> BuiltinQueryScorer<ST> {
(*self).into_query_scorer()
}
}
macro_rules! convert_scorer_enum {
($name:ident, $( $variant:ident: $ty:ident ),+) => {
impl<ST: ScorerTypes, $( $ty: Scorer + IntoQueryScorer<ST> ),+> IntoQueryScorer<ST> for $name<$( $ty ),+> {
fn into_query_scorer(self) -> BuiltinQueryScorer<ST> {
match self { $( Self::$variant(scorer) => scorer.into_query_scorer(), )+ }
}
}
};
}
convert_scorer_enum!(ScorerEnum2, A: S1, B: S2);
convert_scorer_enum!(ScorerEnum3, A: S1, B: S2, C: S3);
convert_scorer_enum!(ScorerEnum4, A: S1, B: S2, C: S3, D: S4);
impl<ST: ScorerTypes> DocIdSetIteratorExtensions for BuiltinQueryScorer<ST> {
fn get_fixed_bit_set(&self) -> Option<&FixedBitSet> {
self.inner.get_fixed_bit_set()
}
fn get_sparse_fixed_bit_set(
&self,
) -> Option<&crate::core::util::sparse_fixed_bit_set::SparseFixedBitSet> {
self.inner.get_sparse_fixed_bit_set()
}
fn get_doc_base_fixed_bit_set(&self) -> Option<(usize, &FixedBitSet)> {
self.inner.get_doc_base_fixed_bit_set()
}
}
impl<ST: ScorerTypes> BitSetIteratorAccess for BuiltinQueryScorer<ST> {
fn is_bit_iter(&self) -> bool {
self.inner.is_bit_iter()
}
fn get(&self, index: usize) -> Result<bool> {
self.inner.get(index)
}
fn set_doc_id(&mut self, doc: i32) -> Result<()> {
self.inner.set_doc_id(doc)
}
fn bit_set_length(&self) -> Result<usize> {
self.inner.bit_set_length()
}
}
impl<ST: ScorerTypes> DocIdSetIterator for BuiltinQueryScorer<ST> {
fn doc_id(&self) -> i32 {
self.inner.doc_id()
}
fn next_doc(&mut self) -> Result<i32> {
self.inner.next_doc()
}
fn advance(&mut self, target: i32) -> Result<i32> {
self.inner.advance(target)
}
fn slow_advance(&mut self, target: i32) -> Result<i32> {
self.inner.slow_advance(target)
}
fn cost(&self) -> Result<i64> {
DocIdSetIterator::cost(&self.inner)
}
}
impl<ST: ScorerTypes> Scorable for BuiltinQueryScorer<ST> {
type Child<'a>
= QueryChildScorable<'a, ST>
where
Self: 'a;
fn score(&mut self) -> Result<f32> {
self.inner.score()
}
fn smoothing_score(&mut self, doc: i32) -> Result<f32> {
self.inner.smoothing_score(doc)
}
fn set_min_competitive_score(&mut self, min: f32) -> Result<()> {
self.inner.set_min_competitive_score(min)
}
fn cost(&self) -> Result<i64> {
self.inner.scorable_cost()
}
fn get_children(&mut self) -> Result<Vec<ChildScorable<Self::Child<'_>>>> {
self.inner.get_children()
}
#[cfg(test)]
fn as_any(&mut self) -> &mut dyn std::any::Any {
self
}
}
impl<ST: ScorerTypes> crate::core::search::scorable::FixedScore for BuiltinQueryScorer<ST> {}
impl<ST: ScorerTypes> ApproximationDISI for BuiltinQueryScorer<ST> {
fn approx_doc_id(&self) -> i32 {
self.inner.approximation_doc_id()
}
fn approx_next_doc(&mut self) -> Result<i32> {
self.inner.approximation_next_doc()
}
fn approx_advance(&mut self, target: i32) -> Result<i32> {
self.inner.approximation_advance(target)
}
fn approx_slow_advance(&mut self, target: i32) -> Result<i32> {
self.inner.approximation_slow_advance(target)
}
fn approx_cost(&self) -> Result<i64> {
self.inner.approximation_cost()
}
}
impl<ST: ScorerTypes> ApproximationBitSetAccess for BuiltinQueryScorer<ST> {
fn approx_is_bit_iter(&self) -> bool {
self.inner.approximation_is_bit_iter()
}
fn approx_get(&self, index: usize) -> Result<bool> {
self.inner.approximation_get(index)
}
fn approx_set_doc_id(&mut self, doc: i32) -> Result<()> {
self.inner.approximation_set_doc_id(doc)
}
fn approx_bit_set_length(&self) -> Result<usize> {
self.inner.approximation_bit_set_length()
}
}
impl<ST: ScorerTypes> TwoPhaseIterator for BuiltinQueryScorer<ST> {
fn matches(&mut self) -> Result<bool> {
self.inner.matches()
}
fn match_cost(&self) -> f32 {
self.inner.match_cost()
}
}
impl<ST: ScorerTypes> Scorer for BuiltinQueryScorer<ST> {
fn scoring_doc_id(&mut self) -> Result<i32> {
self.inner.scoring_doc_id()
}
fn has_two_phase_iterator(&self) -> TwoPhaseState {
self.inner.has_two_phase_iterator()
}
fn advance_shallow(&mut self, target: i32) -> Result<i32> {
self.inner.advance_shallow(target)
}
fn default_advance_shallow(&mut self, target: i32) -> Result<i32> {
self.inner.default_advance_shallow(target)
}
fn get_max_score(&mut self, upto: i32) -> Result<f32> {
self.inner.get_max_score(upto)
}
fn default_cost(&mut self) -> Result<i64> {
self.inner.default_cost()
}
#[cfg(test)]
fn kind(&self) -> crate::core::search::scorer::ScorerKind {
self.inner.kind()
}
}
pub type QueryScorer<
LR,
SIM = crate::core::search::similarities_impl::bm25_similarity::BM25Similarity,
> = BuiltinQueryScorer<LeafScorerTypes<LR, SIM>>;
#[cfg(test)]
impl<ST: ScorerTypes> BuiltinQueryScorer<ST> {
pub(crate) fn for_test<S: Scorer + 'static>(scorer: S) -> Self {
let scorer: Box<dyn crate::test_framework::core::search::test_scorer::TestScorer> =
Box::new(scorer);
scorer.into_query_scorer()
}
}
pub enum QueryChildScorable<'a, ST: ScorerTypes> {
Scorer(&'a mut BuiltinQueryScorer<ST>),
Empty(crate::core::search::dummy::dummy_scorable::DummyScorable),
#[cfg(test)]
Fixture(Box<dyn crate::test_framework::core::search::test_scorer::TestScorable + 'a>),
}
impl<'a, ST: ScorerTypes> Scorable for QueryChildScorable<'a, ST> {
type Child<'b>
= QueryChildScorable<'b, ST>
where
Self: 'b;
fn score(&mut self) -> Result<f32> {
match self {
Self::Scorer(s) => s.score(),
Self::Empty(s) => s.score(),
#[cfg(test)]
Self::Fixture(s) => s.score(),
}
}
fn smoothing_score(&mut self, doc: i32) -> Result<f32> {
match self {
Self::Scorer(s) => s.smoothing_score(doc),
Self::Empty(s) => s.smoothing_score(doc),
#[cfg(test)]
Self::Fixture(s) => s.smoothing_score(doc),
}
}
fn set_min_competitive_score(&mut self, score: f32) -> Result<()> {
match self {
Self::Scorer(s) => s.set_min_competitive_score(score),
Self::Empty(s) => s.set_min_competitive_score(score),
#[cfg(test)]
Self::Fixture(s) => s.set_min_competitive_score(score),
}
}
fn cost(&self) -> Result<i64> {
match self {
Self::Scorer(s) => Scorable::cost(s),
Self::Empty(s) => Scorable::cost(s),
#[cfg(test)]
Self::Fixture(s) => Scorable::cost(s),
}
}
fn get_children(&mut self) -> Result<Vec<ChildScorable<Self::Child<'_>>>> {
match self {
Self::Scorer(s) => s.get_children(),
Self::Empty(_) => Ok(vec![]),
#[cfg(test)]
Self::Fixture(s) => s.get_children().map(|children| {
children
.into_iter()
.map(|child| ChildScorable {
child: QueryChildScorable::Fixture(child.child),
relationship: child.relationship,
})
.collect()
}),
}
}
#[cfg(test)]
fn as_any(&mut self) -> &mut dyn std::any::Any {
match self {
Self::Scorer(s) => s.as_any(),
Self::Empty(s) => s.as_any(),
Self::Fixture(s) => s.as_any(),
}
}
}
impl<ST: ScorerTypes> crate::core::search::scorable::FixedScore for QueryChildScorable<'_, ST> {
fn set_score(&mut self, score: f32) -> Result<()> {
match self {
Self::Scorer(s) => s.set_score(score),
Self::Empty(s) => s.set_score(score),
#[cfg(test)]
Self::Fixture(s) => s.set_score(score),
}
}
}
trait IntoQueryChild<'a, ST: ScorerTypes> {
fn into_query_child(self) -> QueryChildScorable<'a, ST>;
}
impl<'a, ST: ScorerTypes> IntoQueryChild<'a, ST> for &'a mut BuiltinQueryScorer<ST> {
fn into_query_child(self) -> QueryChildScorable<'a, ST> {
QueryChildScorable::Scorer(self)
}
}
impl<'a, ST: ScorerTypes> IntoQueryChild<'a, ST>
for crate::core::search::dummy::dummy_scorable::DummyScorable
{
fn into_query_child(self) -> QueryChildScorable<'a, ST> {
QueryChildScorable::Empty(self)
}
}
impl<'a, ST: ScorerTypes> IntoQueryChild<'a, ST> for QueryChildScorable<'a, ST> {
fn into_query_child(self) -> QueryChildScorable<'a, ST> {
self
}
}
#[cfg(test)]
impl<'a, ST: ScorerTypes> IntoQueryChild<'a, ST>
for Box<dyn crate::test_framework::core::search::test_scorer::TestScorable + 'a>
{
fn into_query_child(self) -> QueryChildScorable<'a, ST> {
QueryChildScorable::Fixture(self)
}
}
macro_rules! either_child {
($name:ident { $( $v:ident:$t:ident ),+ }) => {
impl<'a, ST: ScorerTypes, $( $t: IntoQueryChild<'a, ST> ),+> IntoQueryChild<'a, ST> for crate::core::search::scorable::$name<$( $t ),+> {
fn into_query_child(self) -> QueryChildScorable<'a, ST> { match self { $( Self::$v(child) => child.into_query_child(), )+ } }
}
};
}
either_child!(ScorableEnum2 { A: A, B: B });
either_child!(ScorableEnum3 { A: A, B: B, C: C });
either_child!(ScorableEnum4 {
A: A,
B: B,
C: C,
D: D
});