From b75f9d75b63c6a5a14536a6c6c6e2070247dbfeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Sun, 19 Apr 2020 13:35:14 +0200 Subject: [PATCH] tantivy-py: Upgrade to PyO3 0.9. --- Cargo.toml | 6 +++--- rust-toolchain | 2 +- src/document.rs | 15 +++++++-------- src/facet.rs | 1 + src/index.rs | 6 ++---- src/schemabuilder.rs | 6 +++--- 6 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ec1a1de..d9d22f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,13 +10,13 @@ name = "tantivy" crate-type = ["cdylib"] [dependencies] -chrono = "0.4.10" +chrono = "0.4.11" tantivy = "0.12.0" -itertools = "0.8.2" +itertools = "0.9.0" futures = "0.3.4" [dependencies.pyo3] -version = "0.8.5" +version = "0.9.2" features = ["extension-module"] [package.metadata.maturin] diff --git a/rust-toolchain b/rust-toolchain index ac6e456..1b77fcf 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2020-01-03 +nightly-2020-04-18 diff --git a/src/document.rs b/src/document.rs index a8d2e8e..2818bf3 100644 --- a/src/document.rs +++ b/src/document.rs @@ -127,7 +127,7 @@ pub(crate) fn extract_value(any: &PyAny) -> PyResult { if let Ok(num) = any.extract::() { return Ok(Value::F64(num)); } - if let Ok(py_datetime) = any.downcast_ref::() { + if let Ok(py_datetime) = any.downcast::() { let datetime = Utc .ymd( py_datetime.get_year(), @@ -142,14 +142,14 @@ pub(crate) fn extract_value(any: &PyAny) -> PyResult { ); return Ok(Value::Date(datetime)); } - if let Ok(facet) = any.downcast_ref::() { + if let Ok(facet) = any.extract::() { return Ok(Value::Facet(facet.inner.clone())); } Err(to_pyerr(format!("Value unsupported {:?}", any))) } fn extract_value_single_or_list(any: &PyAny) -> PyResult> { - if let Ok(values) = any.downcast_ref::() { + if let Ok(values) = any.downcast::() { values.iter().map(extract_value).collect() } else { Ok(vec![extract_value(any)?]) @@ -160,20 +160,19 @@ fn extract_value_single_or_list(any: &PyAny) -> PyResult> { impl Document { #[new] #[args(kwargs = "**")] - fn new(obj: &PyRawObject, kwargs: Option<&PyDict>) -> PyResult<()> { + fn new(kwargs: Option<&PyDict>) -> PyResult { let mut document = Document::default(); if let Some(field_dict) = kwargs { document.extend(field_dict)?; } - obj.init(document); - Ok(()) + Ok(document) } fn extend(&mut self, py_dict: &PyDict) -> PyResult<()> { let mut field_values: BTreeMap> = BTreeMap::new(); for key_value_any in py_dict.items() { - if let Ok(key_value) = key_value_any.downcast_ref::() { + if let Ok(key_value) = key_value_any.downcast::() { if key_value.len() != 2 { continue; } @@ -192,7 +191,7 @@ impl Document { let mut field_values: BTreeMap> = BTreeMap::new(); for key_value_any in py_dict.items() { - if let Ok(key_value) = key_value_any.downcast_ref::() { + if let Ok(key_value) = key_value_any.downcast::() { if key_value.len() != 2 { continue; } diff --git a/src/facet.rs b/src/facet.rs index 1686a7c..3216b30 100644 --- a/src/facet.rs +++ b/src/facet.rs @@ -13,6 +13,7 @@ use tantivy::schema; /// ancestor of its facet. In the example above, /electronics/tv_and_video/ /// and /electronics. #[pyclass] +#[derive(Clone)] pub(crate) struct Facet { pub(crate) inner: schema::Facet, } diff --git a/src/index.rs b/src/index.rs index c7760bc..551e646 100644 --- a/src/index.rs +++ b/src/index.rs @@ -165,11 +165,10 @@ impl Index { #[new] #[args(reuse = true)] fn new( - obj: &PyRawObject, schema: &Schema, path: Option<&str>, reuse: bool, - ) -> PyResult<()> { + ) -> PyResult { let index = match path { Some(p) => { let directory = MmapDirectory::open(p).map_err(to_pyerr)?; @@ -184,8 +183,7 @@ impl Index { }; let reader = index.reader().map_err(to_pyerr)?; - obj.init(Index { index, reader }); - Ok(()) + Ok(Index { index, reader }) } /// Create a `IndexWriter` for the index. diff --git a/src/schemabuilder.rs b/src/schemabuilder.rs index 95233c7..6fd7128 100644 --- a/src/schemabuilder.rs +++ b/src/schemabuilder.rs @@ -35,10 +35,10 @@ const RECORD: &str = "position"; #[pymethods] impl SchemaBuilder { #[new] - fn new(obj: &PyRawObject) { - obj.init(SchemaBuilder { + fn new() -> Self { + SchemaBuilder { builder: Arc::new(From::from(Some(schema::Schema::builder()))), - }); + } } /// Add a new text field to the schema.