probe-code 0.6.0

AI-friendly, fully local, semantic code search tool for large codebases
Documentation
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
use std::collections::{HashMap, HashSet};
use std::fs;
use std::path::Path;
use tempfile::TempDir;

use probe_code::search::elastic_query::Expr;
use probe_code::search::query::QueryPlan;
use probe_code::search::{perform_probe, SearchOptions};

/// Create test files with different content for testing queries
fn create_test_files(temp_dir: &Path) {
    // File with "keywordAlpha" and "keywordBeta"
    let file1_path = temp_dir.join("file1.rs");
    let file1_content = r#"
// This file contains keywordAlpha and keywordBeta
fn test_function() {
    // This is keywordAlpha
    let x = 1;
    
    // This is keywordBeta
    let y = 2;
    
    println!("Result: {}", x + y);
}
"#;

    // File with "keywordAlpha" and "keywordGamma"
    let file2_path = temp_dir.join("file2.rs");
    let file2_content = r#"
// This file contains keywordAlpha and keywordGamma
fn another_function() {
    // This is keywordAlpha
    let x = 1;
    
    // This is keywordGamma
    let z = 3;
    
    println!("Result: {}", x + z);
}
"#;

    // File with "keywordBeta" and "keywordGamma"
    let file3_path = temp_dir.join("file3.rs");
    let file3_content = r#"
// This file contains keywordBeta and keywordGamma
fn third_function() {
    // This is keywordBeta
    let y = 2;
    
    // This is keywordGamma
    let z = 3;
    
    println!("Result: {}", y + z);
}
"#;

    // File with all keywords
    let file4_path = temp_dir.join("file4.rs");
    let file4_content = r#"
// This file contains keywordAlpha, keywordBeta, and keywordGamma
fn all_keywords_function() {
    // This is keywordAlpha
    let x = 1;
    
    // This is keywordBeta
    let y = 2;
    
    // This is keywordGamma
    let z = 3;
    
    println!("Result: {}", x + y + z);
}
"#;

    // Write files to disk
    fs::write(file1_path, file1_content).unwrap();
    fs::write(file2_path, file2_content).unwrap();
    fs::write(file3_path, file3_content).unwrap();
    fs::write(file4_path, file4_content).unwrap();
}

/// Test a query with a required term: key OR word OR keyword
#[test]
fn test_required_term_query() {
    // Create a temporary directory for testing
    let temp_dir = TempDir::new().unwrap();
    let temp_path = temp_dir.path();

    // Create test files with different content
    create_test_files(temp_path);

    // Create search query with explicit OR syntax that matches the actual content
    // Since we've removed any_term parameter and changed the default to AND,
    // we need to use explicit OR syntax to maintain the original behavior
    let queries = vec!["keywordAlpha OR keywordBeta OR keywordGamma".to_string()];
    let custom_ignores: Vec<String> = vec![];

    // Print the query for debugging
    println!("Testing query: {queries:?}");

    // Create SearchOptions
    let options = SearchOptions {
        path: temp_path,
        queries: &queries,
        files_only: false,
        custom_ignores: &custom_ignores,
        exclude_filenames: false,
        language: None,
        reranker: "hybrid",
        frequency_search: false,
        max_results: None,
        max_bytes: None,
        max_tokens: None,
        allow_tests: true,
        no_merge: false,
        merge_threshold: Some(5),
        dry_run: false,
        session: None,
        timeout: 30,
        exact: false,
    };

    // Print the temp_path for debugging
    println!("Temp path: {temp_path:?}");

    // List files in the temp directory
    println!("Files in temp directory:");
    for entry in std::fs::read_dir(temp_path).unwrap() {
        let entry = entry.unwrap();
        println!("  {:?}", entry.path());
    }

    // Run the search
    let search_results = perform_probe(&options).unwrap();

    // Debug output
    println!("Search results: {} items", search_results.results.len());
    for result in &search_results.results {
        println!("  File: {}", result.file);
    }

    // Check that we got results
    assert!(
        !search_results.results.is_empty(),
        "Search should return results"
    );

    // We should only find files with keywordAlpha
    let file_names: Vec<&str> = search_results
        .results
        .iter()
        .map(|r| r.file.as_str())
        .collect();

    // Debug output
    println!("Found {} results", search_results.results.len());
    for result in &search_results.results {
        println!("File: {}", result.file);
    }

    // Check that we found files with keywordAlpha OR keywordBeta OR keywordGamma
    assert!(
        file_names.iter().any(|&name| name.contains("file1")),
        "Should find file1 which contains keywordAlpha OR keywordBeta"
    );
    assert!(
        file_names.iter().any(|&name| name.contains("file2")),
        "Should find file2 which contains keywordAlpha OR keywordGamma"
    );
    assert!(
        file_names.iter().any(|&name| name.contains("file3")),
        "Should find file3 which contains keywordBeta OR keywordGamma"
    );
    assert!(
        file_names.iter().any(|&name| name.contains("file4")),
        "Should find file4 which contains keywordAlpha, keywordBeta, and keywordGamma"
    );
}

