1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* 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.
*/
use crate::core::index::index_reader::{Identity, IndexReader};
use crate::core::index::leaf_reader::{
LRNormNumericDocValues, LRNumericDocValues, LRSortedNumericDocValues, LRSortedSetDocValues,
LeafReader,
};
use crate::core::index::leaf_reader_context::LeafReaderContext;
use crate::core::util::error::lucene_error::Result;
use std::sync::Arc;
/// Represents a hierarchical relationship between [`IndexReader`] instances.
pub trait IndexReaderContext {
type IndexReader: IndexReader;
/// Returns the [`IndexReader`], this context represents.
fn reader(&self) -> &Self::IndexReader;
type LeafReader: LeafReader;
/// Returns the context's leaves if this context is a top-level context.
///
/// # Error
///
/// Returns [`LuceneErrorKind::UnsupportedOperation`](crate::core::util::error::lucene_error::LuceneErrorKind::UnsupportedOperation) if this is not a top-level context.
fn leaves(&self) -> Result<&[LeafReaderContext<Self::LeafReader>]>;
fn base(&self) -> &IndexReaderContextBase;
}
#[derive(Clone)]
pub struct IndexReaderContextBase {
/// `true` if this context struct represents the top-level reader within the hierarchical context.
pub is_top_level: bool,
/// The doc base for this reader in the parent, `0` if parent is `None`.
pub doc_base_in_parent: usize,
/// The ord for this reader in the parent, `0` if parent is `None`.
pub ord_in_parent: i32,
// An object that uniquely identifies this context without referencing segments.
pub identity: Identity,
}
impl IndexReaderContextBase {
pub fn new(is_top_level: bool, ord_in_parent: i32, doc_base_in_parent: usize) -> Self {
Self {
is_top_level,
doc_base_in_parent,
ord_in_parent,
identity: Identity::new(),
}
}
pub fn id(&self) -> &Identity {
&self.identity
}
}
pub type IRCLeafReader<IRC> = <IRC as IndexReaderContext>::LeafReader;
pub type IRCLeafReaderCacheHelper<IRC> = <IRCLeafReader<IRC> as LeafReader>::CacheHelper;
pub type IRCSSDV<IRC> = LRSortedSetDocValues<IRCLeafReader<IRC>>;
pub type IRCNDV<IRC> = LRNumericDocValues<IRCLeafReader<IRC>>;
pub type IRCNormNDV<IRC> = LRNormNumericDocValues<IRCLeafReader<IRC>>;
pub type IRCSNDV<IRC> = LRSortedNumericDocValues<IRCLeafReader<IRC>>;
impl<IRC> IndexReaderContext for Arc<IRC>
where
IRC: IndexReaderContext,
{
type IndexReader = IRC::IndexReader;
fn reader(&self) -> &Self::IndexReader {
(**self).reader()
}
type LeafReader = IRC::LeafReader;
fn leaves(&self) -> Result<&[LeafReaderContext<Self::LeafReader>]> {
(**self).leaves()
}
fn base(&self) -> &IndexReaderContextBase {
(**self).base()
}
}