support for offset to do record pagination

master
sourcepirate 2020-09-05 23:51:54 +08:00
parent 8a7eac3e78
commit 89e1cabc58
2 changed files with 5 additions and 4 deletions

View File

@ -13,7 +13,7 @@ crate-type = ["cdylib"]
[dependencies]
chrono = "0.4.11"
tantivy = "0.12.0"
tantivy = "0.13.0"
itertools = "0.9.0"
futures = "0.3.4"

View File

@ -98,12 +98,13 @@ impl Searcher {
/// Returns `SearchResult` object.
///
/// Raises a ValueError if there was an error with the search.
#[args(limit = 10, count = true)]
#[args(limit = 10, offset = 0, count = true)]
fn search(
&self,
_py: Python,
query: &Query,
limit: usize,
offset: usize,
count: bool,
order_by_field: Option<&str>,
) -> PyResult<SearchResult> {
@ -119,7 +120,7 @@ impl Searcher {
if let Some(order_by) = order_by_field {
let field = get_field(&self.inner.index().schema(), order_by)?;
let collector =
TopDocs::with_limit(limit).order_by_u64_field(field);
TopDocs::with_limit(limit).and_offset(offset).order_by_u64_field(field);
let top_docs_handle = multicollector.add_collector(collector);
let ret = self.inner.search(&query.inner, &multicollector);
@ -137,7 +138,7 @@ impl Searcher {
Err(e) => return Err(ValueError::py_err(e.to_string())),
}
} else {
let collector = TopDocs::with_limit(limit);
let collector = TopDocs::with_limit(limit).and_offset(offset);
let top_docs_handle = multicollector.add_collector(collector);
let ret = self.inner.search(&query.inner, &multicollector);