mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-06-01 16:10:42 +00:00
Add a payload: &mut (dyn Any + '_) argument to Directory::save_meta() (#17)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use std::any::Any;
|
||||
use std::collections::HashSet;
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -248,7 +249,12 @@ pub trait Directory: DirectoryClone + fmt::Debug + Send + Sync + 'static {
|
||||
}
|
||||
|
||||
/// Allows the directory to save IndexMeta, overriding the SegmentUpdater's default save_meta
|
||||
fn save_metas(&self, _metas: &IndexMeta, _previous_metas: &IndexMeta) -> crate::Result<()> {
|
||||
fn save_metas(
|
||||
&self,
|
||||
_metas: &IndexMeta,
|
||||
_previous_metas: &IndexMeta,
|
||||
_payload: &mut (dyn Any + '_),
|
||||
) -> crate::Result<()> {
|
||||
Err(crate::TantivyError::InternalError(
|
||||
"save_meta not implemented".to_string(),
|
||||
))
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use std::any::Any;
|
||||
use std::collections::HashSet;
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -337,8 +338,13 @@ impl Directory for ManagedDirectory {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn save_metas(&self, metas: &IndexMeta, previous_metas: &IndexMeta) -> crate::Result<()> {
|
||||
self.directory.save_metas(metas, previous_metas)
|
||||
fn save_metas(
|
||||
&self,
|
||||
metas: &IndexMeta,
|
||||
previous_metas: &IndexMeta,
|
||||
payload: &mut (dyn Any + '_),
|
||||
) -> crate::Result<()> {
|
||||
self.directory.save_metas(metas, previous_metas, payload)
|
||||
}
|
||||
|
||||
fn load_metas(&self, inventory: &SegmentMetaInventory) -> crate::Result<IndexMeta> {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::slice;
|
||||
|
||||
/// Enum describing each component of a tantivy segment.
|
||||
@@ -5,7 +6,7 @@ use std::slice;
|
||||
/// Each component is stored in its own file,
|
||||
/// using the pattern `segment_uuid`.`component_extension`,
|
||||
/// except the delete component that takes an `segment_uuid`.`delete_opstamp`.`component_extension`
|
||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub enum SegmentComponent {
|
||||
/// Postings (or inverted list). Sorted lists of document ids, associated with terms
|
||||
Postings,
|
||||
@@ -30,6 +31,39 @@ pub enum SegmentComponent {
|
||||
Delete,
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for SegmentComponent {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
"idx" => Ok(SegmentComponent::Postings),
|
||||
"pos" => Ok(SegmentComponent::Positions),
|
||||
"term" => Ok(SegmentComponent::Terms),
|
||||
"store" => Ok(SegmentComponent::Store),
|
||||
"temp" => Ok(SegmentComponent::TempStore),
|
||||
"fast" => Ok(SegmentComponent::FastFields),
|
||||
"fieldnorm" => Ok(SegmentComponent::FieldNorms),
|
||||
"del" => Ok(SegmentComponent::Delete),
|
||||
other => Err(other.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for SegmentComponent {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
SegmentComponent::Postings => write!(f, "idx"),
|
||||
SegmentComponent::Positions => write!(f, "pos"),
|
||||
SegmentComponent::FastFields => write!(f, "fast"),
|
||||
SegmentComponent::FieldNorms => write!(f, "fieldnorm"),
|
||||
SegmentComponent::Terms => write!(f, "term"),
|
||||
SegmentComponent::Store => write!(f, "store"),
|
||||
SegmentComponent::TempStore => write!(f, "temp"),
|
||||
SegmentComponent::Delete => write!(f, "del"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SegmentComponent {
|
||||
/// Iterates through the components.
|
||||
pub fn iterator() -> slice::Iter<'static, SegmentComponent> {
|
||||
|
||||
@@ -42,7 +42,7 @@ pub(crate) fn save_metas(
|
||||
) -> crate::Result<()> {
|
||||
info!("save metas");
|
||||
|
||||
match directory.save_metas(metas, previous_metas) {
|
||||
match directory.save_metas(metas, previous_metas, &mut ()) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(crate::TantivyError::InternalError(_)) => {
|
||||
let mut buffer = serde_json::to_vec_pretty(metas)?;
|
||||
|
||||
Reference in New Issue
Block a user