@@ -16,7 +16,7 @@ use crate::sessions::{
1616 LcmSourceRef , LcmSummaryNode , LcmSummaryNodeDraft , LcmSummaryRequest ,
1717 LcmSummarySourceMessage , LcmSummarySourceRange ,
1818 } ,
19- SessionMessageRecord , SessionMessageSearchResult , SessionRecord , SessionSearchScope ,
19+ SessionMessageRecord , SessionMessageSearchResult , SessionRecord , SessionSearchFilters ,
2020} ;
2121
2222const UNIX_TIMESTAMP_MILLIS_THRESHOLD : i64 = 1_000_000_000_000 ;
@@ -3178,8 +3178,7 @@ impl GlobalDb {
31783178 project_key,
31793179 query,
31803180 limit,
3181- SessionSearchScope :: All ,
3182- None ,
3181+ SessionSearchFilters :: default ( ) ,
31833182 )
31843183 . await
31853184 }
@@ -3191,16 +3190,14 @@ impl GlobalDb {
31913190 project_key : Option < & str > ,
31923191 query : & str ,
31933192 limit : usize ,
3194- scope : SessionSearchScope ,
3195- parent_session_id : Option < & str > ,
3193+ filters : SessionSearchFilters < ' _ > ,
31963194 ) -> Vec < SessionMessageSearchResult > {
31973195 self . search_session_messages_filtered_inner (
31983196 Some ( provider) ,
31993197 project_key,
32003198 query,
32013199 limit,
3202- scope,
3203- parent_session_id,
3200+ filters,
32043201 )
32053202 . await
32063203 }
@@ -3211,18 +3208,10 @@ impl GlobalDb {
32113208 project_key : Option < & str > ,
32123209 query : & str ,
32133210 limit : usize ,
3214- scope : SessionSearchScope ,
3215- parent_session_id : Option < & str > ,
3211+ filters : SessionSearchFilters < ' _ > ,
32163212 ) -> Vec < SessionMessageSearchResult > {
3217- self . search_session_messages_filtered_inner (
3218- None ,
3219- project_key,
3220- query,
3221- limit,
3222- scope,
3223- parent_session_id,
3224- )
3225- . await
3213+ self . search_session_messages_filtered_inner ( None , project_key, query, limit, filters)
3214+ . await
32263215 }
32273216
32283217 async fn search_session_messages_filtered_inner (
@@ -3231,8 +3220,7 @@ impl GlobalDb {
32313220 project_key : Option < & str > ,
32323221 query : & str ,
32333222 limit : usize ,
3234- scope : SessionSearchScope ,
3235- parent_session_id : Option < & str > ,
3223+ filters : SessionSearchFilters < ' _ > ,
32363224 ) -> Vec < SessionMessageSearchResult > {
32373225 let fts_query = session_fts_query ( query) ;
32383226 if fts_query. is_empty ( ) || limit == 0 {
@@ -3265,14 +3253,36 @@ impl GlobalDb {
32653253 query_params. push ( Value :: Text ( project_key. to_string ( ) ) ) ;
32663254 let _ = write ! ( sql, " AND s.project_key = ?{}" , query_params. len( ) ) ;
32673255 }
3268- if let Some ( parent_session_id) = parent_session_id {
3256+ if let Some ( parent_session_id) = filters . parent_session_id {
32693257 query_params. push ( Value :: Text ( parent_session_id. to_string ( ) ) ) ;
32703258 let _ = write ! ( sql, " AND s.parent_session_id = ?{}" , query_params. len( ) ) ;
32713259 }
3272- if matches ! ( scope, SessionSearchScope :: ParentsOnly ) {
3260+ if let Some ( start_time) = filters. time_range . start_time {
3261+ query_params. push ( Value :: Integer ( start_time) ) ;
3262+ let _ = write ! (
3263+ sql,
3264+ " AND m.timestamp IS NOT NULL AND m.timestamp >= ?{}" ,
3265+ query_params. len( )
3266+ ) ;
3267+ }
3268+ if let Some ( end_time) = filters. time_range . end_time {
3269+ query_params. push ( Value :: Integer ( end_time) ) ;
3270+ let _ = write ! (
3271+ sql,
3272+ " AND m.timestamp IS NOT NULL AND m.timestamp <= ?{}" ,
3273+ query_params. len( )
3274+ ) ;
3275+ }
3276+ if matches ! (
3277+ filters. scope,
3278+ crate :: sessions:: SessionSearchScope :: ParentsOnly
3279+ ) {
32733280 sql. push_str ( " AND s.is_subagent = 0" ) ;
32743281 }
3275- if matches ! ( scope, SessionSearchScope :: SubagentsOnly ) {
3282+ if matches ! (
3283+ filters. scope,
3284+ crate :: sessions:: SessionSearchScope :: SubagentsOnly
3285+ ) {
32763286 sql. push_str ( " AND s.is_subagent = 1" ) ;
32773287 }
32783288 for term in & literal_terms {
0 commit comments