Skip to content

Commit

Permalink
Const "_dynamic" field name
Browse files Browse the repository at this point in the history
  • Loading branch information
tontinton committed Jun 1, 2024
1 parent c228a6e commit 0036e0d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/commands/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<OwnedValue> {
Ok(serde_json::from_value(value)?)
Expand Down Expand Up @@ -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(),
);

Expand Down
2 changes: 2 additions & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ use crate::{
},
};

const DYNAMIC_FIELD_NAME: &str = "_dynamic";

async fn get_index_config(name: &str, pool: &PgPool) -> Result<IndexConfig> {
let (value,): (serde_json::Value,) = query_as("SELECT config FROM indexes WHERE name=$1")
.bind(name)
Expand Down
4 changes: 2 additions & 2 deletions src/commands/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
};

Expand Down

0 comments on commit 0036e0d

Please sign in to comment.