Skip to content

Commit ee9143d

Browse files
authored
Add facet search test (#530)
1 parent 4017dee commit ee9143d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/tantivy_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,32 @@ def test_index_writer_context_block(self, schema):
596596
result = index.searcher().search(Query.all_query())
597597
assert len(result.hits) == 1
598598

599+
def test_simple_search_facet(self):
600+
schema = (
601+
tantivy.SchemaBuilder()
602+
.add_text_field("title", stored=True)
603+
.add_facet_field("category")
604+
)
605+
index = Index(schema.build())
606+
writer = index.writer(15_000_000, 1)
607+
doc = Document()
608+
doc.add_text("title", "Book about whales")
609+
doc.add_facet(
610+
"category",
611+
tantivy.Facet.from_string("/books/fiction")
612+
)
613+
with writer:
614+
writer.add_document(doc)
615+
616+
index.reload()
617+
618+
query = index.parse_query("+category:/books")
619+
result = index.searcher().search(query, 10)
620+
621+
query = index.parse_query("about", ["title"])
622+
result = index.searcher().search(query, 10)
623+
assert len(result.hits) == 1
624+
599625

600626
class TestUpdateClass(object):
601627
def test_delete_update(self, ram_index):

0 commit comments

Comments
 (0)