web search done right
make sure that all ranking signals are returned even if their score/coefficient is zero
Mikkel Denkere7bc911fb345
diff --git a/crates/core/src/ranking/initial.rs b/crates/core/src/ranking/initial.rsindex e0aca051..a32dbf38 100644--- a/crates/core/src/ranking/initial.rs+++ b/crates/core/src/ranking/initial.rs@@ -81,7 +81,6 @@ impl ScoreSegmentTweaker<Score> for InitialSegmentScoreTweaker {let mut total = self.computer.compute_signals(doc)- .flatten().map(|computed| self.computer.coefficient(&computed.signal) * computed.score).sum();diff --git a/crates/core/src/ranking/pipeline/stages/recall.rs b/crates/core/src/ranking/pipeline/stages/recall.rsindex fb2d2fb0..d7ce249e 100644--- a/crates/core/src/ranking/pipeline/stages/recall.rs+++ b/crates/core/src/ranking/pipeline/stages/recall.rs@@ -185,7 +185,7 @@ impl LocalRecallRankingWebpage {host_id,};- for computed_signal in computer.compute_signals(pointer.address.doc_id).flatten() {+ for computed_signal in computer.compute_signals(pointer.address.doc_id) {res.signals.insert(computed_signal.signal, computed_signal.score);}diff --git a/crates/core/src/ranking/signal/computer/mod.rs b/crates/core/src/ranking/signal/computer/mod.rsindex 9a38fc04..d7a45308 100644--- a/crates/core/src/ranking/signal/computer/mod.rs+++ b/crates/core/src/ranking/signal/computer/mod.rs@@ -390,12 +390,12 @@ impl SignalComputer {/// Computes the scored signals for a given document.///- /// Important: This function assues that the docs a scored in ascending order of docid+ /// Important: This function assumes that the docs a scored in ascending order of docid/// within their segment. If this invariant is not upheld, the documents will not have/// scores calculated for their text related signals. The wrong ranking will most likely/// be returned./// This function also assumes that the segment reader has been set.- pub fn compute_signals(&self, doc: DocId) -> impl Iterator<Item = Option<ComputedSignal>> + '_ {+ pub fn compute_signals(&self, doc: DocId) -> impl Iterator<Item = ComputedSignal> + '_ {self.order.compute(doc, self)}diff --git a/crates/core/src/ranking/signal/computer/order.rs b/crates/core/src/ranking/signal/computer/order.rsindex 6923fee1..ba4afbbd 100644--- a/crates/core/src/ranking/signal/computer/order.rs+++ b/crates/core/src/ranking/signal/computer/order.rs@@ -71,24 +71,29 @@ impl SignalComputeOrder {&'a self,doc: DocId,signal_computer: &'a SignalComputer,- ) -> impl Iterator<Item = Option<ComputedSignal>> + 'a {+ ) -> impl Iterator<Item = ComputedSignal> + 'a {self.text_signals.values().flat_map(move |ngram| ngram.compute(doc, signal_computer))- .map(Some)- .chain(- self.other_signals- .iter()- .filter(|signal| signal_computer.coefficient(signal) > 0.0)- .map(move |signal| {- signal- .compute(doc, signal_computer)- .map(|score| ComputedSignal {- signal: *signal,- score,- })- }),- )+ .chain(self.other_signals.iter().map(move |signal| {+ if signal_computer.coefficient(signal) == 0.0 {+ return ComputedSignal {+ signal: *signal,+ score: 0.0,+ };+ }++ signal+ .compute(doc, signal_computer)+ .map(|score| ComputedSignal {+ signal: *signal,+ score,+ })+ .unwrap_or_else(|| ComputedSignal {+ signal: *signal,+ score: 0.0,+ })+ }))}}@@ -118,25 +123,26 @@ impl NGramComputeOrder {) -> impl Iterator<Item = ComputedSignal> + 'a {let mut hits = 0;- self.signals- .iter()- .map(|(_, s)| s)- .filter_map(move |signal| {- signal- .compute(doc, signal_computer)- .map(|score| ComputedSignal {- signal: *signal,- score,- })- .map(|mut c| {- c.score *= NGRAM_DAMPENING.powi(hits);-- if c.score > 0.0 {- hits += 1;- }-- c- })- })+ self.signals.iter().map(|(_, s)| s).map(move |signal| {+ signal+ .compute(doc, signal_computer)+ .map(|score| ComputedSignal {+ signal: *signal,+ score,+ })+ .map(|mut c| {+ c.score *= NGRAM_DAMPENING.powi(hits);++ if c.score > 0.0 {+ hits += 1;+ }++ c+ })+ .unwrap_or_else(|| ComputedSignal {+ signal: *signal,+ score: 0.0,+ })+ })}}