From 785e37fb06a9578c3281af1bd853125e3dea01a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Sat, 19 Sep 2020 15:17:07 +0200 Subject: [PATCH] query: Upgrade to Tantivy 0.13.1 so we don't need the query hack anymore. --- Cargo.toml | 2 +- src/index.rs | 7 ++----- src/query.rs | 10 +++------- src/searcher.rs | 4 ++-- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 38a3402..2506d3d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ crate-type = ["cdylib"] [dependencies] chrono = "0.4.15" -tantivy = "0.13.0" +tantivy = "0.13.1" itertools = "0.9.0" futures = "0.3.5" diff --git a/src/index.rs b/src/index.rs index 911cf17..4054998 100644 --- a/src/index.rs +++ b/src/index.rs @@ -1,7 +1,5 @@ #![allow(clippy::new_ret_no_self)] -use std::sync::Arc; - use pyo3::exceptions; use pyo3::prelude::*; use pyo3::types::PyAny; @@ -339,11 +337,10 @@ impl Index { } let parser = tv::query::QueryParser::for_index(&self.index, default_fields); - parser.parse_query(query).map_err(to_pyerr)?; + let query = parser.parse_query(query).map_err(to_pyerr)?; Ok(Query { - query: Arc::new(query.to_owned()), - parser, + inner: query, }) } } diff --git a/src/query.rs b/src/query.rs index 849318d..1023309 100644 --- a/src/query.rs +++ b/src/query.rs @@ -1,20 +1,16 @@ use pyo3::prelude::*; use pyo3::PyObjectProtocol; -use std::sync::Arc; use tantivy as tv; /// Tantivy's Query #[pyclass] pub(crate) struct Query { - pub(crate) query: Arc, - pub(crate) parser: tv::query::QueryParser, + pub(crate) inner: Box, } impl Query { - pub(crate) fn get(&self) -> Box { - self.parser - .parse_query(&self.query) - .expect("Created a query that returns a parse error") + pub(crate) fn get(&self) -> &dyn tv::query::Query { + &self.inner } } diff --git a/src/searcher.rs b/src/searcher.rs index a22b29e..2f2c256 100644 --- a/src/searcher.rs +++ b/src/searcher.rs @@ -125,7 +125,7 @@ impl Searcher { .and_offset(offset) .order_by_u64_field(field); let top_docs_handle = multicollector.add_collector(collector); - let ret = self.inner.search(&query.get(), &multicollector); + let ret = self.inner.search(query.get(), &multicollector); match ret { Ok(mut r) => { @@ -143,7 +143,7 @@ impl Searcher { } else { let collector = TopDocs::with_limit(limit).and_offset(offset); let top_docs_handle = multicollector.add_collector(collector); - let ret = self.inner.search(&query.get(), &multicollector); + let ret = self.inner.search(query.get(), &multicollector); match ret { Ok(mut r) => {