/// Test a query with an excluded term: -keywordGamma
#[test]
fn test_excluded_term_query() {
    // Create a temporary directory for testing
    let temp_dir = TempDir::new().unwrap();
    let temp_path = temp_dir.path();

    // Create test files with different content
    create_test_files(temp_path);

    // Create search query with an excluded term
    let queries = vec!["(key OR word OR keyword) -keywordGamma".to_string()];
    let custom_ignores: Vec<String> = vec![];

    // Print the test files for debugging
    println!("Test files created in: {temp_path:?}");
    for entry in std::fs::read_dir(temp_path).unwrap() {
        let entry = entry.unwrap();
        println!("  {:?}", entry.path());

        // Print file content for debugging
        let content = std::fs::read_to_string(entry.path()).unwrap();
        println!(
            "  Content of {:?}:\n{}",
            entry.path().file_name().unwrap(),
            content
        );
    }

    // Create SearchOptions
    let options = SearchOptions {
        path: temp_path,
        queries: &queries,
        files_only: false,
        custom_ignores: &custom_ignores,
        exclude_filenames: false,
        language: None,
        reranker: "hybrid",
        frequency_search: false,
        max_results: None,
        max_bytes: None,
        max_tokens: None,
        allow_tests: true,
        no_merge: false,
        merge_threshold: Some(5),
        dry_run: false,
        session: None,
        timeout: 30,
        exact: false,
    };

    // Print the query for debugging
    println!("Executing search with query: {queries:?}");
    println!(
        "Path: {:?}, frequency_search: {}",
        options.path, options.frequency_search
    );

    // Run the search
    let search_results = perform_probe(&options).unwrap();

    // Check that we got results
    assert!(
        !search_results.results.is_empty(),
        "Search should return results"
    );

    // We should find files with (key OR word OR keyword) -keywordGamma
    let file_names: Vec<&str> = search_results
        .results
        .iter()
        .map(|r| r.file.as_str())
        .collect();

    // Debug output
    println!(
        "Excluded term query results: {} items",
        search_results.results.len()
    );
    for result in &search_results.results {
        println!("  File: {}", result.file);
    }

    // Check that we found file1 (has key OR word OR keyword but not keywordGamma)
    assert!(
        file_names.iter().any(|&name| name.contains("file1")),
        "Should find file1 which contains key OR word OR keyword but not keywordGamma"
    );

    // Check that we don't find file2, file3, and file4 (they have keywordGamma)
    assert!(
        !file_names.iter().any(|&name| name.contains("file2")),
        "Should not find file2 which contains keywordGamma"
    );

    assert!(
        !file_names.iter().any(|&name| name.contains("file3")),
        "Should not find file3 which contains keywordGamma"
    );

    assert!(
        !file_names.iter().any(|&name| name.contains("file4")),
        "Should not find file4 which contains keywordGamma"
    );
}

