use crate::core::index::index_reader_context::IRCLeafReader;
use crate::core::search::query_bulk_scorer::BuiltinQueryBulkScorer;
use crate::core::search::query_scorer::QueryScorer;
use crate::core::search::scorer_types::LeafScorerTypes;
use crate::core::search::similarities_impl::similarities::Similarity;
use crate::core::document::binary_range_field_range_query::BinaryRangeFieldRangeQuery;
use crate::core::document::lat_lon_doc_values_box_query::LatLonDocValuesBoxQuery;
use crate::core::document::lat_lon_doc_values_query::LatLonDocValuesQuery;
use crate::core::document::lat_lon_point_distance_feature_query::LatLonPointDistanceFeatureQuery;
use crate::core::document::lat_lon_point_distance_query::LatLonPointDistanceQuery;
use crate::core::document::range_field_query::RangeFieldQuery;
use crate::core::document::sorted_numeric_doc_values_range_query::SortedNumericDocValuesRangeQuery;
use crate::core::document::sorted_numeric_doc_values_set_query::SortedNumericDocValuesSetQuery;
use crate::core::document::sorted_set_doc_values_range_query::SortedSetDocValuesRangeQuery;
use crate::core::document::xy_doc_values_point_in_geometry_query::XYDocValuesPointInGeometryQuery;
use crate::core::document::xy_point_in_geometry_query::XYPointInGeometryQuery;
use crate::core::index::index_reader::Identity;
use crate::core::index::index_reader_context::IndexReaderContext;
use crate::core::search::boolean_query::BooleanQuery;
use crate::core::search::boost_query::BoostQuery;
use crate::core::search::constant_score_query::ConstantScoreQuery;
use crate::core::search::doc_values_rewrite_method::MultiTermQueryDocValuesWrapper;
use crate::core::search::dummy::dummy_query::DummyQuery;
use crate::core::search::field_exists_query::FieldExistsQuery;
use crate::core::search::float_vector_similarity_query::FloatVectorSimilarityQuery;
use crate::core::search::index_searcher::IndexSearcher;
use crate::core::document::lat_lon_point_query::LatLonPointQuery;
use crate::core::search::abstract_knn_vector_query::DocAndScoreQuery;
use crate::core::search::automaton_query::AutomatonQuery;
use crate::core::search::blended_term_query::BlendedTermQuery;
use crate::core::search::byte_vector_similarity_query::ByteVectorSimilarityQuery;
use crate::core::search::disjunction_max_query::DisjunctionMaxQuery;
use crate::core::search::fuzzy_query::FuzzyQuery;
use crate::core::search::index_or_doc_values_query::IndexOrDocValuesQuery;
use crate::core::search::index_sort_sorted_numeric_doc_values_range_query::IndexSortSortedNumericDocValuesRangeQuery;
use crate::core::search::knn_byte_vector_query::KnnByteVectorQuery;
use crate::core::search::knn_float_vector_query::KnnFloatVectorQuery;
use crate::core::search::match_all_docs_query::MatchAllDocsQuery;
use crate::core::search::match_no_docs_query::MatchNoDocsQuery;
use crate::core::search::multi_phrase_query::MultiPhraseQuery;
use crate::core::search::multi_term_query::MultiTermQuerySet;
use crate::core::search::multi_term_query_constant_score_blended_wrapper::MultiTermQueryConstantScoreBlendedWrapper;
use crate::core::search::multi_term_query_constant_score_wrapper::MultiTermQueryConstantScoreWrapper;
use crate::core::search::n_gram_phrase_query::NGramPhraseQuery;
use crate::core::search::named_matches::NamedQuery;
use crate::core::search::phrase_query::PhraseQuery;
use crate::core::search::point_in_set_query::PointInSetQuery;
use crate::core::search::point_range_query::PointRangeQuery;
use crate::core::search::prefix_query::PrefixQuery;
use crate::core::search::query_visitor::QueryVisitor;
use crate::core::search::regexp_query::RegexpQuery;
use crate::core::search::score_mode::ScoreMode;
use crate::core::search::synonym_query::SynonymQuery;
use crate::core::search::term_in_set_query::TermInSetQuery;
use crate::core::search::term_query::TermQuery;
use crate::core::search::term_range_query::TermRangeQuery;
use crate::core::search::wildcard_query::WildcardQuery;
use crate::core::util::accountable::Accountable;
use crate::core::util::core_helper::HasIdentity;
use crate::core::util::error::lucene_error::{LuceneError, Result};
use crate::sandbox::search::term_automaton_query::TermAutomatonQuery;
#[cfg(test)]
use crate::test_framework::core::search::asserting_query::AssertingQuery;
#[cfg(test)]
use crate::test_framework::core::search::base_vector_similarity_query_test_case::CountingQuery;
#[cfg(test)]
use crate::test_framework::core::search::block_score_query_wrapper::BlockScoreQueryWrapper;
#[cfg(test)]
use crate::test_framework::core::search::multi_term::{
BoostCheckingQuery, DumbPrefixQuery, DumbRegexpQuery,
};
#[cfg(test)]
use crate::test_framework::core::search::query::AssertNeedsScores;
#[cfg(test)]
use crate::test_framework::core::search::query::BitSetQuery;
#[cfg(test)]
use crate::test_framework::core::search::query::BrokenExplainTermQuery;
#[cfg(test)]
use crate::test_framework::core::search::query::CrazyMustUseBulkScorerQuery;
#[cfg(test)]
use crate::test_framework::core::search::query::DummyQuery1;
#[cfg(test)]
use crate::test_framework::core::search::query::RandomQuery;
#[cfg(test)]
use crate::test_framework::core::search::query::TestRewriteQuery;
#[cfg(test)]
use crate::test_framework::core::search::query::{DVCacheQuery, TestLRUQuery};
#[cfg(test)]
use crate::test_framework::core::search::query::{MaxScoreWrapperQuery, WANDScorerQuery};
#[cfg(test)]
use crate::test_framework::core::search::random_approximation_query::RandomApproximationQuery;
use std::cmp::PartialEq;
use std::fmt::Debug;
use std::hash::{Hash, Hasher};
use std::sync::Arc;
pub type QueryWeight<
IRC,
SIM = crate::core::search::similarities_impl::bm25_similarity::BM25Similarity,
> = crate::core::search::query_weight::BuiltinQueryWeight<IRC, SIM>;
pub use crate::core::search::query_matches::{QueryWeightMatches, QueryWeightMatchesIterator};
pub type QueryWeightSs<
IRC,
SIM = crate::core::search::similarities_impl::bm25_similarity::BM25Similarity,
> = crate::core::search::query_scorer_supplier::BuiltinQueryScorerSupplier<IRC, SIM>;
pub type QueryWeightSsBulkScorer<
IRC,
SIM = crate::core::search::similarities_impl::bm25_similarity::BM25Similarity,
> = BuiltinQueryBulkScorer<LeafScorerTypes<IRCLeafReader<IRC>, SIM>>;
pub type QueryWeightSsScorer<
IRC,
SIM = crate::core::search::similarities_impl::bm25_similarity::BM25Similarity,
> = QueryScorer<IRCLeafReader<IRC>, SIM>;
macro_rules! impl_into_box_query {
($($ty:ty),* $(,)?) => {
$(
impl IntoBoxQuery for $ty {
fn into_box_query(self) -> Box<Query> {
Box::new(self.into())
}
}
)*
};
}
impl_into_box_query!(
BinaryRangeFieldRangeQuery,
BlendedTermQuery,
BooleanQuery,
BoostQuery,
ByteVectorSimilarityQuery,
ConstantScoreQuery,
DisjunctionMaxQuery,
DocAndScoreQuery,
DummyQuery,
FieldExistsQuery,
FloatVectorSimilarityQuery,
IndexOrDocValuesQuery,
IndexSortSortedNumericDocValuesRangeQuery,
KnnByteVectorQuery,
KnnFloatVectorQuery,
LatLonDocValuesBoxQuery,
LatLonDocValuesQuery,
LatLonPointDistanceFeatureQuery,
LatLonPointDistanceQuery,
LatLonPointQuery,
MatchAllDocsQuery,
MatchNoDocsQuery,
MultiTermQueryDocValuesWrapper,
MultiTermQueryConstantScoreBlendedWrapper,
MultiTermQueryConstantScoreWrapper,
NGramPhraseQuery,
PhraseQuery,
PointInSetQuery,
PointRangeQuery,
RangeFieldQuery,
SortedNumericDocValuesRangeQuery,
SortedNumericDocValuesSetQuery,
SortedSetDocValuesRangeQuery,
SynonymQuery,
TermQuery,
TermAutomatonQuery,
XYDocValuesPointInGeometryQuery,
XYPointInGeometryQuery,
);
pub trait QueryBase: Debug + HasIdentity + Accountable {
type Weight<IRC, SIM>: crate::core::search::weight::Weight<IRC, SIM>
where
SIM: Similarity,
IRC: IndexReaderContext + 'static;
fn to_string(&self, field: &str) -> Result<String>;
fn create_weight<IRC, SIM>(
self,
_searcher: &IndexSearcher<IRC, SIM>,
_score_mode: &ScoreMode,
_boost: f32,
) -> Result<Self::Weight<IRC, SIM>>
where
SIM: Similarity,
IRC: IndexReaderContext + 'static,
IndexSearcher<IRC, SIM>: Sync,
Self: Sized;
fn rewrite<IRC, SIM>(&self, _searcher: &IndexSearcher<IRC, SIM>) -> Result<Option<Query>>
where
SIM: Similarity,
IRC: IndexReaderContext + 'static,
IndexSearcher<IRC, SIM>: Sync,
Self: Sized,
{
Ok(None)
}
fn visit<QV>(&self, visitor: &mut QV) -> Result<()>
where
QV: QueryVisitor;
}
macro_rules! define_queries {
($d:tt; owned { $( $(#[$attrs:meta])* $variant:ident => $query:ty, )* }
multi_term { $( $(#[$multi_attrs:meta])* $multi:ident => $multi_query:ty, )* }) => {
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Query {
$( $(#[$attrs])* $variant($query), )*
}
#[derive(Clone, Copy, Debug)]
pub enum QueryRef<'a> {
$( $(#[$attrs])* $variant(&'a $query), )*
$( $(#[$multi_attrs])* $multi(&'a $multi_query), )*
}
$( $(#[$attrs])* impl From<$query> for Query {
fn from(query: $query) -> Self { Self::$variant(query) }
}
$(#[$attrs])* impl<'a> From<&'a $query> for QueryRef<'a> {
fn from(query: &'a $query) -> Self { Self::$variant(query) }
} )*
$( $(#[$multi_attrs])* impl<'a> From<&'a $multi_query> for QueryRef<'a> {
fn from(query: &'a $multi_query) -> Self { Self::$multi(query) }
} )*
impl<'a> From<&'a Query> for QueryRef<'a> {
fn from(query: &'a Query) -> Self {
match query { $( $(#[$attrs])* Query::$variant(query) => Self::$variant(query), )* }
}
}
impl From<QueryRef<'_>> for Query {
fn from(query: QueryRef<'_>) -> Self {
match query {
$( $(#[$attrs])* QueryRef::$variant(query) => Self::$variant(query.clone()), )*
$( $(#[$multi_attrs])* QueryRef::$multi(query) => Self::MultiTermQuery(query.clone().into()), )*
}
}
}
impl QueryRef<'_> {
pub fn to_string(self, field: &str) -> Result<String> {
match self {
$( $(#[$attrs])* Self::$variant(query) => QueryBase::to_string(query, field), )*
$( $(#[$multi_attrs])* Self::$multi(query) => QueryBase::to_string(query, field), )*
}
}
}
impl Query {
pub fn name(&self) -> &'static str {
match self { $( $(#[$attrs])* Self::$variant(_) => stringify!($variant), )* }
}
}
macro_rules! dispatch_query {
($d value:expr, |$d inner:ident| $d body:expr) => {
match $d value { $( $(#[$attrs])* Query::$variant($d inner) => $d body, )* }
};
}
};
}
define_queries! {
$; owned {
BinaryRangeFieldRange => BinaryRangeFieldRangeQuery,
BlendedTerm => BlendedTermQuery,
Boolean => BooleanQuery,
Boost => BoostQuery,
ByteVectorSimilarity => ByteVectorSimilarityQuery,
ConstantScore => ConstantScoreQuery,
DisjunctionMax => DisjunctionMaxQuery,
DocAndScore => DocAndScoreQuery,
Dummy => DummyQuery,
FieldExists => FieldExistsQuery,
FloatVectorSimilarity => FloatVectorSimilarityQuery,
IndexOrDocValues => IndexOrDocValuesQuery,
IndexSortSortedNumericDocValuesRange => IndexSortSortedNumericDocValuesRangeQuery,
KnnByteVector => KnnByteVectorQuery,
KnnFloatVector => KnnFloatVectorQuery,
LatLonDocValues => LatLonDocValuesQuery,
LatLonDocValuesBox => LatLonDocValuesBoxQuery,
LatLonPoint => LatLonPointQuery,
LatLonPointDistance => LatLonPointDistanceQuery,
LatLonPointDistanceFeature => LatLonPointDistanceFeatureQuery,
MatchAllDocs => MatchAllDocsQuery,
MatchNoDocs => MatchNoDocsQuery,
Named => NamedQuery,
MultiPhrase => MultiPhraseQuery,
MultiTermQuery => MultiTermQuerySet,
MultiTermQueryDocValuesWrapper => MultiTermQueryDocValuesWrapper,
MultiTermQueryConstantScoreBlendedWrapper => MultiTermQueryConstantScoreBlendedWrapper,
MultiTermQueryConstantScoreWrapper => MultiTermQueryConstantScoreWrapper,
NGramPhrase => NGramPhraseQuery,
Phrase => PhraseQuery,
PointInSet => PointInSetQuery,
PointRange => PointRangeQuery,
RangeField => RangeFieldQuery,
SortedNumericDocValuesRange => SortedNumericDocValuesRangeQuery,
SortedNumericDocValuesSet => SortedNumericDocValuesSetQuery,
SortedSetDocValuesRange => SortedSetDocValuesRangeQuery,
Synonym => SynonymQuery,
Term => TermQuery,
TermAutomaton => TermAutomatonQuery,
XYDocValuesPointInGeometry => XYDocValuesPointInGeometryQuery,
XYPointInGeometry => XYPointInGeometryQuery,
#[cfg(test)]
Asserting => AssertingQuery,
#[cfg(test)]
AssertNeedsScores => AssertNeedsScores,
#[cfg(test)]
BitSet => BitSetQuery,
#[cfg(test)]
BlockScoreQueryWrapper => BlockScoreQueryWrapper,
#[cfg(test)]
BrokenExplainTerm => BrokenExplainTermQuery,
#[cfg(test)]
Counting => CountingQuery,
#[cfg(test)]
CrazyMustUseBulkScorer => CrazyMustUseBulkScorerQuery,
#[cfg(test)]
Dummy1 => DummyQuery1,
#[cfg(test)]
TestLRU => TestLRUQuery,
#[cfg(test)]
DVCache => DVCacheQuery,
#[cfg(test)]
MaxScoreWrapper => MaxScoreWrapperQuery,
#[cfg(test)]
Random => RandomQuery,
#[cfg(test)]
RandomApproximation => RandomApproximationQuery,
#[cfg(test)]
TestRewrite => TestRewriteQuery,
#[cfg(test)]
WANDScorer => WANDScorerQuery,
}
multi_term {
Automaton => AutomatonQuery,
Fuzzy => FuzzyQuery,
Prefix => PrefixQuery,
Regexp => RegexpQuery,
TermInSet => TermInSetQuery,
TermRange => TermRangeQuery,
Wildcard => WildcardQuery,
#[cfg(test)]
BoostChecking => BoostCheckingQuery,
#[cfg(test)]
DumbPrefix => DumbPrefixQuery,
#[cfg(test)]
DumbRegexp => DumbRegexpQuery,
}
}
impl Default for Query {
fn default() -> Self {
Query::Dummy(DummyQuery::default())
}
}
impl Accountable for Query {
fn ram_bytes_used(&self) -> Result<i64> {
dispatch_query!(self, |q| q.ram_bytes_used())
}
}
impl HasIdentity for Query {
fn identity(&self) -> &Identity {
dispatch_query!(self, |q| q.identity())
}
}
impl QueryBase for Query {
type Weight<IRC, SIM>
= QueryWeight<IRC, SIM>
where
SIM: Similarity,
IRC: IndexReaderContext + 'static;
fn to_string(&self, field: &str) -> Result<String> {
dispatch_query!(self, |q| q.to_string(field))
}
fn create_weight<IRC, SIM>(
self,
searcher: &IndexSearcher<IRC, SIM>,
score_mode: &ScoreMode,
boost: f32,
) -> Result<Self::Weight<IRC, SIM>>
where
SIM: Similarity,
IRC: IndexReaderContext + 'static,
IndexSearcher<IRC, SIM>: Sync,
Self: Sized,
{
match self {
Self::BinaryRangeFieldRange(q) => {
q.create_weight(searcher, score_mode, boost).map(Into::into)
},
Self::BlendedTerm(q) => q.create_weight(searcher, score_mode, boost),
Self::Boolean(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::Boost(q) => q.create_weight(searcher, score_mode, boost),
Self::ByteVectorSimilarity(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::ConstantScore(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::DisjunctionMax(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::DocAndScore(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::Dummy(q) => q.create_weight(searcher, score_mode, boost),
Self::FieldExists(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::FloatVectorSimilarity(q) => {
q.create_weight(searcher, score_mode, boost).map(Into::into)
},
Self::IndexOrDocValues(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::IndexSortSortedNumericDocValuesRange(q) => {
q.create_weight(searcher, score_mode, boost).map(Into::into)
},
Self::KnnByteVector(q) => q.create_weight(searcher, score_mode, boost),
Self::KnnFloatVector(q) => q.create_weight(searcher, score_mode, boost),
Self::LatLonDocValues(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::LatLonDocValuesBox(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::LatLonPoint(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::LatLonPointDistance(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::LatLonPointDistanceFeature(q) => {
q.create_weight(searcher, score_mode, boost).map(Into::into)
},
Self::MatchAllDocs(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::MatchNoDocs(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::Named(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::MultiPhrase(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::MultiTermQuery(q) => q.create_weight(searcher, score_mode, boost),
Self::MultiTermQueryDocValuesWrapper(q) => {
q.create_weight(searcher, score_mode, boost).map(Into::into)
},
Self::MultiTermQueryConstantScoreBlendedWrapper(q) => {
q.create_weight(searcher, score_mode, boost).map(Into::into)
},
Self::MultiTermQueryConstantScoreWrapper(q) => {
q.create_weight(searcher, score_mode, boost).map(Into::into)
},
Self::NGramPhrase(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::Phrase(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::PointInSet(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::PointRange(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::RangeField(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::SortedNumericDocValuesRange(q) => {
q.create_weight(searcher, score_mode, boost).map(Into::into)
},
Self::SortedNumericDocValuesSet(q) => {
q.create_weight(searcher, score_mode, boost).map(Into::into)
},
Self::SortedSetDocValuesRange(q) => {
q.create_weight(searcher, score_mode, boost).map(Into::into)
},
Self::Synonym(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::Term(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::TermAutomaton(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
Self::XYDocValuesPointInGeometry(q) => {
q.create_weight(searcher, score_mode, boost).map(Into::into)
},
Self::XYPointInGeometry(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
#[cfg(test)]
Self::Asserting(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
#[cfg(test)]
Self::AssertNeedsScores(q) => q
.create_weight(searcher, score_mode, boost)
.map(QueryWeight::<IRC, SIM>::fixture),
#[cfg(test)]
Self::BitSet(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
#[cfg(test)]
Self::BlockScoreQueryWrapper(q) => {
q.create_weight(searcher, score_mode, boost).map(Into::into)
},
#[cfg(test)]
Self::BrokenExplainTerm(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
#[cfg(test)]
Self::Counting(q) => q
.create_weight(searcher, score_mode, boost)
.map(QueryWeight::<IRC, SIM>::fixture),
#[cfg(test)]
Self::CrazyMustUseBulkScorer(q) => {
q.create_weight(searcher, score_mode, boost).map(Into::into)
},
#[cfg(test)]
Self::Dummy1(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
#[cfg(test)]
Self::TestLRU(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
#[cfg(test)]
Self::DVCache(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
#[cfg(test)]
Self::MaxScoreWrapper(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
#[cfg(test)]
Self::Random(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
#[cfg(test)]
Self::RandomApproximation(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
#[cfg(test)]
Self::TestRewrite(q) => q.create_weight(searcher, score_mode, boost),
#[cfg(test)]
Self::WANDScorer(q) => q.create_weight(searcher, score_mode, boost).map(Into::into),
}
}
fn rewrite<IRC, SIM>(&self, searcher: &IndexSearcher<IRC, SIM>) -> Result<Option<Query>>
where
SIM: Similarity,
IRC: IndexReaderContext + 'static,
IndexSearcher<IRC, SIM>: Sync,
{
dispatch_query!(self, |q| q.rewrite(searcher))
}
fn visit<QV>(&self, visitor: &mut QV) -> Result<()>
where
QV: QueryVisitor,
{
dispatch_query!(self, |query| QueryBase::visit(query, visitor))
}
}
#[derive(Clone, Debug)]
pub struct IdentityQuery {
pub(crate) query: Arc<Query>,
}
impl IdentityQuery {
pub fn new(query: Arc<Query>) -> Self {
Self { query }
}
}
impl PartialEq for IdentityQuery {
fn eq(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.query, &other.query)
}
}
impl Eq for IdentityQuery {}
impl Hash for IdentityQuery {
fn hash<H>(&self, state: &mut H)
where
H: Hasher,
{
Arc::as_ptr(&self.query).hash(state);
}
}
impl<Q> QueryBase for Arc<Q>
where
Q: QueryBase,
{
type Weight<IRC, SIM>
= Q::Weight<IRC, SIM>
where
SIM: Similarity,
IRC: IndexReaderContext + 'static;
fn to_string(&self, field: &str) -> Result<String> {
(**self).to_string(field)
}
fn create_weight<IRC, SIM>(
self,
_searcher: &IndexSearcher<IRC, SIM>,
_score_mode: &ScoreMode,
_boost: f32,
) -> Result<Self::Weight<IRC, SIM>>
where
SIM: Similarity,
IRC: IndexReaderContext + 'static,
Self: Sized,
IndexSearcher<IRC, SIM>: Sync,
{
Err(LuceneError::unsupported_operation(format!(
"Arc<QueryBase> cannot be used to create_weight directly: {}",
std::any::type_name::<Q>()
)))
}
fn rewrite<IRC, SIM>(&self, _searcher: &IndexSearcher<IRC, SIM>) -> Result<Option<Query>>
where
SIM: Similarity,
IRC: IndexReaderContext + 'static,
IndexSearcher<IRC, SIM>: Sync,
{
Err(LuceneError::unsupported_operation(format!(
"Arc<QueryBase> cannot be used to rewrite directly: {}",
std::any::type_name::<Q>()
)))
}
fn visit<QV>(&self, visitor: &mut QV) -> Result<()>
where
QV: QueryVisitor,
{
(**self).visit(visitor)
}
}
pub trait IntoBoxQuery {
fn into_box_query(self) -> Box<Query>;
}
pub trait IntoQuery {
fn into_query(self) -> Query;
}
impl<T> IntoQuery for T
where
T: Into<Query>,
{
fn into_query(self) -> Query {
self.into()
}
}
impl IntoBoxQuery for Query {
fn into_box_query(self) -> Box<Query> {
Box::new(self)
}
}
impl<T> IntoBoxQuery for T
where
T: Into<MultiTermQuerySet>,
{
fn into_box_query(self) -> Box<Query> {
Box::new(self.into().into())
}
}
impl IntoBoxQuery for Box<Query> {
fn into_box_query(self) -> Box<Query> {
self
}
}