pub mod query;
pub mod schema;
pub mod snippets;
pub mod tokenizer;
pub mod writer;
pub use query::execute_on_mem;
pub fn metadata_index_text(entity: &crate::entity::Entity) -> String {
let mut out = String::new();
for (key, value) in &entity.metadata {
out.push_str(key);
out.push(' ');
out.push_str(&value.to_frontmatter_string());
out.push('\n');
}
out
}
pub use schema::IndexFields;
pub use snippets::{compute_matched_terms, compute_score_breakdown};
pub use writer::MemIndex;
use std::collections::HashMap;
use std::sync::Arc;
use memstead_schema::Schema;
use crate::store::Store;
pub fn build_all(
store: &Store,
writable_schemas: &HashMap<String, Arc<Schema>>,
) -> HashMap<String, MemIndex> {
let mut indexes: HashMap<String, MemIndex> = HashMap::new();
for (name, schema) in writable_schemas {
match MemIndex::build_in_ram(name.clone(), Some(schema)) {
Ok(idx) => {
indexes.insert(name.clone(), idx);
}
Err(e) => {
tracing::warn!(
mem = name.as_str(),
error = %e,
"failed to create search index for writable mem; skipping"
);
}
}
}
for entity in store.all_entities() {
if entity.stub {
continue;
}
let Some(idx) = indexes.get_mut(&entity.mem) else {
continue;
};
if let Err(e) = idx.index_entity(entity) {
tracing::warn!(
mem = entity.mem.as_str(),
id = entity.id.as_ref(),
error = %e,
"failed to index entity during bulk build"
);
}
}
for idx in indexes.values_mut() {
if let Err(e) = idx.commit() {
tracing::warn!(
mem = idx.mem.as_str(),
error = %e,
"failed to commit mem index after bulk build"
);
}
}
indexes
}