Skip to content

Commit

Permalink
issue/50 going on
Browse files Browse the repository at this point in the history
  • Loading branch information
fulmicoton committed Oct 30, 2016
1 parent 893932d commit 7421e0a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/query/daat_multiterm_scorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ impl<TPostings: Postings, TAccumulator: MultiTermAccumulator> DAATMultiTermScore
/// # Panics
/// This method will panic if the head `SegmentPostings` is not empty.
fn advance_head(&mut self,) {

{
let mut mutable_head = self.queue.peek_mut().unwrap();
let cur_postings = &mut self.postings[mutable_head.ord as usize];
Expand Down
2 changes: 1 addition & 1 deletion src/query/multi_term_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ struct MultiTermWeight {

impl Weight for MultiTermWeight {


fn scorer<'a>(&'a self, reader: &'a SegmentReader) -> Result<Box<Scorer + 'a>> {


let mut postings_and_fieldnorms = Vec::with_capacity(self.query.num_terms());
{
for &(occur, ref term) in &self.query.occur_terms {
Expand Down
1 change: 1 addition & 0 deletions src/query/scorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ pub trait Scorer: DocSet {
}
}
}

4 changes: 3 additions & 1 deletion src/query/term_query/term_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ impl Query for TermQuery {
self
}

fn weight(&self, _searcher: &Searcher) -> Result<Box<Weight>> {
fn weight(&self, searcher: &Searcher) -> Result<Box<Weight>> {
let doc_freq = searcher.doc_freq(&self.term);
Ok(box TermWeight {
doc_freq: doc_freq,
term: self.term.clone()
})
}
Expand Down
6 changes: 5 additions & 1 deletion src/query/term_query/term_scorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use postings::SegmentPostings;
use fastfield::U32FastFieldReader;
use postings::DocSet;
use query::Scorer;
use postings::Postings;

pub struct TermScorer<'a> {
pub idf: Score,
pub fieldnorm_reader: U32FastFieldReader,
pub segment_postings: SegmentPostings<'a>,
}
Expand All @@ -23,6 +25,8 @@ impl<'a> DocSet for TermScorer<'a> {

impl<'a> Scorer for TermScorer<'a> {
fn score(&self,) -> Score {
1.0
let doc = self.segment_postings.doc();
let field_norm = self.fieldnorm_reader.get(doc);
self.idf * (self.segment_postings.term_freq() as f32 / field_norm as f32).sqrt()
}
}
5 changes: 4 additions & 1 deletion src/query/term_query/term_weight.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use Term;
use Score;
use query::Weight;
use core::SegmentReader;
use query::Scorer;
Expand All @@ -8,7 +9,8 @@ use super::term_scorer::TermScorer;
use Result;

pub struct TermWeight {
pub term: Term
pub doc_freq: u32,
pub term: Term,
}


Expand All @@ -19,6 +21,7 @@ impl Weight for TermWeight {
let fieldnorm_reader = try!(reader.get_fieldnorms_reader(field));
if let Some(segment_postings) = reader.read_postings(&self.term, SegmentPostingsOption::Freq) {
let scorer: TermScorer = TermScorer {
idf: 1f32 / (self.doc_freq as f32),
fieldnorm_reader: fieldnorm_reader,
segment_postings: segment_postings,
};
Expand Down

0 comments on commit 7421e0a

Please sign in to comment.