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.

Compose reviewed alias, scoring and factory-definition corrections

xerj-orgc6c21804f099
diff --cc CHANGELOG.md
index 6648f858f,fb8388a86..abc2a0cb1
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -35,15 -35,12 +35,21 @@@ and this project adheres to [Semantic V
### Fixed
+- Boolean text queries with one `must` match now keep `filter` and `must_not`
+ clauses non-scoring before a flush and on mixed memory/segment indices.
+ Their retained hits use the same BM25 scores as the bare match (#2403).
+
+- Reindex preflights every source alias member before creating or writing the
+ destination. Aliases cannot hide a source/destination overlap; a missing
+ source, invalid query or source flush failure leaves destination data intact.
+ An alias with `is_write_index: false` refuses writes even with one member.
+
+ - TS/JS factory constants exported by a separate local export clause or
+ default identifier now get definition records at their declaration lines
+ (refs #2579). Inline `export const` stays supported; private constants,
+ function-local bindings, type-only exports and remote re-exports stay out.
+ Existing unchanged files need re-extraction to gain these definitions.
+
- Corpus cloning validates existing checkouts and serializes writers (#2453).
New checkouts are staged before publication. Ambiguous existing directories
are preserved for recovery rather than deleted or reset automatically.
diff --cc engine/crates/xerj-api/src/es_compat.rs
index a3bc15f4a,304dead05..74e7e7d3d
--- a/engine/crates/xerj-api/src/es_compat.rs
+++ b/engine/crates/xerj-api/src/es_compat.rs
@@@ -28394,25 -28369,36 +28394,25 @@@ pub async fn reindex
}
};
- // `source.index` may be an index, alias, or data stream. For an alias ES
- // Get or create destination index.
- let dest_idx = match state.engine.get_or_create_index(dest_name) {
- Ok(i) => i,
- Err(e) => return ApiError::new(xerj_common::XerjError::from(e)).into_response(),
- };
-
- // Fetch all docs from source via paginated search_after to handle large indices.
- let source_idx = match state.engine.get_index(source_name) {
- Ok(i) => i,
- Err(e) => return ApiError::new(xerj_common::XerjError::from(e)).into_response(),
- };
++ // `source.index` may be an index or alias. For an alias ES
+ // searches EVERY backing index and applies each member's alias filter;
+ // `get_index` resolves an alias to its first member only, so the old path
+ // silently copied a fraction of the alias and ignored its filters.
+ let source_members = state.engine.resolve_alias(source_name);
- // Flush the source memtable to segments before paging. `_id`-sorted
- // `search_after` keyset pagination is correct over on-disk segments, but
- // the in-memory memtable's field-sort path does NOT order by `_id`
- // reliably, so un-flushed recent writes would be skipped or duplicated
- // across pages. Reindex is a snapshot-style bulk op, so a single flush up
- // front is an acceptable cost and makes the whole source keyset-pageable.
- //
- // Propagated, not swallowed, for the same reason as `clone_index_to`: the
- // flush is a precondition of the paging being complete, so a failed flush
- // must not be followed by a reindex that reports `"total": N` over a source
- // it could not read consistently (issue #204).
- if let Err(e) = source_idx.flush().await {
- return ApiError::new(xerj_common::XerjError::internal(format!(
- "reindex from [{source_name}] into [{dest_name}] was not attempted: flushing \
- the source failed ({e}); the copy needs a flushed source to page over it \
- without skipping or duplicating documents"
- )))
- .into_response();
+ // Compare concrete identities: aliases must not hide a self-copy, which
+ // can rewrite source documents or copy earlier members into later ones.
+ if source_members.contains(&dest_name) {
+ let reason = format!("reindex cannot read and write the same index [{dest_name}]");
+ return (
+ StatusCode::BAD_REQUEST,
+ Json(json!({
+ "error": {"type": "illegal_argument_exception", "reason": reason,
+ "root_cause": [{"type": "illegal_argument_exception", "reason": reason}]},
+ "status": 400
+ })),
+ )
+ .into_response();
}
let query_val = body