mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-01-06 01:02:55 +00:00
Compare commits
2 Commits
quickwit-r
...
0.22.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ef142ece3 | ||
|
|
8791660ef5 |
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tantivy"
|
name = "tantivy"
|
||||||
version = "0.22.0"
|
version = "0.22.1"
|
||||||
authors = ["Paul Masurel <paul.masurel@gmail.com>"]
|
authors = ["Paul Masurel <paul.masurel@gmail.com>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
categories = ["database-implementations", "data-structures"]
|
categories = ["database-implementations", "data-structures"]
|
||||||
|
|||||||
@@ -787,7 +787,7 @@ impl<Score, D, const R: bool> From<TopNComputerDeser<Score, D, R>> for TopNCompu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Score, D, const R: bool> TopNComputer<Score, D, R>
|
impl<Score, D, const REVERSE_ORDER: bool> TopNComputer<Score, D, REVERSE_ORDER>
|
||||||
where
|
where
|
||||||
Score: PartialOrd + Clone,
|
Score: PartialOrd + Clone,
|
||||||
D: Serialize + DeserializeOwned + Ord + Clone,
|
D: Serialize + DeserializeOwned + Ord + Clone,
|
||||||
@@ -808,7 +808,10 @@ where
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn push(&mut self, feature: Score, doc: D) {
|
pub fn push(&mut self, feature: Score, doc: D) {
|
||||||
if let Some(last_median) = self.threshold.clone() {
|
if let Some(last_median) = self.threshold.clone() {
|
||||||
if feature < last_median {
|
if !REVERSE_ORDER && feature > last_median {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if REVERSE_ORDER && feature < last_median {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -843,7 +846,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the top n elements in sorted order.
|
/// Returns the top n elements in sorted order.
|
||||||
pub fn into_sorted_vec(mut self) -> Vec<ComparableDoc<Score, D, R>> {
|
pub fn into_sorted_vec(mut self) -> Vec<ComparableDoc<Score, D, REVERSE_ORDER>> {
|
||||||
if self.buffer.len() > self.top_n {
|
if self.buffer.len() > self.top_n {
|
||||||
self.truncate_top_n();
|
self.truncate_top_n();
|
||||||
}
|
}
|
||||||
@@ -854,7 +857,7 @@ where
|
|||||||
/// Returns the top n elements in stored order.
|
/// Returns the top n elements in stored order.
|
||||||
/// Useful if you do not need the elements in sorted order,
|
/// Useful if you do not need the elements in sorted order,
|
||||||
/// for example when merging the results of multiple segments.
|
/// for example when merging the results of multiple segments.
|
||||||
pub fn into_vec(mut self) -> Vec<ComparableDoc<Score, D, R>> {
|
pub fn into_vec(mut self) -> Vec<ComparableDoc<Score, D, REVERSE_ORDER>> {
|
||||||
if self.buffer.len() > self.top_n {
|
if self.buffer.len() > self.top_n {
|
||||||
self.truncate_top_n();
|
self.truncate_top_n();
|
||||||
}
|
}
|
||||||
@@ -864,9 +867,11 @@ where
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use proptest::prelude::*;
|
||||||
|
|
||||||
use super::{TopDocs, TopNComputer};
|
use super::{TopDocs, TopNComputer};
|
||||||
use crate::collector::top_collector::ComparableDoc;
|
use crate::collector::top_collector::ComparableDoc;
|
||||||
use crate::collector::Collector;
|
use crate::collector::{Collector, DocSetCollector};
|
||||||
use crate::query::{AllQuery, Query, QueryParser};
|
use crate::query::{AllQuery, Query, QueryParser};
|
||||||
use crate::schema::{Field, Schema, FAST, STORED, TEXT};
|
use crate::schema::{Field, Schema, FAST, STORED, TEXT};
|
||||||
use crate::time::format_description::well_known::Rfc3339;
|
use crate::time::format_description::well_known::Rfc3339;
|
||||||
@@ -958,6 +963,44 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proptest! {
|
||||||
|
#[test]
|
||||||
|
fn test_topn_computer_asc_prop(
|
||||||
|
limit in 0..10_usize,
|
||||||
|
docs in proptest::collection::vec((0..100_u64, 0..100_u64), 0..100_usize),
|
||||||
|
) {
|
||||||
|
let mut computer: TopNComputer<_, _, false> = TopNComputer::new(limit);
|
||||||
|
for (feature, doc) in &docs {
|
||||||
|
computer.push(*feature, *doc);
|
||||||
|
}
|
||||||
|
let mut comparable_docs = docs.into_iter().map(|(feature, doc)| ComparableDoc { feature, doc }).collect::<Vec<_>>();
|
||||||
|
comparable_docs.sort();
|
||||||
|
comparable_docs.truncate(limit);
|
||||||
|
prop_assert_eq!(
|
||||||
|
computer.into_sorted_vec(),
|
||||||
|
comparable_docs,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_topn_computer_desc_prop(
|
||||||
|
limit in 0..10_usize,
|
||||||
|
docs in proptest::collection::vec((0..100_u64, 0..100_u64), 0..100_usize),
|
||||||
|
) {
|
||||||
|
let mut computer: TopNComputer<_, _, true> = TopNComputer::new(limit);
|
||||||
|
for (feature, doc) in &docs {
|
||||||
|
computer.push(*feature, *doc);
|
||||||
|
}
|
||||||
|
let mut comparable_docs = docs.into_iter().map(|(feature, doc)| ComparableDoc { feature, doc }).collect::<Vec<_>>();
|
||||||
|
comparable_docs.sort();
|
||||||
|
comparable_docs.truncate(limit);
|
||||||
|
prop_assert_eq!(
|
||||||
|
computer.into_sorted_vec(),
|
||||||
|
comparable_docs,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_top_collector_not_at_capacity_without_offset() -> crate::Result<()> {
|
fn test_top_collector_not_at_capacity_without_offset() -> crate::Result<()> {
|
||||||
let index = make_index()?;
|
let index = make_index()?;
|
||||||
@@ -1371,4 +1414,29 @@ mod tests {
|
|||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_topn_computer_asc() {
|
||||||
|
let mut computer: TopNComputer<u32, u32, false> = TopNComputer::new(2);
|
||||||
|
|
||||||
|
computer.push(1u32, 1u32);
|
||||||
|
computer.push(2u32, 2u32);
|
||||||
|
computer.push(3u32, 3u32);
|
||||||
|
computer.push(2u32, 4u32);
|
||||||
|
computer.push(4u32, 5u32);
|
||||||
|
computer.push(1u32, 6u32);
|
||||||
|
assert_eq!(
|
||||||
|
computer.into_sorted_vec(),
|
||||||
|
&[
|
||||||
|
ComparableDoc {
|
||||||
|
feature: 1u32,
|
||||||
|
doc: 1u32,
|
||||||
|
},
|
||||||
|
ComparableDoc {
|
||||||
|
feature: 1u32,
|
||||||
|
doc: 6u32,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user