Skip to content

Commit

Permalink
Removed fieldnorms from the TermScorer
Browse files Browse the repository at this point in the history
  • Loading branch information
fulmicoton committed Dec 10, 2021
1 parent 241f051 commit db2392e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
5 changes: 0 additions & 5 deletions src/query/term_query/term_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ impl TermQuery {
let error_msg = format!("Field {:?} is not indexed.", field_entry.name());
return Err(crate::TantivyError::SchemaError(error_msg));
}
let has_fieldnorms = searcher
.schema()
.get_field_entry(self.term.field())
.has_fieldnorms();
let bm25_weight = if scoring_enabled {
Bm25Weight::for_terms(searcher, &[term])?
} else {
Expand All @@ -116,7 +112,6 @@ impl TermQuery {
self.term.clone(),
index_record_option,
bm25_weight,
has_fieldnorms,
scoring_enabled,
))
}
Expand Down
11 changes: 5 additions & 6 deletions src/query/term_query/term_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub struct TermWeight {
index_record_option: IndexRecordOption,
similarity_weight: Bm25Weight,
scoring_enabled: bool,
has_fieldnorms: bool,
}

impl Weight for TermWeight {
Expand Down Expand Up @@ -91,14 +90,12 @@ impl TermWeight {
index_record_option: IndexRecordOption,
similarity_weight: Bm25Weight,
scoring_enabled: bool,
has_fieldnorms: bool,
) -> TermWeight {
TermWeight {
term,
index_record_option,
similarity_weight,
scoring_enabled,
has_fieldnorms,
}
}

Expand All @@ -109,11 +106,13 @@ impl TermWeight {
) -> crate::Result<TermScorer> {
let field = self.term.field();
let inverted_index = reader.inverted_index(field)?;
let fieldnorm_reader = if self.scoring_enabled && self.has_fieldnorms {
reader.get_fieldnorms_reader(field)?
let fieldnorm_reader_opt = if self.scoring_enabled {
reader.fieldnorms_readers().get_field(field)?
} else {
FieldNormReader::constant(reader.max_doc(), 1)
None
};
let fieldnorm_reader =
fieldnorm_reader_opt.unwrap_or_else(|| FieldNormReader::constant(reader.max_doc(), 1));
let similarity_weight = self.similarity_weight.boost_by(boost);
let postings_opt: Option<SegmentPostings> =
inverted_index.read_postings(&self.term, self.index_record_option)?;
Expand Down

0 comments on commit db2392e

Please sign in to comment.