Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
7ba188eb6c | |||
188619478e | |||
27f21a23fe | |||
d78db03d5d | |||
df93602db4 | |||
d6f9fa5032 | |||
64884cbb42 |
150
lib/main.dart
150
lib/main.dart
@@ -2,7 +2,6 @@ import 'dart:async';
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:journaler/db.dart';
|
|
||||||
import 'package:journaler/notes.dart';
|
import 'package:journaler/notes.dart';
|
||||||
import 'package:journaler/utils.dart';
|
import 'package:journaler/utils.dart';
|
||||||
import 'package:system_tray/system_tray.dart';
|
import 'package:system_tray/system_tray.dart';
|
||||||
@@ -309,11 +308,13 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
final TextEditingController _intervalController = TextEditingController();
|
final TextEditingController _intervalController = TextEditingController();
|
||||||
final TextEditingController _soundController = TextEditingController();
|
final TextEditingController _soundController = TextEditingController();
|
||||||
final TextEditingController _searchController = TextEditingController();
|
final TextEditingController _searchController = TextEditingController();
|
||||||
|
final FocusNode _keyboardListenerFocusNode = FocusNode(); // Add persistent focus node
|
||||||
|
|
||||||
Note? previousNote;
|
Note? previousNote;
|
||||||
Note? _currentlyDisplayedNote;
|
Note? _currentlyDisplayedNote;
|
||||||
Duration _currentPopupInterval = _defaultPopupInterval;
|
Duration _currentPopupInterval = _defaultPopupInterval;
|
||||||
String _currentNotificationSound = _defaultNotificationSound;
|
String _currentNotificationSound = _defaultNotificationSound;
|
||||||
|
String? _originalScratchContent; // Track original scratch content
|
||||||
|
|
||||||
bool _canGoPrevious = false;
|
bool _canGoPrevious = false;
|
||||||
bool _canGoNext = false;
|
bool _canGoNext = false;
|
||||||
@@ -359,6 +360,7 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
_previousEntryController.dispose();
|
_previousEntryController.dispose();
|
||||||
_currentEntryController.dispose();
|
_currentEntryController.dispose();
|
||||||
_currentEntryFocusNode.dispose();
|
_currentEntryFocusNode.dispose();
|
||||||
|
_keyboardListenerFocusNode.dispose(); // Dispose the keyboard listener focus node
|
||||||
_scratchController.dispose();
|
_scratchController.dispose();
|
||||||
_intervalController.dispose();
|
_intervalController.dispose();
|
||||||
_soundController.dispose();
|
_soundController.dispose();
|
||||||
@@ -424,13 +426,16 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
await windowManager.setSize(const Size(1600, 900));
|
await windowManager.setSize(const Size(1600, 900));
|
||||||
await windowManager.center();
|
await windowManager.center();
|
||||||
|
|
||||||
// Now show and focus
|
// Show and focus immediately
|
||||||
await windowManager.show();
|
await windowManager.show();
|
||||||
await Future.delayed(const Duration(milliseconds: 100)); // Short delay
|
|
||||||
await windowManager.focus();
|
await windowManager.focus();
|
||||||
|
|
||||||
// Set input focus
|
// Set input focus with a post-frame callback to ensure it sticks
|
||||||
_currentEntryFocusNode.requestFocus();
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (mounted) {
|
||||||
|
_currentEntryFocusNode.requestFocus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Play notification sound
|
// Play notification sound
|
||||||
await _playSound();
|
await _playSound();
|
||||||
@@ -439,7 +444,11 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
} else {
|
} else {
|
||||||
// Already visible, just focus
|
// Already visible, just focus
|
||||||
await windowManager.focus();
|
await windowManager.focus();
|
||||||
_currentEntryFocusNode.requestFocus();
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (mounted) {
|
||||||
|
_currentEntryFocusNode.requestFocus();
|
||||||
|
}
|
||||||
|
});
|
||||||
debugPrint("Window already visible, just focused");
|
debugPrint("Window already visible, just focused");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -507,8 +516,10 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
|
|
||||||
// Save the current note content before navigating away
|
// Save the current note content before navigating away
|
||||||
if (_currentlyDisplayedNote != null) {
|
if (_currentlyDisplayedNote != null) {
|
||||||
_currentlyDisplayedNote!.content = _previousEntryController.text;
|
if (_currentlyDisplayedNote!.content != _previousEntryController.text) {
|
||||||
await updateNote(_currentlyDisplayedNote!);
|
_currentlyDisplayedNote!.content = _previousEntryController.text;
|
||||||
|
await updateNote(_currentlyDisplayedNote!);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final prevNote = await getPreviousTo(_currentlyDisplayedNote!.epochTime);
|
final prevNote = await getPreviousTo(_currentlyDisplayedNote!.epochTime);
|
||||||
@@ -526,8 +537,10 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
|
|
||||||
// Save the current note content before navigating away
|
// Save the current note content before navigating away
|
||||||
if (_currentlyDisplayedNote != null) {
|
if (_currentlyDisplayedNote != null) {
|
||||||
_currentlyDisplayedNote!.content = _previousEntryController.text;
|
if (_currentlyDisplayedNote!.content != _previousEntryController.text) {
|
||||||
await updateNote(_currentlyDisplayedNote!);
|
_currentlyDisplayedNote!.content = _previousEntryController.text;
|
||||||
|
await updateNote(_currentlyDisplayedNote!);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final nextNote = await getNextTo(_currentlyDisplayedNote!.epochTime);
|
final nextNote = await getNextTo(_currentlyDisplayedNote!.epochTime);
|
||||||
@@ -559,6 +572,7 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
|
|
||||||
final scratch = await getLatestScratch();
|
final scratch = await getLatestScratch();
|
||||||
_scratchController.text = scratch?.content ?? "";
|
_scratchController.text = scratch?.content ?? "";
|
||||||
|
_originalScratchContent = scratch?.content; // Store original content
|
||||||
|
|
||||||
await _checkNavigation();
|
await _checkNavigation();
|
||||||
|
|
||||||
@@ -593,13 +607,18 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
_currentEntryController.clear(); // Clear the input field after saving
|
_currentEntryController.clear(); // Clear the input field after saving
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle scratch pad
|
// Only create new scratch if content has changed
|
||||||
await createScratch(scratchContent);
|
if (scratchContent != _originalScratchContent) {
|
||||||
|
await createScratch(scratchContent);
|
||||||
|
_originalScratchContent = scratchContent; // Update original content
|
||||||
|
}
|
||||||
|
|
||||||
// Handle previous/currently displayed note
|
// Handle previous/currently displayed note
|
||||||
if (_currentlyDisplayedNote != null) {
|
if (_currentlyDisplayedNote != null) {
|
||||||
_currentlyDisplayedNote!.content = previousEntry;
|
if (_currentlyDisplayedNote!.content != previousEntry) {
|
||||||
await updateNote(_currentlyDisplayedNote!);
|
_currentlyDisplayedNote!.content = previousEntry;
|
||||||
|
await updateNote(_currentlyDisplayedNote!);
|
||||||
|
}
|
||||||
|
|
||||||
// If the note was deleted (due to being empty), update the UI state
|
// If the note was deleted (due to being empty), update the UI state
|
||||||
if (previousEntry.isEmpty) {
|
if (previousEntry.isEmpty) {
|
||||||
@@ -662,9 +681,7 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
spans.add(
|
spans.add(
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: highlightedText.substring(lastIndex, match.start),
|
text: highlightedText.substring(lastIndex, match.start),
|
||||||
style: const TextStyle(
|
style: const TextStyle(fontSize: 13),
|
||||||
fontSize: 13,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -825,11 +842,18 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
// Save current note if needed
|
// Save current note if needed
|
||||||
if (_currentlyDisplayedNote !=
|
if (_currentlyDisplayedNote !=
|
||||||
null) {
|
null) {
|
||||||
_currentlyDisplayedNote!.content =
|
if (_currentlyDisplayedNote!
|
||||||
_previousEntryController.text;
|
.content !=
|
||||||
await updateNote(
|
_previousEntryController
|
||||||
_currentlyDisplayedNote!,
|
.text) {
|
||||||
);
|
_currentlyDisplayedNote!
|
||||||
|
.content =
|
||||||
|
_previousEntryController
|
||||||
|
.text;
|
||||||
|
await updateNote(
|
||||||
|
_currentlyDisplayedNote!,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Navigate to the selected note
|
// Navigate to the selected note
|
||||||
@@ -1107,19 +1131,23 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
String? errorMessage;
|
String? errorMessage;
|
||||||
|
|
||||||
// Load current values
|
// Load current values
|
||||||
getMeilisearchEndpoint().then((value) {
|
getMeilisearchEndpoint()
|
||||||
endpointController.text = value;
|
.then((value) {
|
||||||
isLoading = false;
|
endpointController.text = value;
|
||||||
}).catchError((e) {
|
isLoading = false;
|
||||||
errorMessage = 'Failed to load endpoint: $e';
|
})
|
||||||
isLoading = false;
|
.catchError((e) {
|
||||||
});
|
errorMessage = 'Failed to load endpoint: $e';
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
|
|
||||||
getMeilisearchApiKey().then((value) {
|
getMeilisearchApiKey()
|
||||||
apiKeyController.text = value;
|
.then((value) {
|
||||||
}).catchError((e) {
|
apiKeyController.text = value;
|
||||||
errorMessage = 'Failed to load API key: $e';
|
})
|
||||||
});
|
.catchError((e) {
|
||||||
|
errorMessage = 'Failed to load API key: $e';
|
||||||
|
});
|
||||||
|
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
@@ -1168,29 +1196,34 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
child: const Text('Cancel'),
|
child: const Text('Cancel'),
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: isLoading ? null : () async {
|
onPressed:
|
||||||
try {
|
isLoading
|
||||||
setState(() {
|
? null
|
||||||
isLoading = true;
|
: () async {
|
||||||
errorMessage = null;
|
try {
|
||||||
});
|
setState(() {
|
||||||
|
isLoading = true;
|
||||||
|
errorMessage = null;
|
||||||
|
});
|
||||||
|
|
||||||
await setMeilisearchEndpoint(endpointController.text);
|
await setMeilisearchEndpoint(
|
||||||
await setMeilisearchApiKey(apiKeyController.text);
|
endpointController.text,
|
||||||
|
);
|
||||||
|
await setMeilisearchApiKey(apiKeyController.text);
|
||||||
|
|
||||||
// Try to reinitialize Meilisearch with new settings
|
// Try to reinitialize Meilisearch with new settings
|
||||||
await init();
|
await init();
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setState(() {
|
setState(() {
|
||||||
errorMessage = 'Failed to save settings: $e';
|
errorMessage = 'Failed to save settings: $e';
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: const Text('Save'),
|
child: const Text('Save'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -1205,9 +1238,7 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Wrap Scaffold with RawKeyboardListener as workaround for Escape key
|
// Wrap Scaffold with RawKeyboardListener as workaround for Escape key
|
||||||
return RawKeyboardListener(
|
return RawKeyboardListener(
|
||||||
focusNode:
|
focusNode: _keyboardListenerFocusNode, // Use persistent focus node
|
||||||
FocusNode()
|
|
||||||
..requestFocus(), // Request focus to ensure keyboard events are captured
|
|
||||||
onKey: (RawKeyEvent event) {
|
onKey: (RawKeyEvent event) {
|
||||||
if (event is RawKeyDownEvent) {
|
if (event is RawKeyDownEvent) {
|
||||||
// Handle Escape to close window
|
// Handle Escape to close window
|
||||||
@@ -1216,8 +1247,7 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
"Escape pressed inside MainPage (RawKeyboardListener - Workaround)",
|
"Escape pressed inside MainPage (RawKeyboardListener - Workaround)",
|
||||||
);
|
);
|
||||||
// Call method directly since we are in the state
|
// Call method directly since we are in the state
|
||||||
FocusManager.instance.primaryFocus
|
FocusManager.instance.primaryFocus?.unfocus(); // Keep unfocus attempt
|
||||||
?.unfocus(); // Keep unfocus attempt
|
|
||||||
onWindowClose();
|
onWindowClose();
|
||||||
}
|
}
|
||||||
// Handle Ctrl+F to open search
|
// Handle Ctrl+F to open search
|
||||||
|
220
lib/meilifix.dart
Normal file
220
lib/meilifix.dart
Normal file
@@ -0,0 +1,220 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:core';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:journaler/meilisearch_config.dart';
|
||||||
|
|
||||||
|
const noteIndex = 'notes';
|
||||||
|
const scratchIndex = 'scratch';
|
||||||
|
final alphanum = RegExp(r'[a-zA-Z0-9]', caseSensitive: false);
|
||||||
|
|
||||||
|
class MeilisearchQuery {
|
||||||
|
String q;
|
||||||
|
String? filter;
|
||||||
|
int? limit;
|
||||||
|
int? offset;
|
||||||
|
bool? showRankingScore;
|
||||||
|
double? rankingScoreThreshold;
|
||||||
|
String? highlightPreTag;
|
||||||
|
String? highlightPostTag;
|
||||||
|
List<String>? attributesToHighlight;
|
||||||
|
List<String>? sort;
|
||||||
|
|
||||||
|
MeilisearchQuery({
|
||||||
|
required this.q,
|
||||||
|
this.filter,
|
||||||
|
this.sort,
|
||||||
|
this.limit,
|
||||||
|
this.offset,
|
||||||
|
this.showRankingScore,
|
||||||
|
this.rankingScoreThreshold,
|
||||||
|
this.highlightPreTag,
|
||||||
|
this.highlightPostTag,
|
||||||
|
this.attributesToHighlight,
|
||||||
|
});
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> json = {'q': q};
|
||||||
|
if (filter != null) json['filter'] = filter;
|
||||||
|
if (sort != null) json['sort'] = sort;
|
||||||
|
if (limit != null) json['limit'] = limit;
|
||||||
|
if (offset != null) json['offset'] = offset;
|
||||||
|
if (showRankingScore != null) json['showRankingScore'] = showRankingScore;
|
||||||
|
if (rankingScoreThreshold != null) {
|
||||||
|
json['rankingScoreThreshold'] = rankingScoreThreshold;
|
||||||
|
}
|
||||||
|
if (highlightPreTag != null) json['highlightPreTag'] = highlightPreTag;
|
||||||
|
if (highlightPostTag != null) json['highlightPostTag'] = highlightPostTag;
|
||||||
|
if (attributesToHighlight != null) {
|
||||||
|
json['attributesToHighlight'] = attributesToHighlight;
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MeilisearchResponse {
|
||||||
|
final List<dynamic> hits;
|
||||||
|
final String query;
|
||||||
|
final int processingTimeMs;
|
||||||
|
final int limit;
|
||||||
|
final int offset;
|
||||||
|
final int estimatedTotalHits;
|
||||||
|
|
||||||
|
MeilisearchResponse({
|
||||||
|
required this.hits,
|
||||||
|
required this.query,
|
||||||
|
required this.processingTimeMs,
|
||||||
|
required this.limit,
|
||||||
|
required this.offset,
|
||||||
|
required this.estimatedTotalHits,
|
||||||
|
});
|
||||||
|
|
||||||
|
static MeilisearchResponse fromJson(Map<String, dynamic> json) {
|
||||||
|
return MeilisearchResponse(
|
||||||
|
hits: json['hits'],
|
||||||
|
query: json['query'],
|
||||||
|
processingTimeMs: json['processingTimeMs'],
|
||||||
|
limit: json['limit'],
|
||||||
|
offset: json['offset'],
|
||||||
|
estimatedTotalHits: json['estimatedTotalHits'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Map<String, String>> _getHeaders() async {
|
||||||
|
final apiKey = await getMeilisearchApiKey();
|
||||||
|
return {
|
||||||
|
'Authorization': 'Bearer $apiKey',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<String> _getEndpoint() async {
|
||||||
|
return await getMeilisearchEndpoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<Map<String, dynamic>>> getAllDocuments(String index) async {
|
||||||
|
final endpoint = await _getEndpoint();
|
||||||
|
final headers = await _getHeaders();
|
||||||
|
final allDocuments = <Map<String, dynamic>>[];
|
||||||
|
var offset = 0;
|
||||||
|
const limit = 100;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
final response = await http.get(
|
||||||
|
Uri.parse('$endpoint/indexes/$index/documents?limit=$limit&offset=$offset'),
|
||||||
|
headers: headers,
|
||||||
|
);
|
||||||
|
if (response.statusCode != 200) {
|
||||||
|
throw Exception('Failed to get documents: ${response.statusCode}');
|
||||||
|
}
|
||||||
|
final responseJson = jsonDecode(response.body);
|
||||||
|
final documents = List<Map<String, dynamic>>.from(responseJson['results']);
|
||||||
|
|
||||||
|
if (documents.isEmpty) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
allDocuments.addAll(documents);
|
||||||
|
print('Found ${allDocuments.length} documents so far in $index');
|
||||||
|
|
||||||
|
if (documents.length < limit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
offset += limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
print('Total documents found in $index: ${allDocuments.length}');
|
||||||
|
return allDocuments;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> fixDocument(Map<String, dynamic> doc) {
|
||||||
|
final content = doc['content'] as String;
|
||||||
|
final date = doc['date'] as int;
|
||||||
|
|
||||||
|
// Calculate letter frequency
|
||||||
|
final letterFrequency = <String, int>{};
|
||||||
|
for (final char in content.split('')) {
|
||||||
|
if (alphanum.hasMatch(char)) {
|
||||||
|
letterFrequency[char] = (letterFrequency[char] ?? 0) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final mostFrequentLetter =
|
||||||
|
letterFrequency.entries.isEmpty
|
||||||
|
? 'a'
|
||||||
|
: letterFrequency.entries
|
||||||
|
.reduce((a, b) => a.value > b.value ? a : b)
|
||||||
|
.key;
|
||||||
|
|
||||||
|
final mostFrequentLetterCount =
|
||||||
|
letterFrequency.isEmpty
|
||||||
|
? 0.0
|
||||||
|
: letterFrequency[mostFrequentLetter]! / content.length;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...doc,
|
||||||
|
'dateISO':
|
||||||
|
DateTime.fromMillisecondsSinceEpoch(date).toUtc().toIso8601String(),
|
||||||
|
'topLetter': mostFrequentLetter,
|
||||||
|
'topLetterFrequency': mostFrequentLetterCount,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> updateDocument(String index, Map<String, dynamic> doc) async {
|
||||||
|
final endpoint = await _getEndpoint();
|
||||||
|
final headers = await _getHeaders();
|
||||||
|
final response = await http.post(
|
||||||
|
Uri.parse('$endpoint/indexes/$index/documents'),
|
||||||
|
headers: headers,
|
||||||
|
body: jsonEncode(doc),
|
||||||
|
);
|
||||||
|
if (response.statusCode != 202) {
|
||||||
|
throw Exception('Failed to update document: ${response.statusCode}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> fixAllDocuments() async {
|
||||||
|
print('Fixing notes...');
|
||||||
|
final notes = await getAllDocuments(noteIndex);
|
||||||
|
final noteBatches = <List<Map<String, dynamic>>>[];
|
||||||
|
for (var i = 0; i < notes.length; i += 10) {
|
||||||
|
noteBatches.add(notes.skip(i).take(10).toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (final batch in noteBatches) {
|
||||||
|
await Future.wait(
|
||||||
|
batch.map((note) async {
|
||||||
|
final fixed = fixDocument(note);
|
||||||
|
await updateDocument(noteIndex, fixed);
|
||||||
|
print('Fixed note: ${note['id']}');
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
print('Fixing scratches...');
|
||||||
|
final scratches = await getAllDocuments(scratchIndex);
|
||||||
|
final scratchBatches = <List<Map<String, dynamic>>>[];
|
||||||
|
for (var i = 0; i < scratches.length; i += 10) {
|
||||||
|
scratchBatches.add(scratches.skip(i).take(10).toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (final batch in scratchBatches) {
|
||||||
|
await Future.wait(
|
||||||
|
batch.map((scratch) async {
|
||||||
|
final fixed = fixDocument(scratch);
|
||||||
|
await updateDocument(scratchIndex, fixed);
|
||||||
|
print('Fixed scratch: ${scratch['id']}');
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
try {
|
||||||
|
await fixAllDocuments();
|
||||||
|
print('All documents fixed successfully!');
|
||||||
|
} catch (e) {
|
||||||
|
print('Error fixing documents: $e');
|
||||||
|
}
|
||||||
|
}
|
@@ -142,6 +142,11 @@ Future<void> init() async {
|
|||||||
body: jsonEncode({'uid': settingsIndex, 'primaryKey': 'key'}),
|
body: jsonEncode({'uid': settingsIndex, 'primaryKey': 'key'}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
await http.put(
|
||||||
|
Uri.parse('$endpoint/indexes/$settingsIndex/settings/filterable-attributes'),
|
||||||
|
headers: headers,
|
||||||
|
body: jsonEncode(['key', 'value']),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> indexExists(String index) async {
|
Future<bool> indexExists(String index) async {
|
||||||
@@ -345,11 +350,13 @@ Future<Note> createNote(String content) async {
|
|||||||
|
|
||||||
final mostFrequentLetter =
|
final mostFrequentLetter =
|
||||||
letterFrequency.entries.reduce((a, b) => a.value > b.value ? a : b).key;
|
letterFrequency.entries.reduce((a, b) => a.value > b.value ? a : b).key;
|
||||||
final mostFrequentLetterCount = letterFrequency[mostFrequentLetter];
|
final mostFrequentLetterCount =
|
||||||
|
letterFrequency[mostFrequentLetter]! / trimmedContent.length;
|
||||||
|
|
||||||
final document = {
|
final document = {
|
||||||
'id': generateRandomString(32),
|
'id': generateRandomString(32),
|
||||||
'date': DateTime.now().toUtc().millisecondsSinceEpoch,
|
'date': DateTime.now().toUtc().millisecondsSinceEpoch,
|
||||||
|
'dateISO': DateTime.now().toUtc().toIso8601String(),
|
||||||
'content': content,
|
'content': content,
|
||||||
'topLetter': mostFrequentLetter,
|
'topLetter': mostFrequentLetter,
|
||||||
'topLetterFrequency': mostFrequentLetterCount,
|
'topLetterFrequency': mostFrequentLetterCount,
|
||||||
@@ -433,6 +440,10 @@ Future<void> updateNote(Note note) async {
|
|||||||
'id': note.id,
|
'id': note.id,
|
||||||
'content': trimmedContent,
|
'content': trimmedContent,
|
||||||
'date': note.epochTime,
|
'date': note.epochTime,
|
||||||
|
'dateISO':
|
||||||
|
DateTime.fromMillisecondsSinceEpoch(
|
||||||
|
note.epochTime,
|
||||||
|
).toUtc().toIso8601String(),
|
||||||
'topLetter': mostFrequentLetter,
|
'topLetter': mostFrequentLetter,
|
||||||
'topLetterFrequency': mostFrequentLetterRatio,
|
'topLetterFrequency': mostFrequentLetterRatio,
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user