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
/*
* 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 std::sync::Arc;
use crate::core::search::sort::Sort;
use crate::core::util::error::lucene_error::{LuceneError, Result};
use crate::core::util::version::{LATEST, Version};
#[derive(Clone)]
#[cfg_attr(test, derive(Default))] // for test
pub struct LeafMetaData {
/// The major version of the Lucene format used to create this segment.
pub created_version_major: i32,
/// The minimum version of Lucene that contributed to this segment.
pub min_version: Option<Version>,
/// The sort order of documents in this segment, if any.
pub sort: Option<Arc<Sort>>,
/// Indicates whether this segment contains documents written as blocks.
pub has_blocks: bool,
}
impl LeafMetaData {
/// Constructs a new [`LeafMetaData`] instance.
pub fn new(
created_version_major: i32,
min_version: Option<Version>,
sort: Option<Arc<Sort>>,
has_blocks: bool,
) -> Result<Self> {
if created_version_major > LATEST.major {
return Err(LuceneError::illegal_argument(format!(
"created_version_major is in the future: {created_version_major}"
)));
}
if created_version_major < 6 {
return Err(LuceneError::illegal_argument(format!(
"created_version_major must be >= 6, got: {created_version_major}"
)));
}
if created_version_major >= 7 && min_version.is_none() {
return Err(LuceneError::illegal_argument(
"min_version must be set when created_version_major is >= 7".to_string(),
));
}
Ok(Self {
created_version_major,
min_version,
sort,
has_blocks,
})
}
pub fn get_created_version_major(&self) -> i32 {
self.created_version_major
}
pub fn get_min_version(&self) -> &Option<Version> {
&self.min_version
}
pub fn get_sort(&self) -> &Option<Arc<Sort>> {
&self.sort
}
pub fn get_has_blocks(&self) -> bool {
self.has_blocks
}
}