search/word_search: fix casing of SearchMode variants
This commit is contained in:
@@ -107,7 +107,7 @@ class WordSearchResult {
|
||||
/// Infers which part(s) of this word search result matched the search keyword, and populates [matchSpans] accordingly.
|
||||
void inferMatchSpans(
|
||||
String searchword, {
|
||||
SearchMode searchMode = SearchMode.Auto,
|
||||
SearchMode searchMode = SearchMode.auto,
|
||||
}) {
|
||||
// TODO: handle wildcards like '?' and '*' when that becomes supported in the search.
|
||||
// TODO: If the searchMode is provided, we can use that to narrow down which part of the word search results to look at.
|
||||
|
||||
@@ -30,7 +30,7 @@ extension JaDBConnection on DatabaseExecutor {
|
||||
/// Search for a word in the database.
|
||||
Future<List<WordSearchResult>?> jadbSearchWord(
|
||||
String word, {
|
||||
SearchMode searchMode = SearchMode.Auto,
|
||||
SearchMode searchMode = SearchMode.auto,
|
||||
int page = 0,
|
||||
int? pageSize,
|
||||
}) => searchWordWithDbConnection(
|
||||
@@ -54,7 +54,7 @@ extension JaDBConnection on DatabaseExecutor {
|
||||
/// Search for a word in the database, and return the count of results.
|
||||
Future<int?> jadbSearchWordCount(
|
||||
String word, {
|
||||
SearchMode searchMode = SearchMode.Auto,
|
||||
SearchMode searchMode = SearchMode.auto,
|
||||
}) => searchWordCountWithDbConnection(this, word, searchMode: searchMode);
|
||||
|
||||
/// Given a list of radicals, search which kanji contains all
|
||||
|
||||
@@ -15,15 +15,15 @@ SearchMode _determineSearchMode(String word) {
|
||||
final bool containsAscii = RegExp(r'[A-Za-z]').hasMatch(word);
|
||||
|
||||
if (containsKanji && containsAscii) {
|
||||
return SearchMode.MixedKanji;
|
||||
return SearchMode.mixedKanji;
|
||||
} else if (containsKanji) {
|
||||
return SearchMode.Kanji;
|
||||
return SearchMode.kanji;
|
||||
} else if (containsAscii) {
|
||||
return SearchMode.English;
|
||||
return SearchMode.english;
|
||||
} else if (word.contains(hiraganaRegex) || word.contains(katakanaRegex)) {
|
||||
return SearchMode.Kana;
|
||||
return SearchMode.kana;
|
||||
} else {
|
||||
return SearchMode.MixedKana;
|
||||
return SearchMode.mixedKana;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ Future<List<ScoredEntryId>> fetchEntryIds(
|
||||
int? pageSize,
|
||||
int? offset,
|
||||
) async {
|
||||
if (searchMode == SearchMode.Auto) {
|
||||
if (searchMode == SearchMode.auto) {
|
||||
searchMode = _determineSearchMode(word);
|
||||
}
|
||||
|
||||
@@ -254,20 +254,20 @@ Future<List<ScoredEntryId>> fetchEntryIds(
|
||||
|
||||
late final List<ScoredEntryId> entryIds;
|
||||
switch (searchMode) {
|
||||
case SearchMode.Kanji:
|
||||
case SearchMode.kanji:
|
||||
entryIds = await _queryKanji(connection, word, pageSize, offset);
|
||||
break;
|
||||
|
||||
case SearchMode.Kana:
|
||||
case SearchMode.kana:
|
||||
entryIds = await _queryKana(connection, word, pageSize, offset);
|
||||
break;
|
||||
|
||||
case SearchMode.English:
|
||||
case SearchMode.english:
|
||||
entryIds = await _queryEnglish(connection, word, pageSize, offset);
|
||||
break;
|
||||
|
||||
case SearchMode.MixedKana:
|
||||
case SearchMode.MixedKanji:
|
||||
case SearchMode.mixedKana:
|
||||
case SearchMode.mixedKanji:
|
||||
default:
|
||||
throw UnimplementedError('Search mode $searchMode is not implemented');
|
||||
}
|
||||
@@ -280,7 +280,7 @@ Future<int?> fetchEntryIdCount(
|
||||
String word,
|
||||
SearchMode searchMode,
|
||||
) async {
|
||||
if (searchMode == SearchMode.Auto) {
|
||||
if (searchMode == SearchMode.auto) {
|
||||
searchMode = _determineSearchMode(word);
|
||||
}
|
||||
|
||||
@@ -289,20 +289,20 @@ Future<int?> fetchEntryIdCount(
|
||||
late final int? entryIdCount;
|
||||
|
||||
switch (searchMode) {
|
||||
case SearchMode.Kanji:
|
||||
case SearchMode.kanji:
|
||||
entryIdCount = await _queryKanjiCount(connection, word);
|
||||
break;
|
||||
|
||||
case SearchMode.Kana:
|
||||
case SearchMode.kana:
|
||||
entryIdCount = await _queryKanaCount(connection, word);
|
||||
break;
|
||||
|
||||
case SearchMode.English:
|
||||
case SearchMode.english:
|
||||
entryIdCount = await _queryEnglishCount(connection, word);
|
||||
break;
|
||||
|
||||
case SearchMode.MixedKana:
|
||||
case SearchMode.MixedKanji:
|
||||
case SearchMode.mixedKana:
|
||||
case SearchMode.mixedKanji:
|
||||
default:
|
||||
throw UnimplementedError('Search mode $searchMode is not implemented');
|
||||
}
|
||||
|
||||
@@ -13,13 +13,31 @@ import 'package:jadb/search/word_search/regrouping.dart';
|
||||
import 'package:jadb/table_names/jmdict.dart';
|
||||
import 'package:sqflite_common/sqlite_api.dart';
|
||||
|
||||
enum SearchMode { Auto, English, Kanji, MixedKanji, Kana, MixedKana }
|
||||
enum SearchMode {
|
||||
/// Try to autodetect what is being searched for
|
||||
auto,
|
||||
|
||||
/// Search for english words
|
||||
english,
|
||||
|
||||
/// Search for the kanji reading of a word
|
||||
kanji,
|
||||
|
||||
/// Search for the kanji reading of a word, mixed in with kana/romaji
|
||||
mixedKanji,
|
||||
|
||||
/// Search for the kana reading of a word
|
||||
kana,
|
||||
|
||||
/// Search for the kana reading of a word, mixed in with romaji
|
||||
mixedKana,
|
||||
}
|
||||
|
||||
/// Searches for an input string, returning a list of results with their details. Returns null if the input string is empty.
|
||||
Future<List<WordSearchResult>?> searchWordWithDbConnection(
|
||||
DatabaseExecutor connection,
|
||||
String word, {
|
||||
SearchMode searchMode = SearchMode.Auto,
|
||||
SearchMode searchMode = SearchMode.auto,
|
||||
int page = 0,
|
||||
int? pageSize,
|
||||
}) async {
|
||||
@@ -63,7 +81,7 @@ Future<List<WordSearchResult>?> searchWordWithDbConnection(
|
||||
Future<int?> searchWordCountWithDbConnection(
|
||||
DatabaseExecutor connection,
|
||||
String word, {
|
||||
SearchMode searchMode = SearchMode.Auto,
|
||||
SearchMode searchMode = SearchMode.auto,
|
||||
}) async {
|
||||
if (word.isEmpty) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user