File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -194,6 +194,9 @@ pub(crate) fn extract_value(any: &PyAny) -> PyResult<Value> {
194
194
if let Ok ( facet) = any. extract :: < Facet > ( ) {
195
195
return Ok ( Value :: Facet ( facet. inner ) ) ;
196
196
}
197
+ if let Ok ( b) = any. extract :: < Vec < u8 > > ( ) {
198
+ return Ok ( Value :: Bytes ( b) ) ;
199
+ }
197
200
Err ( to_pyerr ( format ! ( "Value unsupported {any:?}" ) ) )
198
201
}
199
202
Original file line number Diff line number Diff line change
1
+ from io import BytesIO
1
2
import tantivy
2
3
import pytest
3
4
@@ -531,3 +532,27 @@ def test_query_from_json_field(self):
531
532
# )
532
533
# result = index.searcher().search(query, 2)
533
534
# assert len(result.hits) == 1
535
+
536
+
537
+ @pytest .mark .parametrize ('bytes_kwarg' , [True , False ])
538
+ @pytest .mark .parametrize ('bytes_payload' , [
539
+ b"abc" ,
540
+ bytearray (b"abc" ),
541
+ memoryview (b"abc" ),
542
+ BytesIO (b"abc" ).read (),
543
+ BytesIO (b"abc" ).getbuffer (),
544
+ ])
545
+ def test_bytes (bytes_kwarg , bytes_payload ):
546
+ schema = SchemaBuilder ().add_bytes_field ("embedding" ).build ()
547
+ index = Index (schema )
548
+ writer = index .writer ()
549
+
550
+ if bytes_kwarg :
551
+ doc = Document (id = 1 , embedding = bytes_payload )
552
+ else :
553
+ doc = Document (id = 1 )
554
+ doc .add_bytes ("embedding" , bytes_payload )
555
+
556
+ writer .add_document (doc )
557
+ writer .commit ()
558
+ index .reload ()
You can’t perform that action at this time.
0 commit comments