Commit d0a33834 authored by Emmanuel Raviart's avatar Emmanuel Raviart
Browse files

Add offset to queries (and rename count to "limit").

parent 5390ddfd
......@@ -53,13 +53,15 @@ struct ListResponse {
#[derive(Debug, Deserialize, Extract)]
struct SearchQuery {
#[serde(default = "limit_default")]
limit: usize,
#[serde(default)]
q: String,
#[serde(default = "count_default")]
count: usize,
#[serde(default)]
offset: usize,
}
fn count_default() -> usize {
fn limit_default() -> usize {
10
}
......@@ -79,7 +81,7 @@ impl_web!{
let searcher = self.index.searcher();
let mut count_collector = CountCollector::default();
let mut top_collector = TopCollector::with_limit(query_string.count);
let mut top_collector = TopCollector::with_limit(query_string.offset + query_string.limit);
{
let mut chained_collector = collector::chain()
.push(&mut top_collector)
......@@ -90,6 +92,7 @@ impl_web!{
top_collector
.docs()
.iter()
.skip(query_string.offset)
.map(|doc_address| {
let doc: Document = searcher.doc(*doc_address).unwrap();
self.create_hit(&doc, doc_address)
......@@ -116,7 +119,7 @@ impl_web!{
};
let searcher = self.index.searcher();
let mut count_collector = CountCollector::default();
let mut top_collector = TopCollector::with_limit(query_string.count);
let mut top_collector = TopCollector::with_limit(query_string.offset + query_string.limit);
{
let mut chained_collector = collector::chain()
.push(&mut top_collector)
......@@ -127,6 +130,7 @@ impl_web!{
top_collector
.docs()
.iter()
.skip(query_string.offset)
.map(|doc_address| {
let doc: Document = searcher.doc(*doc_address).unwrap();
self.create_hit(&doc, doc_address)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment