Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

feat(api): wire _close/_open to the RAM-releasing engine methods (#463)

xerj-orged51833f3a99
diff --git a/engine/crates/xerj-api/src/es_compat.rs b/engine/crates/xerj-api/src/es_compat.rs
index 3fef19a2c..8d2ed5032 100644
--- a/engine/crates/xerj-api/src/es_compat.rs
+++ b/engine/crates/xerj-api/src/es_compat.rs
@@ -27806,7 +27806,12 @@ pub async fn close_index(
};
let mut indices = serde_json::Map::new();
for (name, _) in &handles {
- state.engine.closed_indices.insert(name.clone(), true);
+ // #463: actually release the index's RAM (flush → drop the in-memory
+ // handle), not just flip the closed flag. A flush failure aborts the
+ // close and leaves the index in service rather than losing data.
+ if let Err(e) = state.engine.close_index(name).await {
+ return ApiError::new(xerj_common::XerjError::from(e)).into_response();
+ }
indices.insert(name.clone(), json!({ "closed": true }));
}
Json(json!({
@@ -27821,6 +27826,28 @@ pub async fn open_index(
State(state): State<AppState>,
Path(index): Path<String>,
) -> impl IntoResponse {
+ // #463: a `_close` that reclaimed RAM dropped the index's in-memory handle,
+ // so it is not in the loaded set that `resolve_indices_for_op` sees. Any
+ // closed index the spec names is reconstructed from disk FIRST, so the
+ // resolve + reopen loop below finds it. Concrete names match directly;
+ // wildcards/_all match against the closed set.
+ let closed_names: Vec<String> = state
+ .engine
+ .closed_indices
+ .iter()
+ .map(|e| e.key().clone())
+ .collect();
+ for name in &closed_names {
+ let named = index
+ .split(',')
+ .map(str::trim)
+ .any(|p| p == "_all" || p == "*" || p == name || glob_match_simple(p, name));
+ if named && !state.engine.is_index_loaded(name) {
+ if let Err(e) = state.engine.reopen_index(name) {
+ return ApiError::new(xerj_common::XerjError::from(e)).into_response();
+ }
+ }
+ }
let handles = match resolve_indices_for_op(&state, &index).await {
Ok(h) => h,
Err(e) => return ApiError::new(e).into_response(),