[tantivy] Fix for schema deserialization error (#902)

Co-authored-by: Pasha <pasha@izihawa.net>
This commit is contained in:
Pasha Podolsky
2020-10-05 05:24:48 +03:00
committed by GitHub
parent ad82b455a3
commit 687a36a49c
2 changed files with 17 additions and 3 deletions

View File

@@ -58,6 +58,7 @@ rand = "0.7"
maplit = "1"
matches = "0.1.8"
proptest = "0.10"
serde_yaml = "0.8.13"
[dev-dependencies.fail]
version = "0.4"

View File

@@ -223,8 +223,8 @@ impl<'de> Deserialize<'de> for FieldEntry {
if ty.is_some() {
return Err(de::Error::duplicate_field("type"));
}
let type_string = map.next_value()?;
match type_string {
let type_string = map.next_value::<String>()?;
match type_string.as_str() {
"hierarchical_facet" => {
field_type = Some(FieldType::HierarchicalFacet);
}
@@ -241,7 +241,7 @@ impl<'de> Deserialize<'de> for FieldEntry {
specified before `options`";
return Err(de::Error::custom(msg));
}
Some(ty) => match ty {
Some(ref ty) => match ty.as_str() {
"text" => field_type = Some(FieldType::Str(map.next_value()?)),
"u64" => field_type = Some(FieldType::U64(map.next_value()?)),
"i64" => field_type = Some(FieldType::I64(map.next_value()?)),
@@ -309,4 +309,17 @@ mod tests {
_ => panic!("expected FieldType::Str"),
}
}
#[test]
fn test_yaml_deserialization() {
let schema_content = r#"
name: text
type: text
options:
indexing:
record: position
tokenizer: default
stored: true
"#;
serde_yaml::from_str::<FieldEntry>(schema_content).unwrap();
}
}