use log::{debug, info, warn};
use std::collections::HashSet;
use std::sync::{Arc, RwLock};
use super::IndexError;
use crate::storage::GraphCache;
pub struct IndexManager {
index_names: Arc<RwLock<HashSet<String>>>,
}
impl IndexManager {
pub fn new() -> Self {
Self {
index_names: Arc::new(RwLock::new(HashSet::new())),
}
}
pub async fn create_index(
&self,
name: String,
_index_type: super::IndexType,
_config: super::IndexConfig,
) -> Result<(), IndexError> {
info!("Creating index '{}'", name);
let mut index_names = self
.index_names
.write()
.map_err(|e| IndexError::creation(format!("Failed to acquire lock: {}", e)))?;
if index_names.contains(&name) {
return Err(IndexError::AlreadyExists(name));
}
index_names.insert(name.clone());
debug!("Index '{}' created successfully", name);
Ok(())
}
pub async fn delete_index(&self, name: &str) -> Result<(), IndexError> {
info!("Deleting index '{}'", name);
let mut index_names = self
.index_names
.write()
.map_err(|e| IndexError::creation(format!("Failed to acquire lock: {}", e)))?;
if !index_names.remove(name) {
return Err(IndexError::NotFound(name.to_string()));
}
debug!("Index '{}' deleted successfully", name);
Ok(())
}
pub fn index_exists(&self, name: &str) -> bool {
self.index_names
.read()
.map(|names| names.contains(name))
.unwrap_or(false)
}
pub fn list_indexes(&self) -> Vec<String> {
self.index_names
.read()
.map(|names| names.iter().cloned().collect())
.unwrap_or_else(|_| Vec::new())
}
pub fn reindex_text_index(
&self,
_name: &str,
_graph: &Arc<GraphCache>,
) -> Result<usize, IndexError> {
warn!("Text index reindexing not supported in GraphLite");
Ok(0)
}
pub fn search_index_sync(
&self,
_index_name: &str,
_query_text: &str,
_limit: usize,
) -> Result<Vec<(String, f32)>, IndexError> {
warn!("Text search not supported in GraphLite");
Ok(Vec::new())
}
pub fn find_indexes_for_label(&self, _label: &str) -> Vec<String> {
Vec::new()
}
pub fn find_index_by_label_and_property(
&self,
_label: &str,
_property: &str,
) -> Option<String> {
None
}
}