Skip to content

DateFormatError(ParseFromDescription(InvalidComponent("year"))) #2138

@sagoez

Description

@sagoez

Describe the bug

  • What did you do?

I created a blank schema with the following types:

  pub fn schema() -> TantivySchema {
       let mut schema_builder = TantivySchema::builder();
       SchemaField::iter().for_each(|field| {
           let opts = DateOptions::from(INDEXED)
               .set_stored()
               .set_fast()
               .set_precision(DateTimePrecision::Seconds);
           match field.r#type() {
               FieldTypes::Text => schema_builder.add_text_field(&field.name(), TEXT | STORED),
               FieldTypes::Integer => schema_builder.add_u64_field(&field.name(), FAST | STORED),
               FieldTypes::Float => schema_builder.add_f64_field(&field.name(), FAST | STORED),
               FieldTypes::Boolean => schema_builder.add_bool_field(&field.name(), FAST | STORED),
               FieldTypes::Date => schema_builder.add_date_field(&field.name(), opts),
               FieldTypes::Json => schema_builder.add_json_field(&field.name(), TEXT | STORED),
           };
       });

       schema_builder.build()
   }

From there the types that belong to my schema are actually the id which is of type u64 and created_at which is of type DateTime<Utc> from chrono. However, to test the validity of my program I'm using tantivy::DateTime::default() as follows:

    let body: Map<String, Value> = serde_json::from_value(json).map_err(|e| {
                Error::SchemaError(anyhow::anyhow!("Error deserializing document: {:?}", e))
    })?;

    let mut doc = Document::default();
    doc.add_u64(id_field, *id);
    doc.add_json_object(body_field, body);
    doc.add_date(created_at_field, TantivyDateTime::default());
    doc.add_date(updated_at_field, TantivyDateTime::default());
    acc.push(doc);
  • What happened?

When trying to query all I get is:

Error parsing term: DateFormatError(ParseFromDescription(InvalidComponent(\"year\")))"

Even for simple queries like a number or a letter. I tried removing fields from the searcher but no luck.

  • What was expected?

To query by date without issue.

Which version of tantivy are you using?

v.0.20.1

Let me know if this is enough, if not I can try to be more specific or even look for a minimum set for reproduction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions