Skip to content

Metadata filtering on a query #414

Closed Answered by ZmeiGorynych
ZmeiGorynych asked this question in Q&A
Discussion options

You must be logged in to vote

Ah, figured it out, here is a self-contained example for those like me who struggle to piece the docs together:

from tantivy import Query, Occur, Index, SchemaBuilder, Document

# Define schema using SchemaBuilder
schema_builder = SchemaBuilder()
schema_builder.add_text_field("title", stored=True)
schema_builder.add_integer_field("year", stored=True, indexed=True)
schema_builder.add_text_field("doc_type", stored=True)
schema = schema_builder.build()

# Create index
index = Index(schema)
writer = index.writer()

# Insert documents
# Relevant docs (matching "example" and year between 2020-2025)
writer.add_document(Document(
    title=["An example document"],
    doc_type="Confluence",
    y…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ZmeiGorynych
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant