#[derive(Debug, Clone, PartialEq, Eq)]
pub enum QueryRoute {
Semantic,
Keyword,
Graph,
Temporal,
Hybrid,
}
pub struct QueryRouter;
impl QueryRouter {
pub fn new() -> Self {
Self
}
pub fn route(&self, query: &str) -> QueryRoute {
let lower = query.to_lowercase();
let word_count = lower.split_whitespace().count();
let temporal_keywords = [
"yesterday",
"last week",
"last month",
"today",
"this morning",
"this afternoon",
"hours ago",
"minutes ago",
"days ago",
"between",
"before",
"after",
];
if temporal_keywords.iter().any(|kw| lower.contains(kw)) {
return QueryRoute::Temporal;
}
let graph_keywords = [
"related to",
"connected to",
"linked with",
"associated with",
"relationship between",
];
if graph_keywords.iter().any(|kw| lower.contains(kw)) {
return QueryRoute::Graph;
}
if query.starts_with('"') && query.ends_with('"') {
return QueryRoute::Keyword;
}
if word_count <= 2 {
return QueryRoute::Keyword;
}
QueryRoute::Hybrid
}
}
impl Default for QueryRouter {
fn default() -> Self {
Self::new()
}
}