Serve item bytes & fields
Some checks failed
CI / Typos (push) Successful in 27s
CI / Clippy (push) Failing after 59s
CI / Build and test (push) Failing after 4m45s

This commit is contained in:
2026-03-10 17:22:43 -07:00
parent a05cf9da01
commit 614d3273f0
3 changed files with 203 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
use chrono::{DateTime, Utc};
use pile_config::{ConfigToml, Label, Source};
use pile_config::{ConfigToml, Label, Source, objectpath::ObjectPath};
use pile_toolbox::cancelabletask::{CancelFlag, CancelableTaskError};
use serde_json::Value;
use std::{collections::HashMap, io::ErrorKind, path::PathBuf, sync::Arc, time::Instant};
use tantivy::{Executor, Index, IndexWriter, TantivyError, collector::TopDocs};
use thiserror::Error;
@@ -9,7 +10,8 @@ use tokio_stream::{StreamExt, wrappers::ReceiverStream};
use tracing::{debug, info, trace, warn};
use crate::{
DataSource, Item,
DataSource, Item, PileValue,
extract::MetaExtractor,
index::{DbFtsIndex, FtsLookupResult},
path_ts_earliest,
source::{DirDataSource, S3DataSource},
@@ -170,6 +172,25 @@ impl Datasets {
self.sources.get(source)?.get(key).await
}
/// Extract a field from an item by object path.
/// Returns `None` if the item or field is not found.
pub async fn get_field(
&self,
source: &Label,
key: &str,
path: &ObjectPath,
) -> Result<Option<Value>, std::io::Error> {
let Some(item) = self.get(source, key).await else {
return Ok(None);
};
let extractor = MetaExtractor::new(&item);
let root = PileValue::Extractor(Arc::new(extractor));
let Some(value) = root.query(path).await? else {
return Ok(None);
};
Ok(Some(value.to_json().await?))
}
//
// MARK: fts
//