use crate::rank::signals::{
authority_score, bm25_score, consensus_score, depth_score, diversity_score, evidence_score,
semantic_score, temporal_score, ScoringContext,
};
use crate::types::ResultItem;
use std::collections::HashMap;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum QueryIntent {
#[default]
Factual,
Informational,
HowTo,
Comparison,
Verification,
CurrentEvents,
DeepAnalysis,
Code,
Academic,
Opinion,
Data,
Casual,
}
#[derive(Debug, Clone)]
pub struct IntentWeights {
pub bm25: f64,
pub semantic: f64,
pub temporal: f64,
pub authority: f64,
pub evidence: f64,
pub diversity: f64,
pub depth: f64,
pub consensus: f64,
}
impl IntentWeights {
pub fn for_intent(intent: QueryIntent) -> Self {
match intent {
QueryIntent::Factual => Self {
bm25: 0.30,
semantic: 0.15,
temporal: 0.05,
authority: 0.10,
evidence: 0.15,
diversity: 0.05,
depth: 0.05,
consensus: 0.15,
},
QueryIntent::Informational => Self {
bm25: 0.40,
semantic: 0.20,
temporal: 0.05,
authority: 0.03,
evidence: 0.10,
diversity: 0.07,
depth: 0.10,
consensus: 0.05,
},
QueryIntent::CurrentEvents => Self {
bm25: 0.15,
semantic: 0.10,
temporal: 0.30,
authority: 0.10,
evidence: 0.10,
diversity: 0.05,
depth: 0.05,
consensus: 0.15,
},
QueryIntent::Academic => Self {
bm25: 0.15,
semantic: 0.20,
temporal: 0.05,
authority: 0.25,
evidence: 0.15,
diversity: 0.05,
depth: 0.10,
consensus: 0.05,
},
QueryIntent::DeepAnalysis => Self {
bm25: 0.10,
semantic: 0.15,
temporal: 0.05,
authority: 0.10,
evidence: 0.10,
diversity: 0.10,
depth: 0.30,
consensus: 0.10,
},
QueryIntent::Code => Self {
bm25: 0.35,
semantic: 0.15,
temporal: 0.05,
authority: 0.05,
evidence: 0.05,
diversity: 0.10,
depth: 0.15,
consensus: 0.10,
},
QueryIntent::HowTo => Self {
bm25: 0.35,
semantic: 0.15,
temporal: 0.05,
authority: 0.05,
evidence: 0.10,
diversity: 0.10,
depth: 0.15,
consensus: 0.05,
},
QueryIntent::Comparison => Self {
bm25: 0.15,
semantic: 0.20,
temporal: 0.05,
authority: 0.15,
evidence: 0.15,
diversity: 0.15,
depth: 0.10,
consensus: 0.05,
},
QueryIntent::Opinion => Self {
bm25: 0.20,
semantic: 0.10,
temporal: 0.05,
authority: 0.10,
evidence: 0.10,
diversity: 0.15,
depth: 0.10,
consensus: 0.20,
},
QueryIntent::Casual => Self {
bm25: 0.35,
semantic: 0.15,
temporal: 0.05,
authority: 0.05,
evidence: 0.05,
diversity: 0.15,
depth: 0.05,
consensus: 0.15,
},
_ => Self {
bm25: 0.15,
semantic: 0.15,
temporal: 0.10,
authority: 0.15,
evidence: 0.10,
diversity: 0.10,
depth: 0.10,
consensus: 0.15,
},
}
}
pub fn with_overrides(mut self, overrides: &HashMap<String, f64>) -> Self {
for (signal, &val) in overrides {
let val = val.clamp(0.0, 1.0);
match signal.as_str() {
"bm25" => self.bm25 = val,
"semantic" => self.semantic = val,
"temporal" => self.temporal = val,
"authority" => self.authority = val,
"evidence" => self.evidence = val,
"diversity" => self.diversity = val,
"depth" => self.depth = val,
"consensus" => self.consensus = val,
_ => {}
}
}
self
}
pub fn sum(&self) -> f64 {
self.bm25
+ self.semantic
+ self.temporal
+ self.authority
+ self.evidence
+ self.diversity
+ self.depth
+ self.consensus
}
pub fn normalize(mut self) -> Self {
let s = self.sum();
if s > 0.0 {
self.bm25 /= s;
self.semantic /= s;
self.temporal /= s;
self.authority /= s;
self.evidence /= s;
self.diversity /= s;
self.depth /= s;
self.consensus /= s;
}
self
}
}
#[derive(Debug, Clone, Default)]
struct RawScores {
bm25: f64,
semantic: f64,
temporal: f64,
authority: f64,
evidence: f64,
diversity: f64,
depth: f64,
consensus: f64,
}
fn adjust_authority_for_intent(url: &str, base: f64, intent: QueryIntent) -> f64 {
if url.contains("github.com/") {
return match intent {
QueryIntent::Code => base, QueryIntent::Academic => base * 0.6, QueryIntent::DeepAnalysis => base * 0.7, QueryIntent::Casual => base * 0.2, _ => base * 0.45, };
}
if url.contains("wikipedia.org") {
let path_lower = url.to_lowercase();
let is_list_or_bio = path_lower.contains("list_of_")
|| path_lower.contains("(academic)")
|| path_lower.contains("(politician)")
|| path_lower.contains("(footballer)")
|| path_lower.contains("(singer)")
|| path_lower.contains("(actor)");
let list_penalty = if is_list_or_bio { 0.5 } else { 1.0 };
return match intent {
QueryIntent::CurrentEvents => base * 0.35 * list_penalty,
QueryIntent::Casual => base * 0.50 * list_penalty, QueryIntent::Factual | QueryIntent::Informational | QueryIntent::Verification => {
base * list_penalty
}
_ => base * 0.75 * list_penalty,
};
}
if url.contains("reddit.com") || url.contains("news.ycombinator.com") {
return match intent {
QueryIntent::Opinion => base, QueryIntent::Casual => base * 0.55, QueryIntent::Comparison => base * 0.85, QueryIntent::Code | QueryIntent::HowTo => base * 0.60, QueryIntent::Academic => base * 0.40, _ => base * 0.70,
};
}
if url.contains("youtube.com") || url.contains("youtu.be") {
return match intent {
QueryIntent::HowTo => base * 0.80, QueryIntent::Opinion => base * 0.85,
QueryIntent::Comparison => base * 0.50, QueryIntent::Code => base * 0.45, QueryIntent::Academic => base * 0.35,
QueryIntent::Casual => base * 0.90,
_ => base * 0.65,
};
}
if url.contains("arxiv.org/") {
return match intent {
QueryIntent::Academic | QueryIntent::Verification | QueryIntent::Data => base,
QueryIntent::Opinion | QueryIntent::Comparison => base * 0.45,
QueryIntent::Casual => base * 0.15, _ => base * 0.75,
};
}
base
}
pub fn hyperfusion_rank(
results: &mut [ResultItem],
query: &str,
intent: QueryIntent,
freshness_need: f64,
weight_overrides: &HashMap<String, f64>,
) {
if results.is_empty() {
return;
}
let weights = IntentWeights::for_intent(intent)
.with_overrides(weight_overrides)
.normalize();
let mut ctx = ScoringContext::new(query, results);
let mut raw: Vec<RawScores> = results
.iter()
.map(|r| {
let base_authority = authority_score(r);
RawScores {
bm25: bm25_score(r, &ctx),
semantic: semantic_score(r, &ctx),
temporal: temporal_score(r, freshness_need),
authority: adjust_authority_for_intent(&r.url, base_authority, intent),
evidence: evidence_score(r),
diversity: 0.0,
depth: depth_score(r),
consensus: consensus_score(r, &ctx),
}
})
.collect();
for (i, result) in results.iter().enumerate() {
raw[i].diversity = diversity_score(result, &mut ctx);
}
let normalized = min_max_normalize(raw);
let fusion_scores: Vec<f64> = normalized
.iter()
.map(|s| {
s.bm25 * weights.bm25
+ s.semantic * weights.semantic
+ s.temporal * weights.temporal
+ s.authority * weights.authority
+ s.evidence * weights.evidence
+ s.diversity * weights.diversity
+ s.depth * weights.depth
+ s.consensus * weights.consensus
})
.collect();
let fmin = fusion_scores.iter().cloned().fold(f64::INFINITY, f64::min);
let fmax = fusion_scores
.iter()
.cloned()
.fold(f64::NEG_INFINITY, f64::max);
let frange = fmax - fmin;
let spread_scores: Vec<f64> = if frange > 1e-9 {
fusion_scores
.iter()
.map(|&s| {
let normalized = (s - fmin) / frange; normalized.powf(0.6)
})
.collect()
} else {
fusion_scores.iter().map(|_| 0.5).collect()
};
for (i, result) in results.iter_mut().enumerate() {
result.score = Some(spread_scores[i]);
}
results.sort_by(|a, b| {
let sa = a.score.unwrap_or(0.0);
let sb = b.score.unwrap_or(0.0);
sb.partial_cmp(&sa)
.unwrap_or(std::cmp::Ordering::Equal)
.then_with(|| a.rank.cmp(&b.rank))
});
for (i, r) in results.iter_mut().enumerate() {
r.rank = (i + 1) as u32;
}
}
fn min_max_normalize(scores: Vec<RawScores>) -> Vec<RawScores> {
const EPSILON: f64 = 1e-9;
macro_rules! normalize_field {
($scores:expr, $field:ident) => {{
let min = $scores
.iter()
.map(|s| s.$field)
.fold(f64::INFINITY, f64::min);
let max = $scores
.iter()
.map(|s| s.$field)
.fold(f64::NEG_INFINITY, f64::max);
let range = max - min;
if range < EPSILON {
for s in $scores.iter_mut() {
s.$field = 0.5;
}
} else {
for s in $scores.iter_mut() {
s.$field = (s.$field - min) / range;
}
}
}};
}
let mut scores = scores;
normalize_field!(scores, bm25);
normalize_field!(scores, semantic);
normalize_field!(scores, temporal);
normalize_field!(scores, authority);
normalize_field!(scores, evidence);
normalize_field!(scores, diversity);
normalize_field!(scores, depth);
normalize_field!(scores, consensus);
scores
}
pub fn detect_intent(query: &str) -> QueryIntent {
let q = query.to_lowercase();
let is_language_learning = (q.contains("learn")
|| q.contains("learning")
|| q.contains("apprendre")
|| q.contains("aprender")
|| q.contains("lernen")
|| q.contains("study"))
&& (q.contains("french")
|| q.contains("français")
|| q.contains("francais")
|| q.contains("spanish")
|| q.contains("español")
|| q.contains("espanol")
|| q.contains("german")
|| q.contains("deutsch")
|| q.contains("italian")
|| q.contains("italiano"));
let has_health_signal = q.contains("diabetes")
|| q.contains("hypertension")
|| q.contains("blood pressure")
|| q.contains("medication")
|| q.contains("treatment")
|| q.contains("therapy")
|| q.contains("disease")
|| q.contains("symptom")
|| q.contains("diagnosis")
|| q.contains("vaccine")
|| q.contains("insulin")
|| q.contains("sleep apnea");
let has_guideline_signal = q.contains("guideline")
|| q.contains("guidelines")
|| q.contains("recommendation")
|| q.contains("recommendations")
|| q.contains("standards of care")
|| q.contains("clinical practice");
let has_recent_year = q.contains("2025") || q.contains("2026");
let has_news_signal = q.contains("today")
|| q.contains("latest")
|| q.contains("news")
|| q.contains("recent")
|| q.contains("this year")
|| q.contains("this month")
|| q.contains("this week")
|| q.contains("breaking")
|| q.contains("update")
|| q.contains("announcement")
|| q.contains("released")
|| q.contains("launched")
|| q.contains("new in ");
let is_technical_eval = q.contains("benchmark")
|| q.contains("performance")
|| q.contains("vs ")
|| q.contains(" vs")
|| q.contains("compare")
|| q.contains("runtime")
|| q.contains("framework")
|| q.contains("latency")
|| q.contains("throughput");
let is_preference_query = q.contains("best ")
|| q.starts_with("best ")
|| q.contains("top ")
|| q.contains("recommended")
|| q.contains("which is better")
|| q.contains("should i use")
|| q.contains("worth it")
|| q.contains("pros and cons");
let has_technical_signal = q.contains("protocol")
|| q.contains("architecture")
|| q.contains("docker")
|| q.contains("compose")
|| q.contains("container")
|| q.contains("containers")
|| q.contains("kubernetes")
|| q.contains("networking")
|| q.contains("hostname")
|| q.contains("dns")
|| q.contains("service name")
|| q.contains("http")
|| q.contains("api")
|| q.contains("theorem")
|| q.contains("equation")
|| q.contains("compiler")
|| q.contains("kernel")
|| q.contains("database")
|| q.contains("encryption")
|| q.contains("neural")
|| q.contains("quantum")
|| q.contains("molecular")
|| q.contains("genome")
|| q.contains("proof")
|| q.contains("axiom")
|| q.contains("cryptograph");
let has_debug_signal = q.contains("error")
|| q.contains("fix")
|| q.contains("troubleshooting")
|| q.contains("troubleshoot")
|| q.contains("out of memory")
|| q.contains("heap")
|| q.contains("segmentation fault")
|| q.contains("exception")
|| q.contains("cors")
|| q.contains("access-control-allow-origin")
|| q.contains("ssl certificate")
|| q.contains("oom killed");
let is_programming_lang = q.contains("python")
|| q.contains("rust")
|| q.contains("javascript")
|| q.contains("typescript")
|| q.contains("node.js")
|| q.contains("nodejs")
|| q.contains("java ")
|| q.contains("golang")
|| q.contains("go ")
|| q.contains("ruby")
|| q.contains("swift")
|| q.contains("kotlin")
|| q.contains("c++")
|| q.contains("c#");
let has_tutorial_signal = q.contains("tutorial")
|| q.contains("guide")
|| q.contains("how to")
|| q.contains("example");
if q.contains("code")
|| q.contains("github")
|| q.contains("function")
|| q.contains("crate")
|| q.contains("snippet")
|| q.contains("implement")
|| q.contains("algorithm")
|| (is_programming_lang
&& !has_tutorial_signal
&& (q.contains("library") || q.contains("package") || q.contains("crate")))
{
return QueryIntent::Code;
}
if is_language_learning {
return QueryIntent::HowTo;
}
if has_debug_signal {
if is_programming_lang
|| q.contains("node.js")
|| q.contains("nodejs")
|| q.contains("react")
|| q.contains("typescript")
{
return QueryIntent::Code;
}
return QueryIntent::HowTo;
}
if has_health_signal && has_guideline_signal {
return QueryIntent::Verification;
}
if has_news_signal
|| (has_recent_year && !is_technical_eval && !is_preference_query)
|| (q.contains("breakthrough") && !is_technical_eval)
{
return QueryIntent::CurrentEvents;
}
if q.contains("how to")
|| q.contains("tutorial")
|| q.contains("guide")
|| q.contains("setup")
|| q.contains("install")
|| q.contains("configure")
|| ((q.contains("docker")
|| q.contains("compose")
|| q.contains("container")
|| q.contains("kubernetes")
|| q.contains("networking")
|| q.contains("hostname")
|| q.contains("dns"))
&& !q.contains(" vs ")
&& !q.contains("compare")
&& !q.contains("comparison"))
{
return QueryIntent::HowTo;
}
if q.starts_with("what is")
|| q.starts_with("what are")
|| q.starts_with("what does")
|| q.starts_with("who is")
|| q.starts_with("who was")
|| q.starts_with("where is")
|| q.starts_with("when was")
|| q.starts_with("when did")
|| q.contains("how does")
|| q.contains("how do ")
|| q.contains("define ")
|| q.contains("definition of")
|| q.contains("definition:")
|| q.contains("explain ")
|| q.contains("meaning of")
|| q.contains(" is a ")
|| q.contains(" is an ")
{
return QueryIntent::Informational;
}
let is_consumer_query = q.contains("pizza")
|| q.contains("restaurant")
|| q.contains("hotel")
|| q.contains("flight")
|| q.contains("coffee")
|| q.contains("recipe")
|| q.contains("movie")
|| q.contains("near me")
|| q.contains("in new ")
|| q.contains("in los ")
|| q.contains("in san ")
|| q.contains("in chicago")
|| q.contains("in london")
|| q.contains("in paris")
|| q.contains("in tokyo")
|| q.contains("shop")
|| q.contains("store")
|| q.contains("gym")
|| q.contains("barber")
|| q.contains("salon")
|| q.contains("dentist")
|| q.contains("plumber");
if is_preference_query && is_consumer_query && !is_programming_lang && !has_technical_signal {
return QueryIntent::Casual;
}
if is_preference_query {
return QueryIntent::Opinion;
}
if q.contains("vs ")
|| q.contains(" vs")
|| q.contains("compare")
|| q.contains("comparison")
|| q.contains("difference")
{
return QueryIntent::Comparison;
}
if q.contains("arxiv") || q.contains("paper") || q.contains("research") || q.contains("study") {
return QueryIntent::Academic;
}
if q.contains("analysis") || q.contains("comprehensive") {
return QueryIntent::DeepAnalysis;
}
if q.contains("deep dive") || q.contains("deep-dive") {
return QueryIntent::HowTo;
}
if q.contains("deep") && !q.contains("deep learning") {
return QueryIntent::DeepAnalysis;
}
let word_count = q.split_whitespace().count();
if word_count <= 6 && !has_technical_signal {
return QueryIntent::Casual;
}
QueryIntent::Factual
}
#[cfg(test)]
mod tests {
use super::*;
use crate::types::BackendId;
fn make_result(title: &str, url: &str, snippet: &str) -> ResultItem {
ResultItem {
title: title.into(),
url: url.into(),
snippet: snippet.into(),
rank: 1,
backend: BackendId::DuckDuckGo,
score: None,
published_date: None,
}
}
#[test]
fn weights_sum_to_one_after_normalize() {
for intent in [
QueryIntent::Factual,
QueryIntent::Informational,
QueryIntent::CurrentEvents,
QueryIntent::Academic,
QueryIntent::Code,
QueryIntent::DeepAnalysis,
] {
let w = IntentWeights::for_intent(intent).normalize();
let sum = w.sum();
assert!((sum - 1.0).abs() < 1e-6, "intent={intent:?} sum={sum}");
}
}
#[test]
fn hyperfusion_ranks_relevant_higher() {
let mut results = vec![
make_result("Random Blog", "https://random-blog.xyz/post", "Some unrelated content about gardening"),
make_result("Rust Lang", "https://rust-lang.org", "Rust is a systems programming language focused on safety, performance, and concurrency."),
make_result("Python Docs", "https://python.org", "Python is a dynamic scripting language"),
];
for (i, r) in results.iter_mut().enumerate() {
r.rank = (i + 1) as u32;
}
hyperfusion_rank(
&mut results,
"Rust programming language",
QueryIntent::Factual,
0.5,
&HashMap::new(),
);
assert_eq!(
results[0].url, "https://rust-lang.org",
"Rust should rank first"
);
assert!(results[0].score.unwrap() > results[2].score.unwrap_or(0.0));
}
#[test]
fn hyperfusion_empty_input() {
let mut results = vec![];
hyperfusion_rank(
&mut results,
"test",
QueryIntent::Factual,
0.5,
&HashMap::new(),
);
assert!(results.is_empty());
}
#[test]
fn all_identical_scores_use_half() {
let scores = vec![
RawScores {
bm25: 0.5,
semantic: 0.5,
temporal: 0.5,
authority: 0.5,
evidence: 0.5,
diversity: 0.5,
depth: 0.5,
consensus: 0.5,
},
RawScores {
bm25: 0.5,
semantic: 0.5,
temporal: 0.5,
authority: 0.5,
evidence: 0.5,
diversity: 0.5,
depth: 0.5,
consensus: 0.5,
},
];
let normalized = min_max_normalize(scores);
assert!((normalized[0].bm25 - 0.5).abs() < 1e-9);
}
#[test]
fn min_max_normalize_correct() {
let scores = vec![
RawScores {
bm25: 0.0,
semantic: 0.0,
temporal: 0.0,
authority: 0.0,
evidence: 0.0,
diversity: 0.0,
depth: 0.0,
consensus: 0.0,
},
RawScores {
bm25: 1.0,
semantic: 1.0,
temporal: 1.0,
authority: 1.0,
evidence: 1.0,
diversity: 1.0,
depth: 1.0,
consensus: 1.0,
},
];
let normalized = min_max_normalize(scores);
assert!((normalized[0].bm25 - 0.0).abs() < 1e-9);
assert!((normalized[1].bm25 - 1.0).abs() < 1e-9);
}
#[test]
fn detect_intent_works() {
assert_eq!(detect_intent("how to install Rust"), QueryIntent::HowTo);
assert_eq!(
detect_intent("docker compose networking between containers"),
QueryIntent::HowTo
);
assert_eq!(
detect_intent("Rust vs Go performance"),
QueryIntent::Comparison
);
assert_eq!(
detect_intent("blood pressure medication side effects comparison"),
QueryIntent::Comparison
);
assert_eq!(
detect_intent("arxiv paper transformer attention"),
QueryIntent::Academic
);
assert_eq!(detect_intent("github rust async code"), QueryIntent::Code);
assert_eq!(
detect_intent("Rust latest news 2026"),
QueryIntent::CurrentEvents
);
}
#[test]
fn detect_intent_temporal_keywords() {
assert_eq!(
detect_intent("quantum computing breakthroughs 2025"),
QueryIntent::CurrentEvents
);
assert_eq!(
detect_intent("recent advances in AI"),
QueryIntent::CurrentEvents
);
assert_eq!(
detect_intent("breaking news AI regulation"),
QueryIntent::CurrentEvents
);
assert_eq!(
detect_intent("new in rust this year"),
QueryIntent::CurrentEvents
);
assert_eq!(
detect_intent("GPT-5 announcement"),
QueryIntent::CurrentEvents
);
}
#[test]
fn detect_intent_technical_year_query_not_forced_to_current_events() {
let intent =
detect_intent("best rust async runtime for high-throughput web api in 2025 benchmark");
assert_ne!(intent, QueryIntent::CurrentEvents);
}
#[test]
fn detect_intent_health_guidelines_prefer_verification_over_current_events() {
assert_eq!(
detect_intent("type 2 diabetes management latest guidelines"),
QueryIntent::Verification
);
}
#[test]
fn detect_intent_language_learning_prefers_howto() {
assert_eq!(
detect_intent("comment apprendre le français rapidement"),
QueryIntent::HowTo
);
}
#[test]
fn detect_intent_cors_fix_prefers_howto() {
assert_eq!(
detect_intent("CORS error Access-Control-Allow-Origin fix"),
QueryIntent::HowTo
);
}
#[test]
fn detect_intent_node_heap_prefers_code() {
assert_eq!(
detect_intent("JavaScript heap out of memory Node.js fix"),
QueryIntent::Code
);
}
#[test]
fn detect_intent_consumer_best_year_query_prefers_opinion() {
let intent = detect_intent("best noise cancelling headphones for office calls 2026");
assert_eq!(intent, QueryIntent::Opinion);
}
#[test]
fn wikipedia_authority_capped_for_temporal() {
let wiki_result = make_result(
"Quantum computing",
"https://en.wikipedia.org/wiki/Quantum_computing",
"Quantum computing is the exploitation of collective properties...",
);
let base_auth = 0.9_f64;
let events_auth =
adjust_authority_for_intent(&wiki_result.url, base_auth, QueryIntent::CurrentEvents);
let factual_auth =
adjust_authority_for_intent(&wiki_result.url, base_auth, QueryIntent::Factual);
assert!(
events_auth < 0.4,
"Wikipedia authority for CurrentEvents should be < 0.4, got {events_auth}"
);
assert!(
(factual_auth - base_auth).abs() < 1e-9,
"Wikipedia authority for Factual should be unchanged"
);
}
#[test]
fn detect_intent_informational() {
assert_eq!(
detect_intent("what is artificial intelligence"),
QueryIntent::Informational
);
assert_eq!(detect_intent("what is ai"), QueryIntent::Informational);
assert_eq!(
detect_intent("what are neural networks"),
QueryIntent::Informational
);
assert_eq!(
detect_intent("who is Alan Turing"),
QueryIntent::Informational
);
assert_eq!(
detect_intent("explain machine learning"),
QueryIntent::Informational
);
assert_eq!(
detect_intent("define deep learning"),
QueryIntent::Informational
);
assert_eq!(
detect_intent("how does TCP work"),
QueryIntent::Informational
);
assert_eq!(
detect_intent("meaning of recursion"),
QueryIntent::Informational
);
}
#[test]
fn informational_authority_lower_than_code_for_github() {
let github_result = make_result(
"hand_detection",
"https://github.com/user/hand_detection",
"A popular ML repository for hand detection",
);
let weights_info = IntentWeights::for_intent(QueryIntent::Informational);
let weights_code = IntentWeights::for_intent(QueryIntent::Code);
assert!(
weights_info.authority < weights_code.authority,
"Informational authority weight ({}) should be < Code ({})",
weights_info.authority,
weights_code.authority
);
let base_auth = 0.9_f64; let info_auth =
adjust_authority_for_intent(&github_result.url, base_auth, QueryIntent::Informational);
let code_auth =
adjust_authority_for_intent(&github_result.url, base_auth, QueryIntent::Code);
assert!(
info_auth < code_auth,
"GitHub info_auth ({info_auth}) should be < code_auth ({code_auth})"
);
assert!(
info_auth < 0.5,
"GitHub authority for informational queries should be < 0.5, got {info_auth}"
);
}
#[test]
fn weight_overrides_applied() {
let weights = IntentWeights::for_intent(QueryIntent::Factual)
.with_overrides(&[("temporal".to_string(), 0.9f64)].into_iter().collect());
assert!((weights.temporal - 0.9).abs() < 1e-9);
}
#[test]
fn hyperfusion_populates_scores() {
let mut results = vec![
make_result("A", "https://a.com", "content A about systems programming"),
make_result("B", "https://b.com", "content B about databases"),
];
results[0].rank = 1;
results[1].rank = 2;
hyperfusion_rank(
&mut results,
"systems",
QueryIntent::Factual,
0.5,
&HashMap::new(),
);
assert!(results[0].score.is_some());
assert!(results[1].score.is_some());
}
}