mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-01-06 17:22:54 +00:00
Cargo fmt
This commit is contained in:
@@ -1,22 +1,21 @@
|
||||
mod term_query;
|
||||
mod term_weight;
|
||||
mod term_scorer;
|
||||
mod term_weight;
|
||||
|
||||
pub use self::term_query::TermQuery;
|
||||
pub use self::term_weight::TermWeight;
|
||||
pub use self::term_scorer::TermScorer;
|
||||
pub use self::term_weight::TermWeight;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use docset::DocSet;
|
||||
use Index;
|
||||
use tests::assert_nearly_equals;
|
||||
use Term;
|
||||
use schema::{TEXT, STRING, SchemaBuilder, IndexRecordOption};
|
||||
use collector::TopCollector;
|
||||
use query::{TermQuery, QueryParser, Query, Scorer};
|
||||
|
||||
use docset::DocSet;
|
||||
use query::{Query, QueryParser, Scorer, TermQuery};
|
||||
use schema::{IndexRecordOption, SchemaBuilder, STRING, TEXT};
|
||||
use tests::assert_nearly_equals;
|
||||
use Index;
|
||||
use Term;
|
||||
|
||||
#[test]
|
||||
pub fn test_term_query_no_freq() {
|
||||
@@ -48,7 +47,6 @@ mod tests {
|
||||
assert_eq!(term_scorer.score(), 0.28768212);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
pub fn test_term_weight() {
|
||||
let mut schema_builder = SchemaBuilder::new();
|
||||
@@ -66,7 +64,6 @@ mod tests {
|
||||
));
|
||||
index_writer.add_document(doc!(left_field => "left4 left1"));
|
||||
index_writer.commit().unwrap();
|
||||
|
||||
}
|
||||
index.load_searchers().unwrap();
|
||||
let searcher = index.searcher();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use Term;
|
||||
use Result;
|
||||
use super::term_weight::TermWeight;
|
||||
use query::bm25::BM25Weight;
|
||||
use query::Query;
|
||||
use query::Weight;
|
||||
use schema::IndexRecordOption;
|
||||
use Result;
|
||||
use Searcher;
|
||||
use query::bm25::BM25Weight;
|
||||
use Term;
|
||||
|
||||
/// A Term query matches all of the documents
|
||||
/// containing a specific term.
|
||||
@@ -44,11 +44,7 @@ impl TermQuery {
|
||||
} else {
|
||||
IndexRecordOption::Basic
|
||||
};
|
||||
TermWeight::new(
|
||||
self.term.clone(),
|
||||
index_record_option,
|
||||
bm25_weight
|
||||
)
|
||||
TermWeight::new(self.term.clone(), index_record_option, bm25_weight)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,4 +53,3 @@ impl Query for TermQuery {
|
||||
Ok(Box::new(self.specialized_weight(searcher, scoring_enabled)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use Score;
|
||||
use DocId;
|
||||
use docset::{DocSet, SkipResult};
|
||||
use query::Scorer;
|
||||
use DocId;
|
||||
use Score;
|
||||
|
||||
use postings::Postings;
|
||||
use fieldnorm::FieldNormReader;
|
||||
use query::bm25::BM25Weight;
|
||||
use postings::Postings;
|
||||
use postings::SegmentPostings;
|
||||
use query::bm25::BM25Weight;
|
||||
|
||||
pub struct TermScorer {
|
||||
postings: SegmentPostings,
|
||||
@@ -14,11 +14,12 @@ pub struct TermScorer {
|
||||
similarity_weight: BM25Weight,
|
||||
}
|
||||
|
||||
|
||||
impl TermScorer {
|
||||
pub fn new(postings: SegmentPostings,
|
||||
fieldnorm_reader: FieldNormReader,
|
||||
similarity_weight: BM25Weight) -> TermScorer {
|
||||
pub fn new(
|
||||
postings: SegmentPostings,
|
||||
fieldnorm_reader: FieldNormReader,
|
||||
similarity_weight: BM25Weight,
|
||||
) -> TermScorer {
|
||||
TermScorer {
|
||||
postings,
|
||||
fieldnorm_reader,
|
||||
@@ -49,7 +50,7 @@ impl Scorer for TermScorer {
|
||||
fn score(&mut self) -> Score {
|
||||
let doc = self.doc();
|
||||
let fieldnorm_id = self.fieldnorm_reader.fieldnorm_id(doc);
|
||||
self.similarity_weight.score(fieldnorm_id, self.postings.term_freq())
|
||||
self.similarity_weight
|
||||
.score(fieldnorm_id, self.postings.term_freq())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use Term;
|
||||
use query::Weight;
|
||||
use super::term_scorer::TermScorer;
|
||||
use core::SegmentReader;
|
||||
use query::Scorer;
|
||||
use docset::DocSet;
|
||||
use postings::SegmentPostings;
|
||||
use schema::IndexRecordOption;
|
||||
use super::term_scorer::TermScorer;
|
||||
use Result;
|
||||
use query::bm25::BM25Weight;
|
||||
use query::Scorer;
|
||||
use query::Weight;
|
||||
use schema::IndexRecordOption;
|
||||
use Result;
|
||||
use Term;
|
||||
|
||||
pub struct TermWeight {
|
||||
term: Term,
|
||||
@@ -16,24 +16,26 @@ pub struct TermWeight {
|
||||
}
|
||||
|
||||
impl Weight for TermWeight {
|
||||
|
||||
fn scorer(&self, reader: &SegmentReader) -> Result<Box<Scorer>> {
|
||||
let field = self.term.field();
|
||||
let inverted_index = reader.inverted_index(field);
|
||||
let fieldnorm_reader = reader.get_fieldnorms_reader(field);
|
||||
let similarity_weight = self.similarity_weight.clone();
|
||||
let postings_opt: Option<SegmentPostings> =
|
||||
inverted_index.read_postings(&self.term, self.index_record_option);
|
||||
if let Some(segment_postings) = postings_opt {
|
||||
Ok(Box::new(TermScorer::new(segment_postings,
|
||||
fieldnorm_reader,
|
||||
similarity_weight)))
|
||||
} else {
|
||||
Ok(Box::new(TermScorer::new(
|
||||
SegmentPostings::empty(),
|
||||
fieldnorm_reader,
|
||||
similarity_weight)))
|
||||
}
|
||||
let postings_opt: Option<SegmentPostings> =
|
||||
inverted_index.read_postings(&self.term, self.index_record_option);
|
||||
if let Some(segment_postings) = postings_opt {
|
||||
Ok(Box::new(TermScorer::new(
|
||||
segment_postings,
|
||||
fieldnorm_reader,
|
||||
similarity_weight,
|
||||
)))
|
||||
} else {
|
||||
Ok(Box::new(TermScorer::new(
|
||||
SegmentPostings::empty(),
|
||||
fieldnorm_reader,
|
||||
similarity_weight,
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
fn count(&self, reader: &SegmentReader) -> Result<u32> {
|
||||
@@ -50,12 +52,12 @@ impl Weight for TermWeight {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl TermWeight {
|
||||
|
||||
pub fn new(term: Term,
|
||||
index_record_option: IndexRecordOption,
|
||||
similarity_weight: BM25Weight) -> TermWeight {
|
||||
pub fn new(
|
||||
term: Term,
|
||||
index_record_option: IndexRecordOption,
|
||||
similarity_weight: BM25Weight,
|
||||
) -> TermWeight {
|
||||
TermWeight {
|
||||
term,
|
||||
index_record_option,
|
||||
@@ -63,4 +65,3 @@ impl TermWeight {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user