Skip to content

Improve indexes #1918

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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open

Conversation

flevi29
Copy link
Collaborator

@flevi29 flevi29 commented Apr 8, 2025

Pull Request

What does this PR do?

  • refactors index types so that they match the meilisearch rust source code model as much as possible
  • removes index manipulating methods from Index class that don't directly take an index UID parameter, and vice versa for MeiliSearch class
  • removes methods that query and then create Index instances from queried data
  • removes deleteIndexIfExists, this is a flawed function that is no longer required, because the base delete function doesn't throw if the index doesn't exist, so it has the same effect
  • refactors tests for these methods
    • test were unnecessarily lengthy and were covering things that were either
      • already covered by other tests
      • already covered by tests in the same file, but with different variations to parameters (we're not testing meilisearch here, we just want to make sure that most of our input is accepted and the expected response is returned)
      • straight up unnecessary, like testing for each endpoint whether a wrong host will give a certain error, these types of tests are HttpRequests tests, and even so might be overdoing things

Migration

  • fn getRawIndex -> getIndex
  • type IndexObject -> IndexView
  • fn getRawIndexes -> getIndexes
  • type IndexesResults<IndexObject[]> -> IndexViewList
  • type IndexesQuery -> ListIndexes
  • type IndexOptions -> IndexCreateRequest
- await client.deleteIndexIfExists(uid);
+ const task = await client.index(uid).deleteIndex().waitTask();
+ const indexNotExists = task.error?.code === "index_not_found";
- await client.deleteIndex(uid).waitTask();
- await client.index(uid).delete().waitTask();
+ await client.index(uid).deleteIndex().waitTask();
- await client.updateIndex(...).waitTask();
- await client.index(uid).update(...).waitTask();
+ await client.index(uid).updateIndex(...).waitTask();
- await client.getRawIndex(uid);
- await client.index(uid).getRawInfo();
+ await client.index(uid).getIndex();
- await client.createIndex(uid, { primaryKey }).waitTask();
+ await client.createIndex({ uid, primaryKey }).waitTask();

These are hardly useful, but here's the migration anyway:

- const index = await client.getIndex(uid);
+ const index = client.index(uid);
+ const obj = { details: await index.getIndex(), index };
- const indexes = await client.getIndexes();
+ const indexes = (await client.getIndexes()).results.map((v) => ({
+   details: v,
+   index: client.index(v.uid),
+ }));

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

@flevi29 flevi29 added the breaking-change The related changes are breaking for the users label Apr 8, 2025
Copy link

codecov bot commented Apr 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.92%. Comparing base (7da269f) to head (6189297).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1918      +/-   ##
==========================================
+ Coverage   99.02%   99.92%   +0.90%     
==========================================
  Files          18       18              
  Lines        1435     1368      -67     
  Branches      303      292      -11     
==========================================
- Hits         1421     1367      -54     
+ Misses         14        1      -13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Strift Strift marked this pull request as draft April 9, 2025 02:53
@flevi29 flevi29 mentioned this pull request Apr 9, 2025
8 tasks
@flevi29 flevi29 marked this pull request as ready for review April 9, 2025 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change The related changes are breaking for the users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant