fix: repair `order_by_field` with date fields (#262)
parent
a14649f103
commit
52f7d6d08d
|
@ -182,7 +182,7 @@ impl Searcher {
|
||||||
if let Some(order_by) = order_by_field {
|
if let Some(order_by) = order_by_field {
|
||||||
let collector = TopDocs::with_limit(limit)
|
let collector = TopDocs::with_limit(limit)
|
||||||
.and_offset(offset)
|
.and_offset(offset)
|
||||||
.order_by_fast_field(order_by, order.into());
|
.order_by_u64_field(order_by, order.into());
|
||||||
let top_docs_handle =
|
let top_docs_handle =
|
||||||
multicollector.add_collector(collector);
|
multicollector.add_collector(collector);
|
||||||
let ret = self.inner.search(query.get(), &multicollector);
|
let ret = self.inner.search(query.get(), &multicollector);
|
||||||
|
|
|
@ -232,6 +232,57 @@ class TestClass(object):
|
||||||
result = searcher.search(query, 10, order_by_field="order")
|
result = searcher.search(query, 10, order_by_field="order")
|
||||||
assert len(result.hits) == 0
|
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):
|
def test_with_merges(self):
|
||||||
# This test is taken from tantivy's test suite:
|
# This test is taken from tantivy's test suite:
|
||||||
# https://github.com/quickwit-oss/tantivy/blob/42acd334f49d5ff7e4fe846b5c12198f24409b50/src/indexer/index_writer.rs#L1130
|
# https://github.com/quickwit-oss/tantivy/blob/42acd334f49d5ff7e4fe846b5c12198f24409b50/src/indexer/index_writer.rs#L1130
|
||||||
|
|
Loading…
Reference in New Issue