Skip to content

Commit

Permalink
feat: return exact handle match when searching by name
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamadJaara committed Feb 19, 2025
1 parent 7c462ea commit c64b48f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SELECT qualified_id, name, complete_asset_id, preview_asset_id, user_type, conne
WHERE connection_status = 'ACCEPTED' AND
qualified_id != (SELECT id FROM SelfUser LIMIT 1) AND
deleted = 0 AND
name LIKE ('%' || :searchQuery || '%');
(name LIKE ('%' || :searchQuery || '%') OR handle = :searchQuery);

selectAllConnectedUsersNotInConversation:
SELECT qualified_id, name, complete_asset_id, preview_asset_id, user_type, connection_status, handle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ CREATE TABLE User (
);
CREATE INDEX user_team_index ON User(team);
CREATE INDEX user_service_id ON User(bot_service);
CREATE INDEX idx_user_connection_deleted_handle ON User (connection_status, deleted, handle);

deleteUser:
DELETE FROM User WHERE qualified_id = ?;
Expand Down
1 change: 1 addition & 0 deletions persistence/src/commonMain/db_user/migrations/99.sqm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE INDEX IF NOT EXISTS idx_user_connection_deleted_handle ON User (connection_status, deleted, handle);
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import com.wire.kalium.persistence.utils.stubs.newUserEntity
import kotlinx.coroutines.test.runTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertContains
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class SearchDAOTest : BaseDatabaseTest() {

Expand Down Expand Up @@ -280,4 +282,39 @@ class SearchDAOTest : BaseDatabaseTest() {
assertEquals(connectedUser2.id, it[0].id)
}
}

@Test
fun givenConnectedUser_whenSearchWithName_thenReturnExactHandleMatchIncluded() = runTest {
val searchQuery = "searchQuery"
val exactHandleMatch = newUserEntity(id = "1").copy(handle = searchQuery, connectionStatus = ConnectionEntity.State.ACCEPTED)
val similarButNotTheSame =
newUserEntity(id = "2").copy(handle = searchQuery + "whatEver", connectionStatus = ConnectionEntity.State.ACCEPTED)
val totalDifferentHandle = newUserEntity(id = "3").copy(handle = "whatEver", connectionStatus = ConnectionEntity.State.ACCEPTED)
val similarNameDifferentHandle = newUserEntity(id = "4").copy(
handle = "whatEver",
name = "321" + searchQuery + "123",
connectionStatus = ConnectionEntity.State.ACCEPTED
)

val conversation = newConversationEntity(id = "1")

userDAO.insertOrIgnoreUsers(
listOf(
exactHandleMatch,
similarButNotTheSame,
totalDifferentHandle,
similarNameDifferentHandle,
)
)
conversationDAO.insertConversation(conversation)

searchDAO.searchList(searchQuery).also { searchEntities ->
assertEquals(2, searchEntities.size)
assertTrue {
searchEntities.find { it.id == exactHandleMatch.id } != null
searchEntities.find { it.id == similarNameDifferentHandle.id } != null
}
}

}
}

0 comments on commit c64b48f

Please sign in to comment.