pub struct EnrichEngine<'a> { /* private fields */ }Expand description
Enrichment workflow engine.
Implementations§
Source§impl<'a> EnrichEngine<'a>
impl<'a> EnrichEngine<'a>
Sourcepub async fn find_candidates(
&self,
query: &EnrichQuery,
) -> Result<Vec<EnrichCandidate>>
pub async fn find_candidates( &self, query: &EnrichQuery, ) -> Result<Vec<EnrichCandidate>>
Find notes that have empty fields matching the query criteria.
Returns a list of candidates with information about which fields need enrichment.
§Arguments
query- Query parameters specifying search filter and fields to check
§Example
let engine = Engine::new();
let query = EnrichQuery {
search: "deck:\"My Deck\" note:Basic".to_string(),
empty_fields: vec!["Example".to_string(), "Pronunciation".to_string()],
};
let candidates = engine.enrich().find_candidates(&query).await?;
for candidate in &candidates {
println!("Note {} needs: {:?}", candidate.note_id, candidate.empty_fields);
}Sourcepub async fn update_note(
&self,
note_id: i64,
fields: &HashMap<String, String>,
) -> Result<()>
pub async fn update_note( &self, note_id: i64, fields: &HashMap<String, String>, ) -> Result<()>
Update a single note with new field values.
§Arguments
note_id- The note to updatefields- Map of field name to new value
§Example
let engine = Engine::new();
let mut fields = HashMap::new();
fields.insert("Example".to_string(), "This is an example sentence.".to_string());
engine.enrich().update_note(12345, &fields).await?;Sourcepub async fn update_notes(
&self,
updates: &[(i64, HashMap<String, String>)],
) -> Result<EnrichReport>
pub async fn update_notes( &self, updates: &[(i64, HashMap<String, String>)], ) -> Result<EnrichReport>
Update multiple notes with new field values.
§Arguments
updates- List of (note_id, fields) pairs to update
§Example
let engine = Engine::new();
let updates: Vec<(i64, HashMap<String, String>)> = vec![
(12345, [("Example".to_string(), "Example 1".to_string())].into_iter().collect()),
(12346, [("Example".to_string(), "Example 2".to_string())].into_iter().collect()),
];
let report = engine.enrich().update_notes(&updates).await?;
println!("Updated: {}, Failed: {}", report.updated, report.failed);Sourcepub async fn tag_enriched(&self, note_ids: &[i64], tag: &str) -> Result<()>
pub async fn tag_enriched(&self, note_ids: &[i64], tag: &str) -> Result<()>
Add a tag to notes after enrichment.
Useful for marking notes as processed.
§Arguments
note_ids- Notes to tagtag- Tag to add
Sourcepub async fn pipeline(&self, query: &EnrichQuery) -> Result<EnrichmentPipeline>
pub async fn pipeline(&self, query: &EnrichQuery) -> Result<EnrichmentPipeline>
Create an enrichment pipeline for batch processing.
The pipeline finds candidates and provides helpers for grouping, updating, and committing changes.
§Arguments
query- Query parameters specifying search filter and fields to check
§Example
let engine = Engine::new();
let query = EnrichQuery {
search: "deck:Japanese".to_string(),
empty_fields: vec!["Example".to_string(), "Pronunciation".to_string()],
};
let mut pipeline = engine.enrich().pipeline(&query).await?;
// Process by missing field for efficient batching
for (field, candidates) in pipeline.by_missing_field() {
println!("Field '{}' needs {} notes enriched", field, candidates.len());
}
// Buffer updates - collect IDs first to avoid borrow issues
let note_ids: Vec<i64> = pipeline.candidates().iter().map(|c| c.note_id).collect();
for note_id in note_ids {
pipeline.update(note_id, [
("Example".to_string(), "Generated example".to_string())
].into_iter().collect());
}
// Commit all updates
let report = pipeline.commit(&engine).await?;
println!("Updated {} notes", report.updated);Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for EnrichEngine<'a>
impl<'a> !RefUnwindSafe for EnrichEngine<'a>
impl<'a> Send for EnrichEngine<'a>
impl<'a> Sync for EnrichEngine<'a>
impl<'a> Unpin for EnrichEngine<'a>
impl<'a> !UnwindSafe for EnrichEngine<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more