Fix settings by making key filterable in meilisearc
This commit is contained in:
@@ -2,7 +2,6 @@ import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:journaler/db.dart';
|
||||
import 'package:journaler/notes.dart';
|
||||
import 'package:journaler/utils.dart';
|
||||
import 'package:system_tray/system_tray.dart';
|
||||
|
@@ -97,39 +97,34 @@ Future<List<Map<String, dynamic>>> getAllDocuments(String index) async {
|
||||
final headers = await _getHeaders();
|
||||
final allDocuments = <Map<String, dynamic>>[];
|
||||
var offset = 0;
|
||||
const limit = 100; // Process in batches of 100
|
||||
const limit = 100;
|
||||
|
||||
while (true) {
|
||||
final searchCondition = MeilisearchQuery(
|
||||
q: '',
|
||||
limit: limit,
|
||||
offset: offset,
|
||||
);
|
||||
final response = await http.post(
|
||||
Uri.parse('$endpoint/indexes/$index/search'),
|
||||
final response = await http.get(
|
||||
Uri.parse('$endpoint/indexes/$index/documents?limit=$limit&offset=$offset'),
|
||||
headers: headers,
|
||||
body: jsonEncode(searchCondition.toJson()),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Failed to get documents: ${response.statusCode}');
|
||||
}
|
||||
final responseJson = MeilisearchResponse.fromJson(
|
||||
jsonDecode(response.body),
|
||||
);
|
||||
final hits = List<Map<String, dynamic>>.from(responseJson.hits);
|
||||
final responseJson = jsonDecode(response.body);
|
||||
final documents = List<Map<String, dynamic>>.from(responseJson['results']);
|
||||
|
||||
if (hits.isEmpty) {
|
||||
if (documents.isEmpty) {
|
||||
break;
|
||||
}
|
||||
|
||||
allDocuments.addAll(documents);
|
||||
print('Found ${allDocuments.length} documents so far in $index');
|
||||
|
||||
if (documents.length < limit) {
|
||||
break;
|
||||
}
|
||||
|
||||
allDocuments.addAll(hits);
|
||||
offset += limit;
|
||||
|
||||
if (hits.length < limit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
print('Total documents found in $index: ${allDocuments.length}');
|
||||
return allDocuments;
|
||||
}
|
||||
|
||||
|
@@ -142,6 +142,11 @@ Future<void> init() async {
|
||||
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 {
|
||||
|
Reference in New Issue
Block a user