Skip to content

Commit 3cfa466

Browse files
committedJun 1, 2024·
config: Change fields to be a list instead of map
1 parent c273db6 commit 3cfa466

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed
 

‎example_config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ path: /tmp/toshokan
44
schema:
55
time_field: timestamp
66
fields:
7-
timestamp:
7+
- name: timestamp
88
type: !datetime
99
formats:
1010
- timestamp
1111
indexed: true
1212
stored: true
1313
fast: true
14-
tenant_id:
14+
- name: tenant_id
1515
type: !number
1616
type: u64
17-
resource:
17+
- name: resource
1818
type: !dynamic_object
1919
expand_dots: true

‎src/commands/index.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::collections::HashMap;
2-
31
use color_eyre::{eyre::eyre, Result};
42
use sqlx::PgPool;
53
use tantivy::{
@@ -32,11 +30,12 @@ fn common_parse(value: serde_json::Value) -> Result<OwnedValue> {
3230
}
3331

3432
fn get_field_parsers(
35-
fields: HashMap<String, FieldsConfig>,
33+
fields: Vec<FieldsConfig>,
3634
schema_builder: &mut SchemaBuilder,
3735
) -> Result<Vec<FieldParsers>> {
3836
let mut field_parsers: Vec<FieldParsers> = Vec::with_capacity(fields.len());
39-
for (name, schema) in fields {
37+
for schema in fields {
38+
let name = schema.name;
4039
match schema.type_ {
4140
FieldType::Text(options) => {
4241
let field = schema_builder.add_text_field(&name, options);

‎src/config/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub mod ip;
55
pub mod number;
66
pub mod text;
77

8-
use std::{collections::HashMap, path::Path};
8+
use std::path::Path;
99

1010
use color_eyre::eyre::Result;
1111
use serde::{Deserialize, Serialize};
@@ -100,6 +100,8 @@ pub enum FieldType {
100100

101101
#[derive(Debug, Clone, Serialize, Deserialize)]
102102
pub struct FieldsConfig {
103+
pub name: String,
104+
103105
#[serde(rename = "type")]
104106
pub type_: FieldType,
105107
}
@@ -123,7 +125,7 @@ impl FieldsConfig {
123125
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
124126
pub struct IndexSchema {
125127
#[serde(default)]
126-
pub fields: HashMap<String, FieldsConfig>,
128+
pub fields: Vec<FieldsConfig>,
127129

128130
#[serde(default)]
129131
#[serde(skip_serializing_if = "Option::is_none")]
@@ -134,9 +136,8 @@ impl IndexSchema {
134136
pub fn get_indexed_fields(&self) -> Vec<String> {
135137
self.fields
136138
.iter()
137-
.filter(|(_, v)| v.is_indexed())
138-
.map(|(k, _)| k)
139-
.cloned()
139+
.filter(|x| x.is_indexed())
140+
.map(|x| x.name.clone())
140141
.collect()
141142
}
142143
}

0 commit comments

Comments
 (0)
Please sign in to comment.