File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change @@ -2921,6 +2921,28 @@ impl Client {
2921
2921
}
2922
2922
}
2923
2923
2924
+ /// Commit a [`Room`]'s [`RoomIndex`]
2925
+ #[ cfg( feature = "experimental-search" ) ]
2926
+ pub async fn commit ( & self , room_id : & RoomId ) {
2927
+ let mut hash_map = self . inner . room_indexes . lock ( ) . await ;
2928
+ if let Some ( index) = hash_map. get_mut ( room_id) {
2929
+ let _ = index. commit ( ) . inspect_err ( |err| {
2930
+ error ! ( "error occured while committing: {err:?}" ) ;
2931
+ } ) ;
2932
+ }
2933
+ }
2934
+
2935
+ /// Commit a [`Room`]'s [`RoomIndex`] and reload searchers
2936
+ #[ cfg( feature = "experimental-search" ) ]
2937
+ pub async fn commit_and_reload ( & self , room_id : & RoomId ) {
2938
+ let mut hash_map = self . inner . room_indexes . lock ( ) . await ;
2939
+ if let Some ( index) = hash_map. get_mut ( room_id) {
2940
+ let _ = index. commit_and_reload ( ) . inspect_err ( |err| {
2941
+ error ! ( "error occured while committing: {err:?}" ) ;
2942
+ } ) ;
2943
+ }
2944
+ }
2945
+
2924
2946
/// Whether the client is configured to take thread subscriptions (MSC4306
2925
2947
/// and MSC4308) into account.
2926
2948
///
Original file line number Diff line number Diff line change @@ -3695,6 +3695,18 @@ impl Room {
3695
3695
self . client . search_index ( query, max_number_of_results, self . room_id ( ) ) . await
3696
3696
}
3697
3697
3698
+ /// Commit a [`Room`]'s [`RoomIndex`]
3699
+ #[ cfg( feature = "experimental-search" ) ]
3700
+ pub async fn commit ( & self ) {
3701
+ self . client . commit ( self . room_id ( ) ) . await ;
3702
+ }
3703
+
3704
+ /// Commit a [`Room`]'s [`RoomIndex`] and reload searchers
3705
+ #[ cfg( feature = "experimental-search" ) ]
3706
+ pub async fn commit_and_reload ( & self ) {
3707
+ self . client . commit_and_reload ( self . room_id ( ) ) . await ;
3708
+ }
3709
+
3698
3710
/// Subscribe to a given thread in this room.
3699
3711
///
3700
3712
/// This will subscribe the user to the thread, so that they will receive
Original file line number Diff line number Diff line change @@ -740,6 +740,40 @@ async fn test_room_message_send() {
740
740
assert_eq ! ( event_id!( "$h29iv0s8:example.com" ) , response. event_id)
741
741
}
742
742
743
+ #[ cfg( feature = "experimental-search" ) ]
744
+ #[ async_test]
745
+ async fn test_sending_message_indexes_message ( ) {
746
+ let mock_server = MatrixMockServer :: new ( ) . await ;
747
+ let client = mock_server. client_builder ( ) . build ( ) . await ;
748
+
749
+ client. event_cache ( ) . subscribe ( ) . unwrap ( ) ;
750
+
751
+ let room_id = room_id ! ( "!room_id:localhost" ) ;
752
+ let event_id = event_id ! ( "$event_id:localost" ) ;
753
+ let user_id = user_id ! ( "@user_id:localost" ) ;
754
+
755
+ let event_factory = EventFactory :: new ( ) ;
756
+ mock_server
757
+ . sync_room (
758
+ & client,
759
+ JoinedRoomBuilder :: new ( room_id) . add_timeline_bulk ( vec ! [ event_factory
760
+ . text_msg( "this is a sentence" )
761
+ . event_id( event_id)
762
+ . sender( user_id)
763
+ . into_raw_sync( ) ] ) ,
764
+ )
765
+ . await ;
766
+
767
+ let room = client. get_room ( room_id) . unwrap ( ) ;
768
+
769
+ room. commit_and_reload ( ) . await ;
770
+
771
+ let response = room. search_index ( "this" , 5 ) . await . expect ( "search should have 1 result" ) ;
772
+
773
+ assert ! ( !response. is_empty( ) , "no results found {response:?}" ) ;
774
+ assert_eq ! ( response[ 0 ] , event_id, "event id doesn't match: {response:?}" ) ;
775
+ }
776
+
743
777
#[ async_test]
744
778
async fn test_room_redact ( ) {
745
779
let server = MatrixMockServer :: new ( ) . await ;
You can’t perform that action at this time.
0 commit comments