summaryrefslogtreecommitdiffstats
path: root/src/query/scorer.rs
diff options
context:
space:
mode:
authorPaul Masurel <paul.masurel@gmail.com>2016-11-02 12:54:06 +0900
committerPaul Masurel <paul.masurel@gmail.com>2016-11-02 17:58:20 +0900
commit6229a927308499e9af2a5ca96ca896cf327538d1 (patch)
treea33c8e3126159cc195a28a00cca95a8bca3cfa2d /src/query/scorer.rs
parentc2c65d311d2e05570defe3860e82b28605680133 (diff)
issue/50 Removed SegmentPostingsTestFactory for just using VecPostings
Diffstat (limited to 'src/query/scorer.rs')
-rw-r--r--src/query/scorer.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/query/scorer.rs b/src/query/scorer.rs
index 32ed4b4..7513705 100644
--- a/src/query/scorer.rs
+++ b/src/query/scorer.rs
@@ -1,7 +1,10 @@
use DocSet;
use collector::Collector;
+use std::ops::{Deref, DerefMut};
-/// Scored `DocSet`
+/// Scored set of documents matching a query within a specific segment.
+///
+/// See [Query](./trait.Query.html).
pub trait Scorer: DocSet {
/// Returns the score.
@@ -9,6 +12,8 @@ pub trait Scorer: DocSet {
/// This method will perform a bit of computation and is not cached.
fn score(&self,) -> f32;
+ /// Consumes the complete `DocSet` and
+ /// push the scored documents to the collector.
fn collect(&mut self, collector: &mut Collector) {
while self.advance() {
collector.collect(self.doc(), self.score());
@@ -16,3 +21,16 @@ pub trait Scorer: DocSet {
}
}
+
+impl<'a> Scorer for Box<Scorer + 'a> {
+ fn score(&self,) -> f32 {
+ self.deref().score()
+ }
+
+ fn collect(&mut self, collector: &mut Collector) {
+ let scorer = self.deref_mut();
+ while scorer.advance() {
+ collector.collect(scorer.doc(), scorer.score());
+ }
+ }
+} \ No newline at end of file