search: return null on whitespace search term

This commit is contained in:
2026-06-08 12:42:08 +09:00
parent 832a74f9c2
commit ab878b3469
3 changed files with 22 additions and 3 deletions
+5 -2
View File
@@ -246,12 +246,15 @@ Future<List<ScoredEntryId>> fetchEntryIds(
int? pageSize,
int? offset,
) async {
assert(
word.trim().isNotEmpty,
'Word should not be empty when fetching entry IDs',
);
if (searchMode == SearchMode.auto) {
searchMode = _determineSearchMode(word);
}
assert(word.isNotEmpty, 'Word should not be empty when fetching entry IDs');
late final List<ScoredEntryId> entryIds;
switch (searchMode) {
case SearchMode.kanji:
+1 -1
View File
@@ -41,7 +41,7 @@ Future<List<WordSearchResult>?> searchWordWithDbConnection(
int page = 0,
int? pageSize,
}) async {
if (word.isEmpty) {
if (word.trim().isEmpty) {
return null;
}
+16
View File
@@ -4,6 +4,22 @@ import 'package:test/test.dart';
import 'setup_database_connection.dart';
void main() {
test('Search empty string - auto', () async {
final connection = await setupDatabaseConnection();
final result = await connection.jadbSearchWord('');
expect(result, isNull);
});
test('Search whitespace - auto', () async {
final connection = await setupDatabaseConnection();
final result1 = await connection.jadbSearchWord(' ');
expect(result1, isNull);
final result2 = await connection.jadbSearchWord('\t');
expect(result2, isNull);
final result3 = await connection.jadbSearchWord('\n');
expect(result3, isNull);
});
test('Search a word - english - auto', () async {
final connection = await setupDatabaseConnection();
final result = await connection.jadbSearchWord('kana');