Include check for bytes in extract_value, fixes #72
parent
2b1439c77e
commit
2f65cc65ff
|
@ -194,6 +194,9 @@ pub(crate) fn extract_value(any: &PyAny) -> PyResult<Value> {
|
||||||
if let Ok(facet) = any.extract::<Facet>() {
|
if let Ok(facet) = any.extract::<Facet>() {
|
||||||
return Ok(Value::Facet(facet.inner));
|
return Ok(Value::Facet(facet.inner));
|
||||||
}
|
}
|
||||||
|
if let Ok(b) = any.extract::<Vec<u8>>() {
|
||||||
|
return Ok(Value::Bytes(b))
|
||||||
|
}
|
||||||
Err(to_pyerr(format!("Value unsupported {any:?}")))
|
Err(to_pyerr(format!("Value unsupported {any:?}")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from io import BytesIO
|
||||||
import tantivy
|
import tantivy
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -531,3 +532,27 @@ class TestJsonField:
|
||||||
# )
|
# )
|
||||||
# result = index.searcher().search(query, 2)
|
# result = index.searcher().search(query, 2)
|
||||||
# assert len(result.hits) == 1
|
# assert len(result.hits) == 1
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('bytes_kwarg', [True, False])
|
||||||
|
@pytest.mark.parametrize('bytes_payload', [
|
||||||
|
b"abc",
|
||||||
|
bytearray(b"abc"),
|
||||||
|
memoryview(b"abc"),
|
||||||
|
BytesIO(b"abc").read(),
|
||||||
|
BytesIO(b"abc").getbuffer(),
|
||||||
|
])
|
||||||
|
def test_bytes(bytes_kwarg, bytes_payload):
|
||||||
|
schema = SchemaBuilder().add_bytes_field("embedding",).build()
|
||||||
|
index = Index(schema)
|
||||||
|
writer = index.writer()
|
||||||
|
|
||||||
|
if bytes_kwarg:
|
||||||
|
doc = Document(id=1, embedding=bytes_payload)
|
||||||
|
else:
|
||||||
|
doc = Document(id=1)
|
||||||
|
doc.add_bytes("embedding", bytes_payload)
|
||||||
|
|
||||||
|
writer.add_document(doc)
|
||||||
|
writer.commit()
|
||||||
|
index.reload()
|
||||||
|
|
Loading…
Reference in New Issue