You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to query the tantivy index by date. I have come up with the following minimal example so far:
import tantivy
from datetime import datetime
schema_builder = tantivy.SchemaBuilder()
schema_builder.add_text_field("title", stored=True)
schema_builder.add_date_field("date", stored=True, indexed=True)
schema = schema_builder.build()
index = tantivy.Index(schema)
writer = index.writer()
writer.add_document(
tantivy.Document(
doc_id=1,
title=["The Old Man and the Sea"],
date=datetime(2024, 1, 2, 0, 0, 0)
)
)
writer.add_document(
tantivy.Document(
doc_id=1,
title=["The Old Man and the Sea 2"],
date=datetime(2024, 2, 1, 0, 0, 0)
)
)
writer.commit()
index.reload()
How can I now create the search query for the date values?
I have tried some variations like the following:
index.parse_query("date:[datetime(2023,12,1,0,0,0) TO datetime(2024,1,3,0,0,0)]") or query = index.parse_query("date:[2023-12-01 00:00:00 TO 2024-01-03 00:00:00]") using the date query described here https://docs.rs/tantivy/latest/tantivy/query/struct.QueryParser.html as an example. These kind of queries lead to the following error: ValueError: Syntax Error: date:[2023-12-01 00:00:00 TO 2024-01-03 00:00:00].
I also reformatted the datetime dates to rfc3339 formatted dates, but this leads to an io:Error or panic error.
I also had a look at the documentation and the test files in this repo, but I could not find an example.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi all,
I need to query the tantivy index by date. I have come up with the following minimal example so far:
How can I now create the search query for the date values?
I have tried some variations like the following:
index.parse_query("date:[datetime(2023,12,1,0,0,0) TO datetime(2024,1,3,0,0,0)]")
orquery = index.parse_query("date:[2023-12-01 00:00:00 TO 2024-01-03 00:00:00]")
using the date query described here https://docs.rs/tantivy/latest/tantivy/query/struct.QueryParser.html as an example. These kind of queries lead to the following error:ValueError: Syntax Error: date:[2023-12-01 00:00:00 TO 2024-01-03 00:00:00]
.I also reformatted the datetime dates to rfc3339 formatted dates, but this leads to an io:Error or panic error.
I also had a look at the documentation and the test files in this repo, but I could not find an example.
Thanks so much for your help!
Beta Was this translation helpful? Give feedback.
All reactions