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