Skip to content

Commit 054b9d0

Browse files
committed
chunk local ands instead of file local. much faster
1 parent eb0eb1a commit 054b9d0

2 files changed

Lines changed: 5 additions & 37 deletions

File tree

src/db/postgres.rs

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -290,42 +290,10 @@ fn push_search_ctes<'a>(
290290
);
291291
}
292292

293-
if plan.required_terms.len() == 1 {
293+
if !plan.required_terms.is_empty() {
294294
for predicate in &plan.required_terms {
295295
push_content_condition(qb, predicate, case_mode, false);
296296
}
297-
} else if !plan.required_terms.is_empty() {
298-
qb.push(" AND (");
299-
for (idx, predicate) in plan.required_terms.iter().enumerate() {
300-
if idx > 0 {
301-
qb.push(" OR ");
302-
}
303-
qb.push("(");
304-
push_content_predicate(qb, predicate, case_mode, "c.text_content");
305-
qb.push(")");
306-
}
307-
qb.push(")");
308-
309-
qb.push(" AND ");
310-
if seed_repo_first {
311-
qb.push("f_seed.content_hash");
312-
} else {
313-
qb.push("cbc.content_hash");
314-
}
315-
qb.push(" IN (");
316-
for (idx, predicate) in plan.required_terms.iter().enumerate() {
317-
if idx > 0 {
318-
qb.push(" INTERSECT ");
319-
}
320-
qb.push(
321-
"SELECT DISTINCT cbc_req.content_hash \
322-
FROM content_blob_chunks cbc_req \
323-
JOIN chunks c_req ON c_req.chunk_hash = cbc_req.chunk_hash \
324-
WHERE ",
325-
);
326-
push_content_predicate(qb, predicate, case_mode, "c_req.text_content");
327-
}
328-
qb.push(")");
329297
}
330298

331299
for predicate in &plan.excluded_terms {
@@ -3628,11 +3596,11 @@ mod tests {
36283596
}
36293597

36303598
#[test]
3631-
fn multi_term_search_builds_intersect_filter() {
3599+
fn multi_term_search_uses_chunk_local_and_filter() {
36323600
let request = TextSearchRequest::from_query_str("polly LinkAllPasses").unwrap();
36333601
let sql = build_phase1_sql(&request);
3634-
assert!(sql.contains("INTERSECT"));
3635-
assert!(sql.contains("cbc.content_hash IN ("));
3602+
assert!(!sql.contains("INTERSECT"));
3603+
assert!(!sql.contains("cbc.content_hash IN ("));
36363604
}
36373605

36383606
#[test]

src/mcp/tools.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ mod tests {
13881388
use super::{
13891389
build_file_list_entries, build_no_result_guidance, compile_query,
13901390
looks_like_search_filter_query, normalize_repo_path, normalize_tool_error, quote_if_needed,
1391-
search_request_echo, slice_file_content,
1391+
search_request_echo, slice_file_content, truncate_results_by_max_bytes,
13921392
};
13931393
use crate::mcp::types::{SearchDedupeMode, SearchToolRequest};
13941394
use serde_json::json;

0 commit comments

Comments
 (0)