/// Test a query with OR: keywordAlpha OR keywordBeta
#[test]
fn test_or_query() {
    // Create a temporary directory for testing
    let temp_dir = TempDir::new().unwrap();
    let temp_path = temp_dir.path();

    // Create test files with different content
    create_test_files(temp_path);

    // Create search query with explicit OR syntax
    // Make sure to use uppercase OR to ensure it's recognized as an operator
    let queries = vec!["keywordAlpha OR keywordBeta".to_string()];
    let custom_ignores: Vec<String> = vec![];

    // Create SearchOptions
    let options = SearchOptions {
        path: temp_path,
        queries: &queries,
        files_only: true, // Use files_only to ensure we find all matching files
        custom_ignores: &custom_ignores,
        exclude_filenames: false,
        language: None,
        reranker: "hybrid",
        frequency_search: true, // Enable frequency search to improve matching
        max_results: None,
        max_bytes: None,
        max_tokens: None,
        allow_tests: true,
        no_merge: false,
        merge_threshold: Some(5),
        dry_run: false,
        session: None,
        timeout: 30,
        exact: false,
    };

    // Print the test files for debugging
    println!("Test files created in: {temp_path:?}");
    for entry in std::fs::read_dir(temp_path).unwrap() {
        let entry = entry.unwrap();
        println!("  {:?}", entry.path());

        // Print file content for debugging
        let content = std::fs::read_to_string(entry.path()).unwrap();
        println!(
            "  Content of {:?}:\n{}",
            entry.path().file_name().unwrap(),
            content
        );
    }

    // Print the query for debugging
    println!("Executing search with query: {queries:?}");
    println!(
        "Path: {:?}, frequency_search: {}",
        options.path, options.frequency_search
    );

    // Run the search
    let search_results = perform_probe(&options).unwrap();

    // Check that we got results
    assert!(
        !search_results.results.is_empty(),
        "Search should return results"
    );

    // We should find files with keywordAlpha OR keywordBeta
    let file_names: Vec<&str> = search_results
        .results
        .iter()
        .map(|r| r.file.as_str())
        .collect();

    // Debug output to see what files were found
    println!("Found files with 'keywordAlpha OR keywordBeta':");
    for name in &file_names {
        println!("  {name}");
    }

    // Check that we found files with keywordAlpha OR keywordBeta
    assert!(
        file_names.iter().any(|&name| name.contains("file1")),
        "Should find file1 which contains keywordAlpha and keywordBeta"
    );
    assert!(
        file_names.iter().any(|&name| name.contains("file2")),
        "Should find file2 which contains keywordAlpha"
    );
    assert!(
        file_names.iter().any(|&name| name.contains("file3")),
        "Should find file3 which contains keywordBeta"
    );
    assert!(
        file_names.iter().any(|&name| name.contains("file4")),
        "Should find file4 which contains keywordAlpha and keywordBeta"
    );
}

/// Test a complex query with OR syntax
#[test]
fn test_complex_query_or() {
    // Create a temporary directory for testing
    let temp_dir = TempDir::new().unwrap();
    let temp_path = temp_dir.path();

    // Create test files with different content
    create_test_files(temp_path);

    // Test with explicit OR syntax
    // "keywordAlpha OR keywordBeta" means files with keywordAlpha OR keywordBeta
    let queries = vec!["keywordAlpha OR keywordBeta".to_string()];
    let custom_ignores: Vec<String> = vec![];

    // Create SearchOptions
    let options = SearchOptions {
        path: temp_path,
        queries: &queries,
        files_only: false,
        custom_ignores: &custom_ignores,
        exclude_filenames: false,
        language: None,
        reranker: "hybrid",
        frequency_search: true, // Enable frequency search to improve matching
        max_results: None,
        max_bytes: None,
        max_tokens: None,
        allow_tests: true,
        no_merge: false,
        merge_threshold: Some(5),
        dry_run: false,
        session: None,
        timeout: 30,
        exact: false,
    };

    // Print the test files for debugging
    println!("Test files created in: {temp_path:?}");
    for entry in std::fs::read_dir(temp_path).unwrap() {
        let entry = entry.unwrap();
        println!("  {:?}", entry.path());

        // Print file content for debugging
        let content = std::fs::read_to_string(entry.path()).unwrap();
        println!(
            "  Content of {:?}:\n{}",
            entry.path().file_name().unwrap(),
            content
        );
    }

    // Print the query for debugging
    println!("Executing search with query: {queries:?}");
    println!(
        "Path: {:?}, frequency_search: {}",
        options.path, options.frequency_search
    );

    // Run the search
    let search_results = perform_probe(&options).unwrap();

    // Check that we got results
    assert!(
        !search_results.results.is_empty(),
        "Search should return results"
    );

    let file_names: Vec<&str> = search_results
        .results
        .iter()
        .map(|r| r.file.as_str())
        .collect();

    // Debug output to see what files were found
    println!("Found files with 'keywordAlpha OR keywordBeta':");
    for name in &file_names {
        println!("  {name}");
    }

    // With explicit OR syntax, should find all files with keywordAlpha OR keywordBeta
    assert!(
        file_names.iter().any(|&name| name.contains("file1")),
        "Should find file1 which has keywordAlpha and keywordBeta"
    );
    assert!(
        file_names.iter().any(|&name| name.contains("file2")),
        "Should find file2 which has keywordAlpha"
    );
    assert!(
        file_names.iter().any(|&name| name.contains("file3")),
        "Should find file3 which has keywordBeta"
    );
    assert!(
        file_names.iter().any(|&name| name.contains("file4")),
        "Should find file4 which has keywordAlpha and keywordBeta"
    );
}

