Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify tasks #185

Merged
merged 4 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:meilisearch/src/query_parameters/tasks_query.dart';
import 'package:meilisearch/src/result.dart';
import 'package:meilisearch/src/result_task.dart';
import 'package:meilisearch/src/task.dart';
import 'package:meilisearch/src/task_info.dart';

import 'http_request.dart';
import 'index.dart';
Expand Down Expand Up @@ -46,13 +45,13 @@ abstract class MeiliSearchClient {

/// Create a new index by given [uid] and optional [primaryKey] parameter.
/// Throws an error if index is already exists.
Future<TaskInfo> createIndex(String uid, {String primaryKey});
Future<Task> createIndex(String uid, {String primaryKey});

/// Delete the index by matching [uid].
Future<TaskInfo> deleteIndex(String uid);
Future<Task> deleteIndex(String uid);

/// Update the primary Key of the index by matching [uid].
Future<TaskInfo> updateIndex(String uid, String primaryKey);
Future<Task> updateIndex(String uid, String primaryKey);

/// Return health of the Meilisearch server.
/// Throws an error if containing details if Meilisearch can't process your request.
Expand Down
15 changes: 7 additions & 8 deletions lib/src/client_impl.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import 'package:dio/dio.dart';
import 'package:meilisearch/src/client_task_impl.dart';
import 'package:meilisearch/src/query_parameters/indexes_query.dart';
import 'package:meilisearch/src/query_parameters/keys_query.dart';
import 'package:meilisearch/src/query_parameters/tasks_query.dart';
import 'package:meilisearch/src/result.dart';
import 'package:meilisearch/src/result_task.dart';
import 'package:meilisearch/src/task.dart';
import 'package:meilisearch/src/task_info.dart';
import 'package:meilisearch/src/tenant_token.dart';

import 'http_request.dart';
Expand Down Expand Up @@ -38,14 +36,14 @@ class MeiliSearchClientImpl implements MeiliSearchClient {
return new MeiliSearchIndexImpl(this, uid);
}

Future<TaskInfo> _update(Future<Response> future) async {
Future<Task> _update(Future<Response> future) async {
final response = await future;

return ClientTaskImpl.fromMap(this, response.data);
return Task.fromMap(response.data);
}

@override
Future<TaskInfo> createIndex(String uid, {String? primaryKey}) async {
Future<Task> createIndex(String uid, {String? primaryKey}) async {
final data = <String, dynamic>{
'uid': uid,
if (primaryKey != null) 'primaryKey': primaryKey,
Expand Down Expand Up @@ -84,14 +82,14 @@ class MeiliSearchClientImpl implements MeiliSearchClient {
}

@override
Future<TaskInfo> deleteIndex(String uid) async {
Future<Task> deleteIndex(String uid) async {
final index = this.index(uid);

return await index.delete();
}

@override
Future<TaskInfo> updateIndex(String uid, String primaryKey) async {
Future<Task> updateIndex(String uid, String primaryKey) async {
final index = this.index(uid);

return index.update(primaryKey: primaryKey);
Expand Down Expand Up @@ -132,7 +130,8 @@ class MeiliSearchClientImpl implements MeiliSearchClient {

@override
Future<Key> getKey(String keyOrUid) async {
final response = await http.getMethod<Map<String, dynamic>>('/keys/${keyOrUid}');
final response =
await http.getMethod<Map<String, dynamic>>('/keys/${keyOrUid}');

return Key.fromJson(response.data!);
}
Expand Down
22 changes: 0 additions & 22 deletions lib/src/client_task_impl.dart

This file was deleted.

53 changes: 25 additions & 28 deletions lib/src/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:meilisearch/src/result_task.dart';

import 'index_settings.dart';

import 'task_info.dart';
import 'search_result.dart';
import 'stats.dart' show IndexStats;
import 'task.dart';
Expand All @@ -19,10 +18,10 @@ abstract class MeiliSearchIndex {
set primaryKey(String? primaryKey);

/// Update the primary Key of the index.
Future<TaskInfo> update({String primaryKey});
Future<Task> update({String primaryKey});

/// Delete the index.
Future<TaskInfo> delete();
Future<Task> delete();

/// Search for documents matching a specific query in the index.
Future<SearchResult> search(
Expand Down Expand Up @@ -50,26 +49,26 @@ abstract class MeiliSearchIndex {

/// Add a list of documents by given [documents] and optional [primaryKey] parameter.
/// If index is not exists tries to create a new index and adds documents.
Future<TaskInfo> addDocuments(
Future<Task> addDocuments(
List<Map<String, dynamic>> documents, {
String? primaryKey,
});

/// Add a list of documents or update them if they already exist by given [documents] and optional [primaryKey] parameter.
/// If index is not exists tries to create a new index and adds documents.
Future<TaskInfo> updateDocuments(
Future<Task> updateDocuments(
List<Map<String, dynamic>> documents, {
String? primaryKey,
});

/// Delete one document by given [id].
Future<TaskInfo> deleteDocument(dynamic id);
Future<Task> deleteDocument(dynamic id);

/// Delete all documents in the specified index.
Future<TaskInfo> deleteAllDocuments();
Future<Task> deleteAllDocuments();

/// Delete a selection of documents by given [ids].
Future<TaskInfo> deleteDocuments(List<dynamic> ids);
Future<Task> deleteDocuments(List<dynamic> ids);

/// Get the settings of the index.
Future<IndexSettings> getSettings();
Expand All @@ -78,82 +77,80 @@ abstract class MeiliSearchIndex {
Future<List<String>> getFilterableAttributes();

/// Reset filterable attributes of the index.
Future<TaskInfo> resetFilterableAttributes();
Future<Task> resetFilterableAttributes();

/// Update filterable attributes of the index.
Future<TaskInfo> updateFilterableAttributes(
List<String> filterableAttributes);
Future<Task> updateFilterableAttributes(List<String> filterableAttributes);

/// Get the displayed attributes of the index.
Future<List<String>> getDisplayedAttributes();

/// Reset the displayed attributes of the index.
Future<TaskInfo> resetDisplayedAttributes();
Future<Task> resetDisplayedAttributes();

/// Update the displayed attributes of the index.
Future<TaskInfo> updateDisplayedAttributes(List<String> displayedAttributes);
Future<Task> updateDisplayedAttributes(List<String> displayedAttributes);

/// Get the distinct attribute for the index.
Future<String?> getDistinctAttribute();

/// Reset the distinct attribute for the index.
Future<TaskInfo> resetDistinctAttribute();
Future<Task> resetDistinctAttribute();

/// Update the distinct attribute for the index.
Future<TaskInfo> updateDistinctAttribute(String distinctAttribute);
Future<Task> updateDistinctAttribute(String distinctAttribute);

/// Get ranking rules of the index.
Future<List<String>> getRankingRules();

/// Reset ranking rules of the index.
Future<TaskInfo> resetRankingRules();
Future<Task> resetRankingRules();

/// Update ranking rules of the index.
Future<TaskInfo> updateRankingRules(List<String> rankingRules);
Future<Task> updateRankingRules(List<String> rankingRules);

/// Get searchable attributes of the index.
Future<List<String>> getSearchableAttributes();

/// Reset searchable attributes of the index.
Future<TaskInfo> resetSearchableAttributes();
Future<Task> resetSearchableAttributes();

/// Update the searchable attributes of the index.
Future<TaskInfo> updateSearchableAttributes(
List<String> searchableAttributes);
Future<Task> updateSearchableAttributes(List<String> searchableAttributes);

/// Get stop words of the index.
Future<List<String>> getStopWords();

/// Reset stop words of the index.
Future<TaskInfo> resetStopWords();
Future<Task> resetStopWords();

/// Update stop words of the index
Future<TaskInfo> updateStopWords(List<String> stopWords);
Future<Task> updateStopWords(List<String> stopWords);

/// Get synonyms of the index.
Future<Map<String, List<String>>> getSynonyms();

/// Reset synonyms of the index.
Future<TaskInfo> resetSynonyms();
Future<Task> resetSynonyms();

/// Update synonyms of the index
Future<TaskInfo> updateSynonyms(Map<String, List<String>> synonyms);
Future<Task> updateSynonyms(Map<String, List<String>> synonyms);

/// Get sortable attributes of the index.
Future<List<String>> getSortableAttributes();

/// Reset sortable attributes of the index.
Future<TaskInfo> resetSortableAttributes();
Future<Task> resetSortableAttributes();

/// Update sortable attributes of the index.
Future<TaskInfo> updateSortableAttributes(List<String> sortableAttributes);
Future<Task> updateSortableAttributes(List<String> sortableAttributes);

/// Reset the settings of the index.
/// All settings will be reset to their default value.
Future<TaskInfo> resetSettings();
Future<Task> resetSettings();

/// Update the settings of the index. Any parameters not provided in the body will be left unchanged.
Future<TaskInfo> updateSettings(IndexSettings settings);
Future<Task> updateSettings(IndexSettings settings);

/// Get the information of the index from the Meilisearch server and return it.
Future<MeiliSearchIndex> fetchInfo();
Expand Down
Loading