Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No score calls if score is not requested #1646

Merged
merged 4 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Tantivy 0.19
================================

- Skip score calculation, when no scoring is required [#1646](https://github.com/quickwit-oss/tantivy/pull/1646) (@PSeitz)
- Limit fast fields to u32 (`get_val(u32)`) [#1644](https://github.com/quickwit-oss/tantivy/pull/1644) (@PSeitz)
- Major bugfix: Fix missing fieldnorms for u64, i64, f64, bool, bytes and date [#1620](https://github.com/quickwit-oss/tantivy/pull/1620) (@PSeitz)
- Updated [Date Field Type](https://github.com/quickwit-oss/tantivy/pull/1396)
Expand Down
4 changes: 2 additions & 2 deletions src/collector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ pub trait Collector: Sync + Send {
let mut segment_collector = self.for_segment(segment_ord as u32, reader)?;

if let Some(alive_bitset) = reader.alive_bitset() {
weight.for_each(reader, &mut |doc, score| {
weight.for_each(reader, self.requires_scoring(), &mut |doc, score| {
if alive_bitset.is_alive(doc) {
segment_collector.collect(doc, score);
}
})?;
} else {
weight.for_each(reader, &mut |doc, score| {
weight.for_each(reader, self.requires_scoring(), &mut |doc, score| {
segment_collector.collect(doc, score);
})?;
}
Expand Down
10 changes: 6 additions & 4 deletions src/indexer/index_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,16 @@ fn compute_deleted_bitset(

// A delete operation should only affect
// document that were inserted before it.
delete_op
.target
.for_each(segment_reader, &mut |doc_matching_delete_query, _| {
delete_op.target.for_each(
segment_reader,
false, // requires_scoring
&mut |doc_matching_delete_query, _| {
if doc_opstamps.is_deleted(doc_matching_delete_query, delete_op.opstamp) {
alive_bitset.remove(doc_matching_delete_query);
might_have_changed = true;
}
})?;
},
)?;
delete_cursor.advance();
}
Ok(might_have_changed)
Expand Down
5 changes: 3 additions & 2 deletions src/query/boolean_query/boolean_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,17 @@ impl<TScoreCombiner: ScoreCombiner + Sync> Weight for BooleanWeight<TScoreCombin
fn for_each(
&self,
reader: &SegmentReader,
requires_scoring: bool,
callback: &mut dyn FnMut(DocId, Score),
) -> crate::Result<()> {
let scorer = self.complex_scorer(reader, 1.0, &self.score_combiner_fn)?;
match scorer {
SpecializedScorer::TermUnion(term_scorers) => {
let mut union_scorer = Union::build(term_scorers, &self.score_combiner_fn);
for_each_scorer(&mut union_scorer, callback);
for_each_scorer(&mut union_scorer, requires_scoring, callback);
}
SpecializedScorer::Other(mut scorer) => {
for_each_scorer(scorer.as_mut(), callback);
for_each_scorer(scorer.as_mut(), requires_scoring, callback);
}
}
Ok(())
Expand Down
3 changes: 2 additions & 1 deletion src/query/term_query/term_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ impl Weight for TermWeight {
fn for_each(
&self,
reader: &SegmentReader,
requires_scoring: bool,
callback: &mut dyn FnMut(DocId, Score),
) -> crate::Result<()> {
let mut scorer = self.specialized_scorer(reader, 1.0)?;
for_each_scorer(&mut scorer, callback);
for_each_scorer(&mut scorer, requires_scoring, callback);
Ok(())
}

Expand Down
18 changes: 14 additions & 4 deletions src/query/weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@ use crate::{DocId, Score, TERMINATED};
/// `DocSet` and push the scored documents to the collector.
pub(crate) fn for_each_scorer<TScorer: Scorer + ?Sized>(
scorer: &mut TScorer,
requires_scoring: bool,
Copy link
Collaborator

@fulmicoton fulmicoton Oct 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not add this parameter to this function and instead create a separate function:

pub(crate) fn for_each_docset<TDocSet: DocSet + ?Sized>(
    docset: &mut TDocset,
    callback: &mut dyn FnMut(DocId)
) -> { ... }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the PR, but it still adds a fake score when collect()ing

callback: &mut dyn FnMut(DocId, Score),
) {
let mut doc = scorer.doc();
while doc != TERMINATED {
callback(doc, scorer.score());
doc = scorer.advance();

if requires_scoring {
while doc != TERMINATED {
callback(doc, scorer.score());
doc = scorer.advance();
}
} else {
while doc != TERMINATED {
callback(doc, 0.0);
doc = scorer.advance();
}
}
}

Expand Down Expand Up @@ -71,10 +80,11 @@ pub trait Weight: Send + Sync + 'static {
fn for_each(
&self,
reader: &SegmentReader,
requires_scoring: bool,
callback: &mut dyn FnMut(DocId, Score),
) -> crate::Result<()> {
let mut scorer = self.scorer(reader, 1.0)?;
for_each_scorer(scorer.as_mut(), callback);
for_each_scorer(scorer.as_mut(), requires_scoring, callback);
Ok(())
}

Expand Down