Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sagoez opened this issue Aug 8, 2023 · 1 comment
Closed

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

sagoez opened this issue Aug 8, 2023 · 1 comment

Comments

@sagoez
Copy link

sagoez commented Aug 8, 2023

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.

@sagoez sagoez closed this as completed Aug 8, 2023
@sagoez
Copy link
Author

sagoez commented Aug 8, 2023

Realised I was misusing the API. Counting the hours for this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant