1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
//! Search module for hybrid retrieval system.
//!
//! This module implements the complete query processing and search execution pipeline
//! for hybrid search, combining full-text search (FTS), vector similarity, graph signals,
//! and temporal signals.
//!
//! # Architecture
//!
//! The search pipeline consists of two main stages:
//!
//! 1. **Query Processing** (`query_processor`):
//! - Tokenization for FTS compatibility
//! - Embedding generation for vector search
//! - Query expansion with synonyms
//! - Search mode detection (Code/Text/Auto)
//!
//! 2. **Search Execution** (`executors`):
//! - FTS query execution with ts_rank_cd
//! - Vector similarity search using pgvector
//! - Graph-based importance from chunk_edges
//! - Temporal signal scoring (recency/churn)
//! - Parallel execution using tokio::join!
//!
//! # Examples
//!
//! ## Basic Query Processing
//!
//! ```ignore
//! use maproom::search::{QueryProcessor, SearchMode};
//! use maproom::embedding::EmbeddingService;
//! use std::sync::Arc;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Initialize embedding service
//! let embedder = Arc::new(EmbeddingService::from_env()?);
//!
//! // Create query processor
//! let processor = QueryProcessor::new(embedder);
//!
//! // Process a query
//! let query = "authenticate user with OAuth";
//! let processed = processor.process(query).await?;
//!
//! println!("Original: {}", processed.original);
//! println!("Tokens: {:?}", processed.tokens);
//! println!("Expanded terms: {:?}", processed.expanded_terms);
//! println!("Mode: {:?}", processed.mode);
//! println!("FTS query: {}", processed.fts_query_string());
//!
//! Ok(())
//! }
//! ```
//!
//! ## Parallel Search Execution
//!
//! ```ignore
//! use maproom::search::{QueryProcessor, SearchExecutors};
//! use maproom::embedding::EmbeddingService;
//! use maproom::db;
//! use std::sync::Arc;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Connect to database
//! let store = db::connect().await?;
//!
//! // Initialize components
//! let embedder = Arc::new(EmbeddingService::from_env()?);
//! let processor = QueryProcessor::new(embedder);
//! let executors = SearchExecutors::new(store);
//!
//! // Process query
//! let processed = processor.process("authenticate user").await?;
//!
//! // Execute all searches in parallel
//! let results = executors.execute_all(&processed, 1, None, 10).await?;
//!
//! println!("Search completed: {}", results.summary());
//! println!("FTS results: {}", results.fts.len());
//! println!("Vector results: {}", results.vector.len());
//! println!("Graph results: {}", results.graph.len());
//! println!("Signal results: {}", results.signals.len());
//!
//! Ok(())
//! }
//! ```
//!
//! ## Custom Components
//!
//! ```ignore
//! use maproom::search::{QueryProcessor, Tokenizer, QueryExpander};
//! use maproom::embedding::EmbeddingService;
//! use std::sync::Arc;
//! use std::collections::{HashMap, HashSet};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Custom tokenizer with specific stop words
//! let mut stop_words = HashSet::new();
//! stop_words.insert("custom".to_string());
//! let tokenizer = Tokenizer::with_stop_words(stop_words);
//!
//! // Custom expander with domain-specific synonyms
//! let mut synonyms = HashMap::new();
//! synonyms.insert("oauth".to_string(), vec!["openid".to_string(), "saml".to_string()]);
//! let expander = QueryExpander::with_synonyms(synonyms);
//!
//! // Embedding service
//! let embedder = Arc::new(EmbeddingService::from_env()?);
//!
//! // Create processor with custom components
//! let processor = QueryProcessor::with_components(tokenizer, embedder, expander);
//!
//! let processed = processor.process("oauth authentication").await?;
//! println!("Processed query: {:?}", processed.tokens);
//!
//! Ok(())
//! }
//! ```
//!
//! ## Search Mode Detection
//!
//! ```ignore
//! use maproom::search::{QueryProcessor, SearchMode};
//! use maproom::embedding::EmbeddingService;
//! use std::sync::Arc;
//!
//! let embedder = Arc::new(EmbeddingService::from_env().unwrap());
//! let processor = QueryProcessor::new(embedder);
//!
//! // Code queries
//! assert_eq!(processor.detect_mode("User::authenticate"), SearchMode::Code);
//! assert_eq!(processor.detect_mode("array->map"), SearchMode::Code);
//!
//! // Natural language queries
//! assert_eq!(processor.detect_mode("how to handle authentication errors"), SearchMode::Text);
//!
//! // Ambiguous queries
//! assert_eq!(processor.detect_mode("user auth"), SearchMode::Auto);
//! ```
// Query processing modules
// Search execution modules
// Search pipeline modules (Phase 2)
// Performance optimization modules (Phase 4)
// Re-export main types for convenience
pub use QueryExpander;
pub use ;
pub use Tokenizer;
pub use ;
// Re-export executor types
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
// Re-export pipeline types (Phase 2 + Phase 3)
pub use compute_result_confidence;
pub use ;
pub use ;
pub use ;
pub use ;
pub use find_top_related_chunks;
pub use ;
// Re-export performance optimization types (Phase 4)
pub use ;
pub use ;
pub use ;