diff --git a/src/searcher.rs b/src/searcher.rs index cecef89..e87ac4e 100644 --- a/src/searcher.rs +++ b/src/searcher.rs @@ -182,7 +182,7 @@ impl Searcher { if let Some(order_by) = order_by_field { let collector = TopDocs::with_limit(limit) .and_offset(offset) - .order_by_fast_field(order_by, order.into()); + .order_by_u64_field(order_by, order.into()); let top_docs_handle = multicollector.add_collector(collector); let ret = self.inner.search(query.get(), &multicollector); diff --git a/tests/tantivy_test.py b/tests/tantivy_test.py index 96d64f7..e2a77eb 100644 --- a/tests/tantivy_test.py +++ b/tests/tantivy_test.py @@ -232,6 +232,57 @@ class TestClass(object): result = searcher.search(query, 10, order_by_field="order") assert len(result.hits) == 0 + def test_order_by_search_date(self): + schema = ( + SchemaBuilder() + .add_date_field("order", fast=True) + .add_text_field("title", stored=True) + .build() + ) + + index = Index(schema) + writer = index.writer() + + doc = Document() + doc.add_date("order", datetime.datetime(2020, 1, 1)) + doc.add_text("title", "Test title") + + writer.add_document(doc) + + doc = Document() + doc.add_date("order", datetime.datetime(2022, 1, 1)) + doc.add_text("title", "Final test title") + writer.add_document(doc) + + doc = Document() + doc.add_date("order", datetime.datetime(2021, 1, 1)) + doc.add_text("title", "Another test title") + + writer.add_document(doc) + + writer.commit() + index.reload() + + query = index.parse_query("test") + + searcher = index.searcher() + + result = searcher.search(query, 10, order_by_field="order") + + assert len(result.hits) == 3 + + _, doc_address = result.hits[0] + searched_doc = index.searcher().doc(doc_address) + assert searched_doc["title"] == ["Final test title"] + + _, doc_address = result.hits[1] + searched_doc = index.searcher().doc(doc_address) + assert searched_doc["title"] == ["Another test title"] + + _, doc_address = result.hits[2] + searched_doc = index.searcher().doc(doc_address) + assert searched_doc["title"] == ["Test title"] + def test_with_merges(self): # This test is taken from tantivy's test suite: # https://github.com/quickwit-oss/tantivy/blob/42acd334f49d5ff7e4fe846b5c12198f24409b50/src/indexer/index_writer.rs#L1130