diff --git a/lib/src/index.dart b/lib/src/index.dart index 5d224344..5a6fbe43 100644 --- a/lib/src/index.dart +++ b/lib/src/index.dart @@ -42,7 +42,7 @@ abstract class MeiliSearchIndex { }); /// Return the document in the index by given [id]. - Future?> getDocument(dynamic id); + Future?> getDocument(dynamic id, { List fields }); /// Return a list of all existing documents in the index. Future getDocuments({DocumentsQuery? params}); diff --git a/lib/src/index_impl.dart b/lib/src/index_impl.dart index ebc7ac32..18c0a834 100644 --- a/lib/src/index_impl.dart +++ b/lib/src/index_impl.dart @@ -199,9 +199,11 @@ class MeiliSearchIndexImpl implements MeiliSearchIndex { } @override - Future?> getDocument(id) async { + Future?> getDocument(id, { List fields: const [] }) async { + final params = DocumentsQuery(fields: fields); final response = await http.getMethod>( '/indexes/$uid/documents/$id', + queryParameters: params.toQuery() ); return response.data; diff --git a/test/documents_test.dart b/test/documents_test.dart index 3a41639d..828a069f 100644 --- a/test/documents_test.dart +++ b/test/documents_test.dart @@ -78,5 +78,13 @@ void main() { expect(docs.results[0]['book_id'], isNotNull); expect(docs.results[0]['title'], isNull); }); + + test('Get document with fields', () async { + final index = await createBooksIndex(); + final doc = await index.getDocument(1, fields: ['book_id']); + + expect(doc?['book_id'], isNotNull); + expect(doc?['title'], isNull); + }); }); }