Squash merge feature/fts into master

This commit is contained in:
2025-04-23 14:51:24 +02:00
parent 5ea62a1216
commit 9d39cb09df
3 changed files with 496 additions and 43 deletions

View File

@@ -3,8 +3,10 @@ import 'package:journaler/db.dart';
class Note {
final String date;
String content;
String?
snippet; // Optional field to hold highlighted snippets for search results
Note({required this.date, required this.content});
Note({required this.date, required this.content, this.snippet});
}
class Scratch {
@@ -100,3 +102,25 @@ Future<Note?> getNextNote(String currentDate) async {
// This handles the case where the `currentDate` might not be the absolute latest.
return getLatestNote();
}
// Search notes using full-text search
Future<List<Note>> searchNotes(String query) async {
if (query.isEmpty) {
return [];
}
// Call DB search function
final List<Map<String, dynamic>> results = await DB.searchNotes(query);
// Convert results to Note objects
return results
.map(
(result) => Note(
date: result['date'] as String,
content: result['content'] as String,
snippet:
result['snippet'] as String?, // Highlighted snippets from FTS
),
)
.toList();
}