From 0036e0dff77635b0cdf66c2e8de045db573967bf Mon Sep 17 00:00:00 2001 From: Tony Solomonik Date: Sat, 1 Jun 2024 12:46:32 +0300 Subject: [PATCH] Const "_dynamic" field name --- src/commands/index.rs | 4 ++-- src/commands/mod.rs | 2 ++ src/commands/search.rs | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/commands/index.rs b/src/commands/index.rs index 47205ec..0bab1c9 100644 --- a/src/commands/index.rs +++ b/src/commands/index.rs @@ -14,7 +14,7 @@ use tokio::{ use crate::{args::IndexArgs, index_config::FieldType}; -use super::{get_index_config, write_unified_index}; +use super::{get_index_config, write_unified_index, DYNAMIC_FIELD_NAME}; fn common_parse(value: serde_json::Value) -> Result { Ok(serde_json::from_value(value)?) @@ -57,7 +57,7 @@ pub async fn run_index(args: IndexArgs, pool: PgPool) -> Result<()> { let mut schema_builder = Schema::builder(); let dynamic_field = schema_builder.add_json_field( - "_dynamic", + DYNAMIC_FIELD_NAME, JsonObjectOptions::from(STORED | STRING).set_expand_dots_enabled(), ); diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 842cfd1..1653e2d 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -26,6 +26,8 @@ use crate::{ }, }; +const DYNAMIC_FIELD_NAME: &str = "_dynamic"; + async fn get_index_config(name: &str, pool: &PgPool) -> Result { let (value,): (serde_json::Value,) = query_as("SELECT config FROM indexes WHERE name=$1") .bind(name) diff --git a/src/commands/search.rs b/src/commands/search.rs index 5861ed8..6c4fd7a 100644 --- a/src/commands/search.rs +++ b/src/commands/search.rs @@ -13,7 +13,7 @@ use tokio::{spawn, sync::mpsc::channel, task::spawn_blocking}; use crate::args::SearchArgs; -use super::{get_index_config, open_unified_directories}; +use super::{get_index_config, open_unified_directories, DYNAMIC_FIELD_NAME}; fn get_prettified_json( doc: TantivyDocument, @@ -49,7 +49,7 @@ pub async fn run_search(args: SearchArgs, pool: PgPool) -> Result<()> { let indexed_field_names = { let mut fields = config.schema.get_indexed_fields(); - fields.push("_dynamic".to_string()); + fields.push(DYNAMIC_FIELD_NAME.to_string()); fields };