Fix settings by making key filterable in meilisearc

This commit is contained in:
2025-05-25 10:05:48 +02:00
parent d78db03d5d
commit 27f21a23fe
3 changed files with 22 additions and 23 deletions

View File

@@ -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);
if (hits.isEmpty) {
final responseJson = jsonDecode(response.body);
final documents = List<Map<String, dynamic>>.from(responseJson['results']);
if (documents.isEmpty) {
break;
}
allDocuments.addAll(hits);
allDocuments.addAll(documents);
print('Found ${allDocuments.length} documents so far in $index');
if (documents.length < limit) {
break;
}
offset += limit;
if (hits.length < limit) {
break;
}
}
print('Total documents found in $index: ${allDocuments.length}');
return allDocuments;
}