2019-06-04 09:09:58 +00:00
|
|
|
use pyo3::prelude::*;
|
2019-08-02 11:23:10 +00:00
|
|
|
use pyo3::PyObjectProtocol;
|
2020-09-19 09:36:31 +00:00
|
|
|
use std::sync::Arc;
|
2019-06-04 09:09:58 +00:00
|
|
|
use tantivy as tv;
|
|
|
|
|
|
|
|
/// Tantivy's Query
|
|
|
|
#[pyclass]
|
|
|
|
pub(crate) struct Query {
|
2020-09-19 09:36:31 +00:00
|
|
|
pub(crate) query: Arc<String>,
|
|
|
|
pub(crate) parser: tv::query::QueryParser,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Query {
|
|
|
|
pub(crate) fn get(&self) -> Box<dyn tv::query::Query> {
|
|
|
|
self.parser
|
|
|
|
.parse_query(&self.query)
|
|
|
|
.expect("Created a query that returns a parse error")
|
|
|
|
}
|
2019-06-04 09:09:58 +00:00
|
|
|
}
|
|
|
|
|
2019-08-02 11:23:10 +00:00
|
|
|
#[pyproto]
|
|
|
|
impl PyObjectProtocol for Query {
|
|
|
|
fn __repr__(&self) -> PyResult<String> {
|
2020-09-19 09:36:31 +00:00
|
|
|
Ok(format!("Query({:?})", self.get()))
|
2019-06-04 09:09:58 +00:00
|
|
|
}
|
|
|
|
}
|