Compare commits

...

8 Commits

Author SHA1 Message Date
Paul Masurel
4d08713c73 Update CHANGELOG with date range queries 2021-04-19 09:33:56 +09:00
Paul Masurel
570c4fdbb1 Cargo check 2021-04-19 08:54:28 +09:00
Paul Masurel
00506594b9 Removing TermMerger::next().
Closing #933
2021-04-19 08:54:28 +09:00
Paul Masurel
3313fd39fc Edited CHANGELOG 2021-04-19 08:54:28 +09:00
Hardik Prajapati
9dd8c268bd Simplified chain orderings 2021-04-19 08:54:28 +09:00
Hardik Prajapati
942cbfb383 Fixed formatting using cargo fmt 2021-04-19 08:54:28 +09:00
Hardik Prajapati
5d1627e52d Implementation of Ord trait changed for Hit
- This will result in lexicographical ordering of facet in BinaryHeep in case of a tie
2021-04-19 08:54:28 +09:00
Hardik Prajapati
84cad5c1aa AAdded failing test for tie scenario in topk 2021-04-19 08:54:28 +09:00
4 changed files with 43 additions and 15 deletions

View File

@@ -3,9 +3,10 @@ Tantivy 0.15.0
- API Changes. Using Range instead of (start, end) in the API and internals (`FileSlice`, `OwnedBytes`, `Snippets`, ...)
This change is breaking but migration is trivial.
- Added an Histogram collector. (@fulmicoton) #994
- Added support for Option<TCollector>. (@fulmicoton)
- Added support for Option<TCollector>. (@fulmicoton)
- DocAddress is now a struct (@scampi) #987
- Bugfix consistent tie break handling in facet's topk (@hardikpnsp) #357
- Date field support for range queries (@rihardsk) #516
Tantivy 0.14.0
=========================

View File

@@ -37,7 +37,10 @@ impl<'a> PartialOrd<Hit<'a>> for Hit<'a> {
impl<'a> Ord for Hit<'a> {
fn cmp(&self, other: &Self) -> Ordering {
other.count.cmp(&self.count)
other
.count
.cmp(&self.count)
.then(self.facet.cmp(other.facet))
}
}
@@ -657,6 +660,41 @@ mod tests {
);
}
}
#[test]
fn test_facet_collector_topk_tie_break() -> crate::Result<()> {
let mut schema_builder = Schema::builder();
let facet_field = schema_builder.add_facet_field("facet", INDEXED);
let schema = schema_builder.build();
let index = Index::create_in_ram(schema);
let docs: Vec<Document> = vec![("b", 2), ("a", 2), ("c", 4)]
.into_iter()
.flat_map(|(c, count)| {
let facet = Facet::from(&format!("/facet/{}", c));
let doc = doc!(facet_field => facet);
iter::repeat(doc).take(count)
})
.collect();
let mut index_writer = index.writer_for_tests()?;
for doc in docs {
index_writer.add_document(doc);
}
index_writer.commit()?;
let searcher = index.reader()?.searcher();
let mut facet_collector = FacetCollector::for_field(facet_field);
facet_collector.add_facet("/facet");
let counts: FacetCounts = searcher.search(&AllQuery, &facet_collector)?;
let facets: Vec<(&Facet, u64)> = counts.top_k("/facet", 2);
assert_eq!(
facets,
vec![(&Facet::from("/facet/c"), 4), (&Facet::from("/facet/a"), 2)]
);
Ok(())
}
}
#[cfg(all(test, feature = "unstable"))]

View File

@@ -170,7 +170,7 @@ pub fn merge_segments<Dir: Directory>(
if indices
.iter()
.skip(1)
.any(|index| &index.schema() != &target_schema)
.any(|index| index.schema() != target_schema)
{
return Err(crate::TantivyError::InvalidArgument(
"Attempt to merge different schema indices".to_string(),

View File

@@ -1,4 +1,3 @@
use crate::schema::Term;
use crate::termdict::TermOrdinal;
use crate::termdict::TermStreamer;
use std::cmp::Ordering;
@@ -114,14 +113,4 @@ impl<'a> TermMerger<'a> {
pub fn current_kvs(&self) -> &[HeapItem<'a>] {
&self.current_streamers[..]
}
/// Iterates through terms
#[cfg_attr(feature = "cargo-clippy", allow(clippy::should_implement_trait))]
pub fn next(&mut self) -> Option<Term<&[u8]>> {
if self.advance() {
Some(Term::wrap(self.current_streamers[0].streamer.key()))
} else {
None
}
}
}