/// Test a complex query with explicit OR syntax
#[test]
fn test_complex_query_exclusion() {
    // Create a temporary directory for testing
    let temp_dir = TempDir::new().unwrap();
    let temp_path = temp_dir.path();

    // Create test files with different content
    create_test_files(temp_path);

    // Test with exclusion
    let queries = vec!["\"keywordAlpha\" -keywordGamma".to_string()];
    let custom_ignores: Vec<String> = vec![];

    // Create SearchOptions
    let options = SearchOptions {
        path: temp_path,
        queries: &queries,
        files_only: false,
        custom_ignores: &custom_ignores,
        exclude_filenames: false,
        language: None,
        reranker: "hybrid",
        frequency_search: false,
        max_results: None,
        max_bytes: None,
        max_tokens: None,
        allow_tests: true,
        no_merge: false,
        merge_threshold: Some(5),
        dry_run: false,
        session: None,
        timeout: 30,
        exact: false,
    };

    // Print the query for debugging
    println!("Executing search with query: {queries:?}");
    println!(
        "Path: {:?}, frequency_search: {}",
        options.path, options.frequency_search
    );

    // Run the search
    let search_results = perform_probe(&options).unwrap();

    // Check that we got results
    assert!(
        !search_results.results.is_empty(),
        "Search should return results for query: {queries:?}"
    );

    let file_names: Vec<&str> = search_results
        .results
        .iter()
        .map(|r| r.file.as_str())
        .collect();

    // Debug output to see what files were found
    println!("Found files with 'keywordAlpha -keywordGamma':");
    for name in &file_names {
        println!("  {name}");
    }

    // Should find file1 (has keywordAlpha and no keywordGamma)
    assert!(
        file_names.iter().any(|&name| name.contains("file1")),
        "Should find file1 which has keywordAlpha but no keywordGamma"
    );

    // Should NOT find file2 (has keywordAlpha but also has keywordGamma)
    assert!(
        !file_names.iter().any(|&name| name.contains("file2")),
        "Should not find file2 which has keywordGamma"
    );

    // Should NOT find file4 (has keywordAlpha but also has keywordGamma)
    assert!(
        !file_names.iter().any(|&name| name.contains("file4")),
        "Should not find file4 which has keywordGamma"
    );
}

