search fix to new architecture
This commit is contained in:
@@ -18,6 +18,17 @@ pub const F_DATA_WORD: &str = "data_word";
|
||||
pub const F_DATA_NGRAM: &str = "data_ngram";
|
||||
pub const F_DATA_EXACT: &str = "data_exact";
|
||||
pub const JOURNAL_TABLE_NAME: &str = "general_ledger";
|
||||
pub const ARCHIVED_ROW_KEY_PREFIX: &str = "__archive__:";
|
||||
pub const SEARCH_INDEX_FORMAT_DIRECTORY: &str = "v2";
|
||||
|
||||
/// Root for the current on-disk index format. The format component prevents
|
||||
/// an executable with new projection semantics from opening old documents.
|
||||
pub fn search_index_root() -> PathBuf {
|
||||
std::env::var_os("TANTIVY_INDEX_DIR")
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| PathBuf::from("./tantivy_indexes"))
|
||||
.join(SEARCH_INDEX_FORMAT_DIRECTORY)
|
||||
}
|
||||
|
||||
pub const TOK_WORD: &str = "kw_word";
|
||||
pub const TOK_NGRAM: &str = "kw_ngram";
|
||||
@@ -33,6 +44,30 @@ pub fn search_row_key(table_name: &str, row_id: i64) -> String {
|
||||
format!("{}:{}", table_name, row_id)
|
||||
}
|
||||
|
||||
/// Returns the unique index key for an immutable archived row version.
|
||||
pub fn archived_search_row_key(
|
||||
table_definition_id: i64,
|
||||
row_id: i64,
|
||||
version_number: i64,
|
||||
) -> String {
|
||||
format!(
|
||||
"{ARCHIVED_ROW_KEY_PREFIX}{table_definition_id}:{row_id}:{version_number}"
|
||||
)
|
||||
}
|
||||
|
||||
/// Decodes an archived index key into (table definition, row, version).
|
||||
pub fn parse_archived_search_row_key(row_key: &str) -> Option<(i64, i64, i64)> {
|
||||
let encoded = row_key.strip_prefix(ARCHIVED_ROW_KEY_PREFIX)?;
|
||||
let mut parts = encoded.split(':');
|
||||
let table_definition_id = parts.next()?.parse().ok()?;
|
||||
let row_id = parts.next()?.parse().ok()?;
|
||||
let version_number = parts.next()?.parse().ok()?;
|
||||
if parts.next().is_some() {
|
||||
return None;
|
||||
}
|
||||
Some((table_definition_id, row_id, version_number))
|
||||
}
|
||||
|
||||
/// Normalizes user-entered values for exact-mode terms.
|
||||
pub fn normalize_exact(input: &str) -> String {
|
||||
let trimmed = input.trim();
|
||||
@@ -184,6 +219,19 @@ impl SchemaFields {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{archived_search_row_key, parse_archived_search_row_key};
|
||||
|
||||
#[test]
|
||||
fn archived_row_key_round_trips_stable_identity() {
|
||||
let key = archived_search_row_key(42, 7, 3);
|
||||
assert_eq!(parse_archived_search_row_key(&key), Some((42, 7, 3)));
|
||||
assert_eq!(parse_archived_search_row_key("customers:7"), None);
|
||||
assert_eq!(parse_archived_search_row_key("__archive__:42:7"), None);
|
||||
}
|
||||
}
|
||||
|
||||
fn get_field(schema: &Schema, name: &str) -> tantivy::Result<Field> {
|
||||
schema.get_field(name).map_err(|e| {
|
||||
tantivy::TantivyError::SchemaError(format!("schema is missing field '{name}': {e}"))
|
||||
|
||||
Reference in New Issue
Block a user