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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃殌 Feature: Add Sync with Meilisearch for Dart #188

Closed
6 tasks
gewenyu99 opened this issue Oct 1, 2023 · 9 comments
Closed
6 tasks

馃殌 Feature: Add Sync with Meilisearch for Dart #188

gewenyu99 opened this issue Oct 1, 2023 · 9 comments
Assignees
Labels
hacktoberfest Issues for Hacktoberfest 2023

Comments

@gewenyu99
Copy link

Appwrite Functions allow you to extend and customize your Appwrite server functionality by executing your custom code. 馃ぉ You can learn more at our official Appwrite Functions docs.

Your task is to implement the Sync with Meilisearch function in Dart. You can look at the existing Appwrite Functions Templates in another coding language.

Your function should behave and be implemented similarly to existing Sync with Meilisearch Node.js template.

Tasks summary:

  • Fork & clone Appwrite's templates repository
  • Create a branch feat-implement-sync-with-meilisearch-dart
  • Write code for the function in folder dart/sync_with_meilisearch/.
  • Test the function using Appwrite, provide a video.
  • Write a README.md explaining what the function does, how to use it, and customize it. Here is an example.
  • Submit a pull request to our templates repository

If you need any help, contact us on our Discord server.

Are you ready to work on this issue? 馃 Let us know, and we will assign it to you 馃槉

Happy Appwriting!

@gewenyu99 gewenyu99 added the hacktoberfest Issues for Hacktoberfest 2023 label Oct 1, 2023
@notpritam
Copy link

can you please assign this to me.. i would love to contribute on this...

@Haimantika
Copy link

can you please assign this to me.. i would love to contribute on this...

Hi @notpritam have assigned the issue to you! Thank you for showing interest in contributing to Appwrite! Happy Hacktoberfest 馃巸

Notes:

  1. Please update us with your progress every 3 days, so that we know that you are working on it.
  2. Join us on Discord - https://appwrite.io/discord to chat about Hacktoberfest and Appwrite!

@notpritam
Copy link

Here is the Progress ,
i am about to complete this , i am new to both appwrite and meilisearch so having a little trouble,

import 'dart:convert';
import 'dart:io';
import 'utils.dart';

import 'package:http/http.dart' as http;
import 'package:meilisearch/meilisearch.dart';
import 'package:dart_appwrite/dart_appwrite.dart';


Future<void> main(final context) async {

  final requiredEnvVars = [
    'APPWRITE_API_KEY',
    'APPWRITE_DATABASE_ID',
    'APPWRITE_COLLECTION_ID',
    'MEILISEARCH_ENDPOINT',
    'MEILISEARCH_INDEX_NAME',
    'MEILISEARCH_ADMIN_API_KEY',
    'MEILISEARCH_SEARCH_API_KEY',
  ];

  throwIfMissing(Platform.environment, requiredEnvVars);
  

    if (context.method == 'GET') {
      final html = interpolate(await getStaticFile('index.html'), {
        'MEILISEARCH_ENDPOINT': Platform.environment['MEILISEARCH_ENDPOINT'] as String,
        'MEILISEARCH_INDEX_NAME': Platform.environment['MEILISEARCH_INDEX_NAME'] as String,
        'MEILISEARCH_SEARCH_API_KEY':
            Platform.environment['MEILISEARCH_SEARCH_API_KEY'] as String,
      });

      context.req.response
        ..headers.contentType = ContentType.html
        ..write(html)
        ..close();
    } else {
      
      final client = Client()
     .setEndpoint('https://cloud.appwrite.io/v1')
     .setProject(Platform.environment['APPWRITE_FUNCTION_PROJECT_ID'])
     .setKey(Platform.environment['APPWRITE_API_KEY']);

      final databases = Databases(client);

      final meilisearch = MeiliSearchClient('http:https://127.0.0.1:7700', Platform.environment['MEILISEARCH_ADMIN_API_KEY'] as String);

      final index = meilisearch.index(Platform.environment['MEILISEARCH_INDEX_NAME'] as String);

      String? cursor;

      do {
        final queries = [Query.limit(100)];

        if (cursor != null) {
          queries.add(Query.cursorAfter(cursor!));
        }

        final response = await databases.listDocuments(
         databaseId: Platform.environment['APPWRITE_DATABASE_ID'] as String,
         collectionId: Platform.environment['APPWRITE_COLLECTION_ID'] as String,
        queries: queries,
        );

        final documents = response['documents'];

        if (documents.isNotEmpty) {
          cursor = documents[documents.length - 1]['\$id'];
        } else {
          print('No more documents found.');
          cursor = null;
          break;
        }

        print('Syncing chunk of ${documents.length} documents ...');
        await index.addDocuments(documents, primaryKey: '\$id');
      } while (cursor != null);

      print('Sync finished.');

      context.req.response
        ..write('Sync finished.')
        ..close();
    }
  
}

String interpolate(String content, Map<String, String> variables) {
  for (final entry in variables.entries) {
    content = content.replaceAll('{{${entry.key}}}', entry.value);
  }
  return content;
}

@gewenyu99
Copy link
Author

@notpritam Thanks for the update!

@Haimantika
Copy link

Hi @notpritam any update?

@himanshubalani
Copy link

Hey @gewenyu99 @Haimantika , can I work on the issue if the previous assignee is inactive?

@notpritam
Copy link

Hi @notpritam any update?

I am almost done with issue, i was having some problem with meilisearch, I will create a pr tomorrow after completing it

@Haimantika
Copy link

Hi @notpritam any update?

I am almost done with issue, i was having some problem with meilisearch, I will create a pr tomorrow after completing it

Hi, is the issue with Meilisearch solved? If not, you can raise a support thread on our Discord server and we can help you

@tessamero
Copy link

Closing issue due to inactivity and hacktoberfest being over, thank you for taking the time to be part of hacktoberfest this year :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Issues for Hacktoberfest 2023
Projects
None yet
Development

No branches or pull requests

5 participants