fastSearchExtension method
Fast search without debug overhead.
Optimized for performance with minimal overhead. Use when you don't need debug output or detailed field scoring.
Parameters are the same as smartSearchDynamicDetailedExtension except
debug is not available.
Implementation
Future<List<T>> fastSearchExtension({
required String query,
required Map<String, List<String>> searchFieldsMap,
required Map<String, dynamic> Function(T) toJson,
Map<String, double> fieldWeights = const {},
double minScore = 0.3,
int limit = 10,
bool useIsolate = true,
bool useDamerauLevenshtein = true,
bool useNGram = true,
}) async {
// Validate parameters
_validateSearchParameters(
query: query,
searchFieldsMap: searchFieldsMap,
minScore: minScore,
limit: limit,
);
// Validate field weights
for (final entry in fieldWeights.entries) {
if (entry.value < 0) {
throw SearchParameterException(
'Field weight for "${entry.key}" must be non-negative, got ${entry.value}',
);
}
if (!searchFieldsMap.containsKey(entry.key)) {
throw SearchParameterException(
'Field weight specified for "${entry.key}" but field not in searchFieldsMap',
);
}
}
final itemsJson = map((item) => toJson(item)).toList();
final params = DynamicSearchParams(
items: itemsJson,
query: query,
searchFieldsMap: searchFieldsMap,
fieldWeights: fieldWeights,
minScore: minScore,
limit: limit,
useDamerauLevenshtein: useDamerauLevenshtein,
useNGram: useNGram,
);
List<Map<String, dynamic>> results;
try {
if (useIsolate && length > SearchConstants.isolateThreshold) {
results = await compute(_isolateSearchWorker, params);
} else {
results = _dynamicSearchWorker(params);
}
} catch (e) {
rethrow;
}
// Super fast: just array access!
return results.map((result) {
final index = result['_index'] as int;
return this[index]; // ← O(1) lookup!
}).toList();
}