From 89e1cabc58fdde98b30cae4aebf363667efd762e Mon Sep 17 00:00:00 2001 From: sourcepirate Date: Sat, 5 Sep 2020 23:51:54 +0800 Subject: [PATCH] support for offset to do record pagination --- Cargo.toml | 2 +- src/searcher.rs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a9179b2..44f7e17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/searcher.rs b/src/searcher.rs index f2ba1d3..6ea2952 100644 --- a/src/searcher.rs +++ b/src/searcher.rs @@ -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 { @@ -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);