/// Test underscore handling in queries
#[test]
fn test_underscore_handling_integration() {
    // Create a temporary directory for testing
    let temp_dir = TempDir::new().unwrap();
    let temp_path = temp_dir.path();

    // Create a test file with the tokenized terms
    let file_path = temp_path.join("underscore_test.rs");
    let file_content = r#"
// This file contains key word score
fn test_function() {
    // This has key, word, and score
    let x = 1;
    
    // This also has key word score
    let y = 2;
    
    println!("Result: {}", x + y);
}
"#;
    fs::write(file_path, file_content).unwrap();

    // Test query with underscore using explicit OR syntax
    // Since we've removed any_term parameter and changed the default to AND,
    // we need to use explicit OR syntax to maintain the original behavior
    let queries = vec!["key OR word OR score".to_string()];
    let custom_ignores: Vec<String> = vec![];

    // Create SearchOptions
    let options = SearchOptions {
        path: temp_path,
        queries: &queries,
        files_only: false,
        custom_ignores: &custom_ignores,
        exclude_filenames: false,
        language: None,
        reranker: "hybrid",
        frequency_search: false,
        max_results: None,
        max_bytes: None,
        max_tokens: None,
        allow_tests: true,
        no_merge: false,
        merge_threshold: Some(5),
        dry_run: false,
        session: None,
        timeout: 30,
        exact: false,
    };

    // Run the search
    let search_results = perform_probe(&options).unwrap();

    // Check that we got results
    assert!(
        !search_results.results.is_empty(),
        "Search should return results"
    );

    let file_names: Vec<&str> = search_results
        .results
        .iter()
        .map(|r| r.file.as_str())
        .collect();

    // Debug output to see what files were found
    println!("Found files with 'key OR word OR score':");
    for name in &file_names {
        println!("  {name}");
    }

    // Should find the file with at least one of the terms: key, word, or score
    assert!(
        file_names.iter().any(|&name| name.contains("underscore_test")),
        "Should find underscore_test.rs which contains at least one of the terms: key, word, or score"
    );

    // Verify that the code in the results contains at least one of the tokenized terms
    for result in &search_results.results {
        println!("Result code: {}", result.code);
        // The search should find files containing at least one of the tokenized terms
        assert!(
            result.code.contains("key")
                || result.code.contains("word")
                || result.code.contains("score"),
            "Result code should contain at least one of the terms: 'key', 'word', or 'score'"
        );
    }
}

/// Test the direct usage of filter_code_block_with_ast
#[test]
fn test_filter_code_block_with_ast() {
    // This test directly tests the filter_code_block_with_ast function
    // by creating a mock QueryPlan and term matches

    // Create a simple AST: keywordAlpha AND -keywordBeta
    let ast = Expr::And(
        Box::new(Expr::Term {
            keywords: vec!["keywordAlpha".to_string()],
            field: None,
            required: false,
            excluded: false,
            exact: false,
        }),
        Box::new(Expr::Term {
            keywords: vec!["keywordBeta".to_string()],
            field: None,
            required: false,
            excluded: true,
            exact: false,
        }),
    );

    // Create a term indices map
    let mut term_indices = HashMap::new();
    term_indices.insert("keywordAlpha".to_string(), 0);
    term_indices.insert("keywordBeta".to_string(), 1);

    // Create a QueryPlan
    let plan = QueryPlan {
        ast,
        term_indices,
        excluded_terms: {
            let mut set = HashSet::new();
            set.insert("keywordBeta".to_string());
            set
        },
        exact: false,
    };

    // Create term matches for a block
    let mut term_matches = HashMap::new();

    // Block with only keywordAlpha
    let mut lines1 = HashSet::new();
    lines1.insert(1);
    lines1.insert(2);
    term_matches.insert(0, lines1);

    // Test the function with a block that should match
    let block_lines = (1, 5);
    let debug_mode = false;

    // Import the function from probe crate
    use probe_code::search::file_processing::filter_code_block_with_ast;

    // The block should match because it has keywordAlpha but not keywordBeta
    assert!(
        filter_code_block_with_ast(block_lines, &term_matches, &plan, debug_mode),
        "Block should match because it has keywordAlpha but not keywordBeta"
    );

    // Now add keywordBeta to the block
    let mut lines2 = HashSet::new();
    lines2.insert(3);
    lines2.insert(4);
    term_matches.insert(1, lines2);

    // The block should not match because it now has keywordBeta (which is excluded)
    assert!(
        !filter_code_block_with_ast(block_lines, &term_matches, &plan, debug_mode),
        "Block should not match because it has keywordBeta which is excluded"
    );
}

