@@ -47,6 +47,7 @@ use common::{
4747 } ,
4848 document:: ResolvedDocument ,
4949 index:: IndexKeyBytes ,
50+ knobs:: USE_MULTI_SEGMENT_SEARCH_QUERY ,
5051 query:: {
5152 search_value_to_bytes,
5253 InternalSearch ,
@@ -84,7 +85,7 @@ use query::{
8485 RevisionWithKeys ,
8586 TextQueryTerm ,
8687} ;
87- use searcher:: FragmentedTextSegmentStorageKeys ;
88+ use searcher:: TextStorageKeys ;
8889use storage:: Storage ;
8990pub use tantivy:: Document as TantivyDocument ;
9091use tantivy:: {
@@ -410,7 +411,7 @@ impl TantivySearchIndexSchema {
410411 compiled_query : CompiledQuery ,
411412 memory_index : & MemorySearchIndex ,
412413 search_storage : Arc < dyn Storage > ,
413- segments : Vec < FragmentedTextSegmentStorageKeys > ,
414+ segments : Vec < TextStorageKeys > ,
414415 disk_index_ts : Timestamp ,
415416 searcher : Arc < dyn Searcher > ,
416417 ) -> anyhow:: Result < RevisionWithKeys > {
@@ -438,11 +439,11 @@ impl TantivySearchIndexSchema {
438439 // and merge the results to get the top terms.
439440 let mut match_aggregator = TokenMatchAggregator :: new ( MAX_UNIQUE_QUERY_TERMS ) ;
440441 memory_index. query_tokens ( & token_queries, & mut match_aggregator) ?;
441- for segment in & segments {
442+ for segment in segments. clone ( ) {
442443 let segment_token_matches = searcher
443444 . query_tokens (
444445 search_storage. clone ( ) ,
445- segment. clone ( ) ,
446+ segment,
446447 token_queries. clone ( ) ,
447448 MAX_UNIQUE_QUERY_TERMS ,
448449 )
@@ -482,9 +483,9 @@ impl TantivySearchIndexSchema {
482483 // Step 3: Given the terms we decided on, query BM25 statistics across all of
483484 // the indexes and merge their results.
484485 let mut bm25_stats = Bm25Stats :: empty ( ) ;
485- for segment in & segments {
486+ for segment in segments. clone ( ) {
486487 bm25_stats += searcher
487- . query_bm25_stats ( search_storage. clone ( ) , segment. clone ( ) , terms. clone ( ) )
488+ . query_bm25_stats ( search_storage. clone ( ) , segment, terms. clone ( ) )
488489 . await ?;
489490 }
490491 bm25_stats = memory_index. update_bm25_stats ( disk_index_ts, & terms, bm25_stats) ?;
@@ -545,9 +546,9 @@ impl TantivySearchIndexSchema {
545546 & mut match_aggregator,
546547 ) ?;
547548 }
548- for segment in & segments {
549+ for segment in segments {
549550 let segment_matches = searcher
550- . query_posting_lists ( search_storage. clone ( ) , segment. clone ( ) , query. clone ( ) )
551+ . query_posting_lists ( search_storage. clone ( ) , segment, query. clone ( ) )
551552 . await ?;
552553 for m in segment_matches {
553554 if !match_aggregator. insert ( m) {
@@ -590,6 +591,27 @@ impl TantivySearchIndexSchema {
590591 disk_index_ts : Timestamp ,
591592 searcher : Arc < dyn Searcher > ,
592593 ) -> anyhow:: Result < RevisionWithKeys > {
594+ if * USE_MULTI_SEGMENT_SEARCH_QUERY {
595+ let number_of_segments = searcher
596+ . number_of_segments ( search_storage. clone ( ) , disk_index. clone ( ) )
597+ . await ?;
598+ let segments = ( 0 ..number_of_segments)
599+ . map ( |i| TextStorageKeys :: SingleSegment {
600+ storage_key : disk_index. clone ( ) ,
601+ segment_ord : i as u32 ,
602+ } )
603+ . collect ( ) ;
604+ return self
605+ . search2 (
606+ compiled_query,
607+ memory_index,
608+ search_storage,
609+ segments,
610+ disk_index_ts,
611+ searcher,
612+ )
613+ . await ;
614+ }
593615 // 1. Fetch the memory index matches for each QueryTerm in the query and bound.
594616 let ( term_shortlist, term_shortlist_ids) =
595617 memory_index. bound_and_evaluate_query_terms ( & compiled_query. text_query ) ;
0 commit comments