tantivy-py: Upgrade to PyO3 0.9.

master
Damir Jelić 2020-04-19 13:35:14 +02:00
parent 094f8974ea
commit b75f9d75b6
6 changed files with 17 additions and 19 deletions

View File

@ -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]

View File

@ -1 +1 @@
nightly-2020-01-03
nightly-2020-04-18

View File

@ -127,7 +127,7 @@ pub(crate) fn extract_value(any: &PyAny) -> PyResult<Value> {
if let Ok(num) = any.extract::<f64>() {
return Ok(Value::F64(num));
}
if let Ok(py_datetime) = any.downcast_ref::<PyDateTime>() {
if let Ok(py_datetime) = any.downcast::<PyDateTime>() {
let datetime = Utc
.ymd(
py_datetime.get_year(),
@ -142,14 +142,14 @@ pub(crate) fn extract_value(any: &PyAny) -> PyResult<Value> {
);
return Ok(Value::Date(datetime));
}
if let Ok(facet) = any.downcast_ref::<Facet>() {
if let Ok(facet) = any.extract::<Facet>() {
return Ok(Value::Facet(facet.inner.clone()));
}
Err(to_pyerr(format!("Value unsupported {:?}", any)))
}
fn extract_value_single_or_list(any: &PyAny) -> PyResult<Vec<Value>> {
if let Ok(values) = any.downcast_ref::<PyList>() {
if let Ok(values) = any.downcast::<PyList>() {
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<Vec<Value>> {
impl Document {
#[new]
#[args(kwargs = "**")]
fn new(obj: &PyRawObject, kwargs: Option<&PyDict>) -> PyResult<()> {
fn new(kwargs: Option<&PyDict>) -> PyResult<Self> {
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<String, Vec<tv::schema::Value>> =
BTreeMap::new();
for key_value_any in py_dict.items() {
if let Ok(key_value) = key_value_any.downcast_ref::<PyTuple>() {
if let Ok(key_value) = key_value_any.downcast::<PyTuple>() {
if key_value.len() != 2 {
continue;
}
@ -192,7 +191,7 @@ impl Document {
let mut field_values: BTreeMap<String, Vec<tv::schema::Value>> =
BTreeMap::new();
for key_value_any in py_dict.items() {
if let Ok(key_value) = key_value_any.downcast_ref::<PyTuple>() {
if let Ok(key_value) = key_value_any.downcast::<PyTuple>() {
if key_value.len() != 2 {
continue;
}

View File

@ -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,
}

View File

@ -165,11 +165,10 @@ impl Index {
#[new]
#[args(reuse = true)]
fn new(
obj: &PyRawObject,
schema: &Schema,
path: Option<&str>,
reuse: bool,
) -> PyResult<()> {
) -> PyResult<Self> {
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.

View File

@ -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.