query: Upgrade to Tantivy 0.13.1 so we don't need the query hack anymore.

master
Damir Jelić 2020-09-19 15:17:07 +02:00
parent e91726e010
commit 785e37fb06
4 changed files with 8 additions and 15 deletions

View File

@ -13,7 +13,7 @@ crate-type = ["cdylib"]
[dependencies] [dependencies]
chrono = "0.4.15" chrono = "0.4.15"
tantivy = "0.13.0" tantivy = "0.13.1"
itertools = "0.9.0" itertools = "0.9.0"
futures = "0.3.5" futures = "0.3.5"

View File

@ -1,7 +1,5 @@
#![allow(clippy::new_ret_no_self)] #![allow(clippy::new_ret_no_self)]
use std::sync::Arc;
use pyo3::exceptions; use pyo3::exceptions;
use pyo3::prelude::*; use pyo3::prelude::*;
use pyo3::types::PyAny; use pyo3::types::PyAny;
@ -339,11 +337,10 @@ impl Index {
} }
let parser = let parser =
tv::query::QueryParser::for_index(&self.index, default_fields); 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 { Ok(Query {
query: Arc::new(query.to_owned()), inner: query,
parser,
}) })
} }
} }

View File

@ -1,20 +1,16 @@
use pyo3::prelude::*; use pyo3::prelude::*;
use pyo3::PyObjectProtocol; use pyo3::PyObjectProtocol;
use std::sync::Arc;
use tantivy as tv; use tantivy as tv;
/// Tantivy's Query /// Tantivy's Query
#[pyclass] #[pyclass]
pub(crate) struct Query { pub(crate) struct Query {
pub(crate) query: Arc<String>, pub(crate) inner: Box<dyn tv::query::Query>,
pub(crate) parser: tv::query::QueryParser,
} }
impl Query { impl Query {
pub(crate) fn get(&self) -> Box<dyn tv::query::Query> { pub(crate) fn get(&self) -> &dyn tv::query::Query {
self.parser &self.inner
.parse_query(&self.query)
.expect("Created a query that returns a parse error")
} }
} }

View File

@ -125,7 +125,7 @@ impl Searcher {
.and_offset(offset) .and_offset(offset)
.order_by_u64_field(field); .order_by_u64_field(field);
let top_docs_handle = multicollector.add_collector(collector); 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 { match ret {
Ok(mut r) => { Ok(mut r) => {
@ -143,7 +143,7 @@ impl Searcher {
} else { } else {
let collector = TopDocs::with_limit(limit).and_offset(offset); let collector = TopDocs::with_limit(limit).and_offset(offset);
let top_docs_handle = multicollector.add_collector(collector); 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 { match ret {
Ok(mut r) => { Ok(mut r) => {