This commit is contained in:
randogoth 2025-02-20 22:40:41 +02:00
commit 84c134adc4
131 changed files with 5489 additions and 0 deletions

21
lib/search_service.dart Normal file
View file

@ -0,0 +1,21 @@
import 'dart:io';
class SearchService {
static List<File> searchNotes(String query, List<File> notes) {
if (query.isEmpty) return notes;
final lowerQuery = query.toLowerCase();
return notes.where((note) {
final fileName = note.uri.pathSegments.last.replaceAll('.md', '').toLowerCase();
final content = note.readAsStringSync().toLowerCase();
// Fuzzy search: Match if all words in the query are found in either the title or content
return _matchesFuzzy(lowerQuery, fileName) || _matchesFuzzy(lowerQuery, content);
}).toList();
}
static bool _matchesFuzzy(String query, String text) {
final words = query.split(RegExp(r'\s+')).where((word) => word.isNotEmpty);
return words.every((word) => text.contains(word));
}
}