Skip to content

#22 | Add getOrCreateIndex functionality #45

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

Merged
merged 24 commits into from
Nov 5, 2020

Conversation

arjunrc143
Copy link
Contributor

No description provided.

@arjunrc143 arjunrc143 mentioned this pull request Oct 27, 2020
2 tasks
@eskombro
Copy link
Member

Hi @arjunrc143

Thanks for your PR. It is important that in the getoOrCreateIndex method we catch the Exception only if the error corresponds to an index that exists already. Otherwise we shouldn't proceed as we do not necessarily know where the problem is coming from. You can check in the MeiliSearch response if the errorCode corresponds to index_already_exists.

This will be updated later when we implement a Custom error handler in #7

Can you please add this check?

@eskombro
Copy link
Member

Also, please link the issue. You can add a comment in your pr like this

Closes #22 

@arjunrc143
Copy link
Contributor Author

Hi @arjunrc143

Thanks for your PR. It is important that in the getoOrCreateIndex method we catch the Exception only if the error corresponds to an index that exists already. Otherwise we shouldn't proceed as we do not necessarily know where the problem is coming from. You can check in the MeiliSearch response if the errorCode corresponds to index_already_exists.

This will be updated later when we implement a Custom error handler in #7

Can you please add this check?

Done

@arjunrc143
Copy link
Contributor Author

closes #22

@eskombro eskombro linked an issue Oct 27, 2020 that may be closed by this pull request
2 tasks
@eskombro
Copy link
Member

eskombro commented Oct 27, 2020

closes #22

I think this must be done in the PR description :)

I linked it anyways !

@eskombro
Copy link
Member

eskombro commented Oct 27, 2020

This PR seems good! Just need to add a few integration tests ! For example:

  • Use getOrCreateIndex() and check that the index is created
  • Use getOrCreateIndex() with an existing index and check that no Exception is thrown, and that the index is returned
  • Use getOrCreateIndex() 2 or three times in a row...

@arjunrc143
Copy link
Contributor Author

@eskombro I have added the integration tests. Please check.

@arjunrc143
Copy link
Contributor Author

2 integration tests are failing. Will check that.

@eskombro
Copy link
Member

eskombro commented Oct 29, 2020

@arjunrc143 I checked what's going on, and the problem is that when you get an index_already_exists error, the SDK is throwing an IOException with the message

Server returned HTTP response code: 400 for URL: http://localhost:7700/indexes

So the check you implemented for the error catching (line 123) doesn't work. This problem is coming from what createIndex() returns in case of failure, and so, not your bad or any problem in your PR at all actually.

I'll fix this since I'm implementing a basic error handler, and let you know so you can rebase your branch and it should work fine!

Glad you added those tests 👍

@arjunrc143
Copy link
Contributor Author

@eskombro Cool. Let me know once this gets fixed. Thanks!

eskombro and others added 2 commits November 4, 2020 01:14
…MeiliSearchConnectionException (meilisearch#46)

Custom Exceptions: MeiliSearchException => MeiliSearchApiException + MeiliSearchConnectionException
Copy link
Member

@eskombro eskombro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @arjunrc143!

We can already use custom Exceptions, Can you please rebase your branch on master?

I did a suggestion on your code, on how to check the MeiliSearchApiException errorCode in this method which is already tested!

ALSO:

Can you please create a getOrCreateIndex(String uid) method without a primaryKey, which calls getOrCreateIndex(String uid, null) ?

public Index getOrCreateIndex(String uid) throws Exception {
	return getOrCreateIndex(uid, null);
}

primaryKey should be optional!

After this PR will be ready to merge! 🎉

Chris and others added 5 commits November 4, 2020 12:42
* Implementation of delete list of documents from index.
* Add tests for deleteDocuments , fixed existing errors in test module.
* change name of package com.meilisearch.sdk.Exception -> com.meilisearch.sdk.exception to resolve errors
@arjunrc143
Copy link
Contributor Author

Hey @arjunrc143!

We can already use custom Exceptions, Can you please rebase your branch on master?

I did a suggestion on your code, on how to check the MeiliSearchApiException errorCode in this method which is already tested!

ALSO:

Can you please create a getOrCreateIndex(String uid) method without a primaryKey, which calls getOrCreateIndex(String uid, null) ?

public Index getOrCreateIndex(String uid) throws Exception {
	return getOrCreateIndex(uid, null);
}

primaryKey should be optional!

After this PR will be ready to merge! 🎉

@eskombro This is done. Can you please review it?

Copy link
Member

@eskombro eskombro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 🎉

@eskombro eskombro merged commit f05cb9c into meilisearch:master Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add GetOrCreateIndex method
2 participants