mod entity_search;
#[cfg(feature = "search")]
mod index;
#[cfg(feature = "search")]
pub mod search_stats;
pub mod typed;
pub use entity_search::{EntitySearch, EntitySearchResult};
#[cfg(feature = "search")]
pub use index::SearchIndex;
#[cfg(not(feature = "search"))]
mod stub_index {
use std::sync::Arc;
use crate::core::item::AnyItem;
pub struct SearchIndex;
impl SearchIndex {
pub fn new() -> Self {
Self
}
pub fn index_item(&self, _item: &Arc<dyn AnyItem>) {}
pub fn remove_entity(&self, _entity_type: &str, _entity_id: &str) {}
pub fn commit(&self) {}
pub fn search(&self, _entity_type: &str, _query: &str, _limit: usize) -> Vec<Arc<str>> {
Vec::new()
}
pub fn is_searchable(&self, _entity_type: &str) -> bool {
false
}
pub fn build_from_registry(&self, _registry: &crate::store::StoreRegistry) {}
}
impl Default for SearchIndex {
fn default() -> Self {
Self::new()
}
}
}
#[cfg(not(feature = "search"))]
pub use stub_index::SearchIndex;
pub struct SearchableRegistration {
pub entity_type: &'static str,
pub fields: &'static [&'static str],
pub register_typed: Option<fn(&mut typed::SearchRegistry)>,
}
inventory::collect!(SearchableRegistration);
pub fn iter_searchable() -> impl Iterator<Item = &'static SearchableRegistration> {
inventory::iter::<SearchableRegistration>()
}
pub fn build_typed_registry() -> typed::SearchRegistry {
let mut registry = typed::SearchRegistry::new();
for reg in iter_searchable() {
if let Some(register) = reg.register_typed {
register(&mut registry);
}
}
registry
}
pub fn default_search_limit() -> usize {
100
}