/// Test the direct usage of filter_tokenized_block
#[test]
fn test_filter_tokenized_block() {
    // This test directly tests the filter_tokenized_block function
    // by creating a mock QueryPlan and tokenized content

    // Create a simple AST: keywordAlpha AND -keywordBeta
    let ast = Expr::And(
        Box::new(Expr::Term {
            keywords: vec!["keywordAlpha".to_string()],
            field: None,
            required: false,
            excluded: false,
            exact: false,
        }),
        Box::new(Expr::Term {
            keywords: vec!["keywordBeta".to_string()],
            field: None,
            required: false,
            excluded: true,
            exact: false,
        }),
    );

    // Create a term indices map
    let mut term_indices = HashMap::new();
    term_indices.insert("keywordAlpha".to_string(), 0);
    term_indices.insert("keywordBeta".to_string(), 1);

    // Create a QueryPlan
    let plan = QueryPlan {
        ast,
        term_indices: term_indices.clone(),
        excluded_terms: {
            let mut set = HashSet::new();
            set.insert("keywordBeta".to_string());
            set
        },
        exact: false,
    };

    // Import the function from probe crate
    use probe_code::search::file_processing::filter_tokenized_block;

    // Test case 1: Tokenized content with only keywordAlpha
    let tokenized_content = vec!["keywordAlpha".to_string()];
    let debug_mode = false;

    // The block should match because it has keywordAlpha but not keywordBeta
    assert!(
        filter_tokenized_block(&tokenized_content, &term_indices, &plan, debug_mode),
        "Block should match because it has keywordAlpha but not keywordBeta"
    );

    // Test case 2: Tokenized content with both keywordAlpha and keywordBeta
    let tokenized_content = vec!["keywordAlpha".to_string(), "keywordBeta".to_string()];

    // The block should not match because it has keywordBeta (which is excluded)
    assert!(
        !filter_tokenized_block(&tokenized_content, &term_indices, &plan, debug_mode),
        "Block should not match because it has keywordBeta which is excluded"
    );

    // Test case 3: Tokenized content with neither keyword
    let tokenized_content = vec!["other".to_string()];

    // The block should not match because it doesn't have keywordAlpha
    assert!(
        !filter_tokenized_block(&tokenized_content, &term_indices, &plan, debug_mode),
        "Block should not match because it doesn't have keywordAlpha"
    );

    // Test case 4: Empty tokenized content
    let tokenized_content: Vec<String> = vec![];

    // The block should not match because it doesn't have keywordAlpha
    assert!(
        !filter_tokenized_block(&tokenized_content, &term_indices, &plan, debug_mode),
        "Empty block should not match"
    );

    // Test case 5: Test with OR expression
    // Create a simple AST: keywordAlpha OR keywordGamma
    let ast_or = Expr::Or(
        Box::new(Expr::Term {
            keywords: vec!["keywordAlpha".to_string()],
            field: None,
            required: false,
            excluded: false,
            exact: false,
        }),
        Box::new(Expr::Term {
            keywords: vec!["keywordGamma".to_string()],
            field: None,
            required: false,
            excluded: false,
            exact: false,
        }),
    );

    // Create a term indices map
    let mut term_indices_or = HashMap::new();
    term_indices_or.insert("keywordAlpha".to_string(), 0);
    term_indices_or.insert("keywordGamma".to_string(), 2);

    // Create a QueryPlan
    let plan_or = QueryPlan {
        ast: ast_or,
        term_indices: term_indices_or.clone(),
        excluded_terms: HashSet::new(),
        exact: false,
    };

    // Test with only keywordGamma
    let tokenized_content = vec!["keywordGamma".to_string()];

    // The block should match because it has keywordGamma (part of OR expression)
    assert!(
        filter_tokenized_block(&tokenized_content, &term_indices_or, &plan_or, debug_mode),
        "Block should match because it has keywordGamma (part of OR expression)"
    );

    // Test with both keywordAlpha and keywordGamma
    let tokenized_content = vec!["keywordAlpha".to_string(), "keywordGamma".to_string()];

    // The block should match because it has both keywords in OR expression
    assert!(
        filter_tokenized_block(&tokenized_content, &term_indices_or, &plan_or, debug_mode),
        "Block should match because it has both keywords in OR expression"
    );
}