-
Notifications
You must be signed in to change notification settings - Fork 58
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
Refactor code to prepare support for NDJSON and CSV #213
Conversation
I was digging a bit further to add NDJSON and CSV support and I found something that needs to be discussed a bit. I think there is an issue with the JsonSerializerOptions here : meilisearch-dotnet/src/Meilisearch/MeilisearchClient.cs Lines 22 to 26 in 8d63ed4
And this code meilisearch-dotnet/src/Meilisearch/ObjectExtensions.cs Lines 49 to 63 in 8d63ed4
Used here meilisearch-dotnet/src/Meilisearch/Index.cs Line 212 in 8d63ed4
First issue is the custom function Second issue which is more serious, removing null properties is a bad decision. Here is why : Imagine we have this object we want to add to Meilisearch public class UserAccount
{
public int Id { get; set; }
public string Name { get; set; }
public bool? HasAcceptedLicense { get; set; }
} When we add the object the first time we have the following values
A few days later, you change the license and require the user to accept or refuse it and you want to set You won't be able to do that with the current Last important thing is With the following records and actual options
The To conclude The best option would be to remove the custom If you're ok with that, I can add a small commit to this PR with the changes. |
Before working on this PR, I suggest that we first finish the work to support Meilisearch 0.25. Then, I will take some changes from this big PR and create smaller ones to prepare the support for NDJSON and CSV. It will be easier to review. |
Completely agreed! |
230: Create a GetChunks extension method for batches r=brunoocasali a=juchom # Pull Request ## What does this PR do? This pull request is here to make code a little bit easier to follow for batches. For exemple if we look at `AddDocumentsInBatchesAsync` we have this two piece of code. https://github.com/meilisearch/meilisearch-dotnet/blob/3f14f432a658deb8a83ab505179b34559e9c1252/src/Meilisearch/Index.cs#L152-L161 https://github.com/meilisearch/meilisearch-dotnet/blob/3f14f432a658deb8a83ab505179b34559e9c1252/src/Meilisearch/Index.cs#L732-L745 To follow the code we have to start 159 with a call to the second snippet. We go to the second snippet where we do so computation to get chunks, then we call a function and we have to go up to the first snippet and see what is happening with this local function. With this refactoring the `AddDocumentsInBatchesAsync` is self explaining. The second snippet is now replaced by an extension method that returns a chunk on demand. With the new code you see what the method is doing on first read https://github.com/meilisearch/meilisearch-dotnet/blob/4264a71913db643356c128670de09122b6c7e7f4/src/Meilisearch/Index.cs#L152-L161 This is a part from a previous PR #213. I will make several from #213 because there is too much things in this one. Co-authored-by: Julien Chomarat <j.chomarat@linoa.com>
230: Create a GetChunks extension method for batches r=brunoocasali a=juchom # Pull Request ## What does this PR do? This pull request is here to make code a little bit easier to follow for batches. For exemple if we look at `AddDocumentsInBatchesAsync` we have this two piece of code. https://github.com/meilisearch/meilisearch-dotnet/blob/3f14f432a658deb8a83ab505179b34559e9c1252/src/Meilisearch/Index.cs#L152-L161 https://github.com/meilisearch/meilisearch-dotnet/blob/3f14f432a658deb8a83ab505179b34559e9c1252/src/Meilisearch/Index.cs#L732-L745 To follow the code we have to start 159 with a call to the second snippet. We go to the second snippet where we do so computation to get chunks, then we call a function and we have to go up to the first snippet and see what is happening with this local function. With this refactoring the `AddDocumentsInBatchesAsync` is self explaining. The second snippet is now replaced by an extension method that returns a chunk on demand. With the new code you see what the method is doing on first read https://github.com/meilisearch/meilisearch-dotnet/blob/4264a71913db643356c128670de09122b6c7e7f4/src/Meilisearch/Index.cs#L152-L161 This is a part from a previous PR #213. I will make several from #213 because there is too much things in this one. Co-authored-by: Julien Chomarat <j.chomarat@linoa.com>
Pull Request
The main idea of this pull request is to cleanup and refactor some code in order to easily add support for CSV and NDJSON.
The only format supported is still JSON. I have renamed the methods according to the issue.
Batches methods were a bit akward and difficult to read / understand, so I removed the
BatchOperationAsync
method and added anEnumerableExtensions
class which gives theChunk
.Documents Add / Update unit tests are now
Theory
so we can easily extends them for CSV and NDJSON.Documentation has been updated.
@curquiza let me know if you need help to review the code.
What does this PR do?
First step for #182
PR checklist
Please check if your PR fulfills the following requirements:
Thank you so much for contributing to MeiliSearch!