Serve item bytes & fields
This commit is contained in:
@@ -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
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user