Skip to content

Bytes in Query.term_query #563

@andreymal

Description

@andreymal

The current implementation doesn't seem to handle Value::Bytes:

>>> import tantivy
>>> schema = tantivy.SchemaBuilder().add_bytes_field("foo", indexed=True).build()
>>> tantivy.Query.term_query(schema, "foo", b"\x01\x02\x03")
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    tantivy.Query.term_query(schema, "foo", b"\x01\x02\x03")
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Can't create a term for Field `foo` with value `b'\x01\x02\x03'`.

As usual, the workaround is to use parse_query, but this is inconvenient:

>>> import base64
>>> index = tantivy.Index(schema)
>>> index.parse_query("foo:" + base64.b64encode(b"\x01\x02\x03").decode())
Query(TermQuery(Term(field=0, type=Bytes, [1, 2, 3])))

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-parityFeature parity with upstream tantivyhelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions