@@ -4,11 +4,6 @@ use std::str::FromStr;
44
55use anyhow:: Result ;
66use common:: {
7- document:: {
8- CreationTime ,
9- PackedDocument ,
10- ResolvedDocument ,
11- } ,
127 index:: IndexKey ,
138 interval:: {
149 End ,
@@ -20,16 +15,13 @@ use common::{
2015 testing:: TestIdGenerator ,
2116 types:: {
2217 IndexDescriptor ,
23- PersistenceVersion ,
2418 TableName ,
2519 TabletIndexName ,
2620 Timestamp ,
2721 } ,
2822 value:: {
2923 id_v6:: DeveloperDocumentId ,
30- ConvexObject ,
3124 ConvexValue ,
32- FieldName ,
3325 TabletIdAndTableNumber ,
3426 } ,
3527} ;
@@ -42,13 +34,15 @@ use criterion::{
4234use database:: {
4335 write_log:: {
4436 new_write_log,
37+ DocumentIndexKeysUpdate ,
4538 LogWriter ,
46- PackedDocumentUpdate ,
4739 WriteSource ,
4840 } ,
4941 ReadSet ,
5042 TransactionReadSet ,
5143} ;
44+ use indexing:: index_registry:: DocumentIndexKeys ;
45+ use maplit:: btreemap;
5246use search:: {
5347 query:: TextQueryTerm ,
5448 FilterConditionRead ,
@@ -68,8 +62,7 @@ fn create_test_setup() -> Result<(
6862 let table_name: TableName = "test_table" . parse ( ) ?;
6963 let table_id_and_number = id_generator. user_table_id ( & table_name) ;
7064
71- let ( _log_owner, _log_reader, log_writer) =
72- new_write_log ( Timestamp :: must ( 1000 ) , PersistenceVersion :: default ( ) ) ;
65+ let ( _log_owner, _log_reader, log_writer) = new_write_log ( Timestamp :: must ( 1000 ) ) ;
7366
7467 Ok ( ( log_writer, id_generator, table_id_and_number, table_name) )
7568}
@@ -97,26 +90,22 @@ fn create_write_log_with_standard_index_writes(num_writes: usize) -> Result<(Log
9790 26 + ( ( i * 7 ) % 75 )
9891 } ;
9992
100- let document_update = PackedDocumentUpdate {
93+ let index_key = IndexKey :: new ( vec ! [ val!( value as i64 ) ] , id. into ( ) ) ;
94+ let document_keys =
95+ DocumentIndexKeys :: with_standard_index_for_test ( index_name. clone ( ) , index_key) ;
96+
97+ let writes = vec ! [ (
10198 id,
102- old_document : None ,
103- new_document : Some ( PackedDocument :: pack ( & ResolvedDocument :: new (
99+ DocumentIndexKeysUpdate {
104100 id,
105- CreationTime :: try_from ( 1. ) ?,
106- ConvexObject :: try_from (
107- [ (
108- FieldName :: from_str ( "value" ) . unwrap ( ) ,
109- ConvexValue :: Int64 ( value as i64 ) ,
110- ) ]
111- . into_iter ( )
112- . collect :: < std:: collections:: BTreeMap < _ , _ > > ( ) ,
113- ) ?,
114- ) ?) ) ,
115- } ;
101+ old_document_keys: None ,
102+ new_document_keys: Some ( document_keys) ,
103+ } ,
104+ ) ] ;
116105
117106 log_writer. append (
118107 Timestamp :: must ( ( 1001 + i) as i32 ) ,
119- vec ! [ ( id , document_update ) ] . into ( ) ,
108+ writes . into ( ) ,
120109 WriteSource :: unknown ( ) ,
121110 ) ;
122111 }
@@ -203,6 +192,7 @@ fn create_write_log_with_search_index_writes(num_writes: usize) -> Result<(LogWr
203192 // Add writes to the log
204193 for i in 0 ..num_writes {
205194 let id = id_generator. user_generate ( & table_name) ;
195+ let search_field: FieldPath = "content" . parse ( ) ?;
206196
207197 // Generate random text content - some will contain "target" word, but not all
208198 // documents that match filter conditions
@@ -222,45 +212,35 @@ fn create_write_log_with_search_index_writes(num_writes: usize) -> Result<(LogWr
222212 text_words. insert ( insert_pos, "target" ) ;
223213 }
224214
225- let search_value = text_words. join ( " " ) ;
226-
227- // Create document with search content and filterable fields
228- let mut document_content = std:: collections:: BTreeMap :: < FieldName , ConvexValue > :: new ( ) ;
229- document_content. insert (
230- FieldName :: from_str ( "content" ) ?,
231- ConvexValue :: String ( search_value. try_into ( ) ?) ,
232- ) ;
233- document_content. insert (
234- FieldName :: from_str ( "category" ) ?,
235- ConvexValue :: String (
215+ let filter_values = btreemap ! {
216+ "category" . parse( ) ? => FilterValue :: from_search_value( Some ( & ConvexValue :: String (
236217 if i % 3 == 0 { "important" } else { "normal" }
237218 . to_string( )
238219 . try_into( ) ?,
239- ) ,
240- ) ;
241- document_content. insert (
242- FieldName :: from_str ( "priority" ) ?,
243- ConvexValue :: Int64 ( ( i % 5 + 1 ) as i64 ) ,
244- ) ;
245- document_content. insert (
246- FieldName :: from_str ( "active" ) ?,
247- ConvexValue :: Boolean ( i % 2 == 0 ) ,
248- ) ;
220+ ) ) ) ,
221+ "priority" . parse( ) ? => FilterValue :: from_search_value( Some ( & ConvexValue :: Int64 ( ( i % 5 + 1 ) as i64 ) ) ) ,
222+ "active" . parse( ) ? => FilterValue :: from_search_value( Some ( & ConvexValue :: Boolean ( i % 2 == 0 ) ) ) ,
223+ } ;
249224
250- let value = ConvexObject :: try_from ( document_content) ?;
251- let creation_time = CreationTime :: try_from ( 1. ) ?;
252- let document = ResolvedDocument :: new ( id, creation_time, value) ?;
253- let packed_document = PackedDocument :: pack ( & document) ;
225+ let document_keys = DocumentIndexKeys :: with_search_index_for_test_with_filters (
226+ index_name. clone ( ) ,
227+ search_field,
228+ text_words. join ( " " ) . try_into ( ) ?,
229+ filter_values,
230+ ) ;
254231
255- let document_update = PackedDocumentUpdate {
232+ let writes = vec ! [ (
256233 id,
257- old_document : None ,
258- new_document : Some ( packed_document) ,
259- } ;
234+ DocumentIndexKeysUpdate {
235+ id,
236+ old_document_keys: None ,
237+ new_document_keys: Some ( document_keys) ,
238+ } ,
239+ ) ] ;
260240
261241 log_writer. append (
262242 Timestamp :: must ( ( 1001 + i) as i32 ) ,
263- vec ! [ ( id , document_update ) ] . into ( ) ,
243+ writes . into ( ) ,
264244 WriteSource :: unknown ( ) ,
265245 ) ;
266246 }
0 commit comments