-
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
make _formatted value user friendly :) #406
base: main
Are you sure you want to change the base?
Conversation
…lass from tests since it's useless now
Hello @ahmednfwela, Thanks for this PR and this idea to solve the issue. The main question we have here, is to consider if the issue is coming from the client or from the server response. My personal opinion, is that the problem is coming from the server, the response is shaped like this thanks to a flattening operation that only exists in rust. In other word, the serialisation of the real object is not following standard json. It all depends on how Meilisearch team will consider this issue. If they consider this response ok, then the issue is on our side and we will have to do some akward things here. If they consider that using serd's flatten option is not ideal, then the fix will be very natural here. |
I think the flattening is ok here, since following the principle of least surprise, if a user who is used to a list of {"id": 1, "name": "Hello world"} suddenly starts seeing a list of {"original":{ "id": 1, "name": "Hello world"}, "formatted":{ "id": 1, "name": "Hello world"}} when they request highlighting, it would throw them off. |
For me, I think that it's really weird to ask a developer to chose between two functions for searching with different return types. public async Task<ISearchable<T>> SearchAsync<T>(string query,
SearchQuery searchAttributes = default, CancellationToken cancellationToken = default) and public async Task<ISearchable<IFormatContainer<T, TFormatted>>> SearchAsync<T, TFormatted>(string query,
SearchQuery searchAttributes = default, CancellationToken cancellationToken = default) The response should always be the same and the formatted property should always exists as a nullable property. Otherwise you would have to duplicate some code in your ui depending if you want to see highlighting or not. The other problem with flattening here, is name collision, what if your model has a |
the second method is just a sugar syntax for the first one actually, because you can just do the developer can keep using also for name collisions, I think it's normal, as long as it's well-documented it becomes the user's problem to avoid using preserved fields |
This actual could be solve with this var item = response.Original;
Not my opinion, this issue can be avoided without this transformation. Users who are evaluating the option Meilisearch are not going to break what they already have just to make it compatible with it. I'm sure this is a very low percentage and Meilisearch will have to evaluate what is more interesting for them. This is not only technical, it is now a business decision too. |
I'm ok with that if this is the decision of Meilisearch team. What I was more saying is that before merging this PR, we should wait to know what the core team wants to do with this issue. This is impacting all strongly typed languages. It's not an easy decision to take for them. |
Hey @ahmednfwela! Just to let you know @alallema is on Holiday and will review this PR once they come back :) |
merged with main and solved conflicts @alallema |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much @ahmednfwela, for this PR ❤️ and so sorry for the delay ...
I'll make a few comments, but shouldn't we change the samples in the code-sample file according to this new PR?
Also I didn't have the right on this PR to fix the conflicts I let you do it 😃
@@ -32,6 +33,33 @@ public async Task InitializeAsync() | |||
|
|||
public Task DisposeAsync() => Task.CompletedTask; | |||
|
|||
[Fact] | |||
public async Task TestJsonConverter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this method asynchronous if there is no await
inside?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's just a habit of making everything async 😄
@alallema Thanks for your review! I think after the recent changes in meilisearch, it's better if we take an approach similar to this PR meilisearch/meilisearch-dart#350 where we make a comprehensive what do you think ? |
Co-authored-by: Amélie <alallema@users.noreply.github.com>
@ahmednfwela, I more than agree. But I think it's up to @brunoocasali to take the decision |
But I think that triggers the same issue, no? Because it may not be possible to do it... |
bors try |
@brunoocasali I am currently working on a refactor for this PR |
Thank you very much @ahmednfwela ;) |
@ahmednfwela, thank you again for this PR. DO you think we should continue to work on it? |
@curquiza Hi, and sorry for the long delay, but yes, I am currently updating this PR. |
@ahmednfwela do you need any assistance with this? create an abstact class /// <summary>
/// Inheritable class for retrieving formatted results.
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class MeilisearchDocumentContainer<T>
{
/// <summary>
/// Gets or sets the _formatted field.
/// </summary>
[JsonPropertyName("_formatted")]
public T _Formatted { get; set; }
} Then if the user sets the "AttributesToHighlight" and are expecting This method passes all existing tests without modification (other than the Let me know your thoughts! |
hi @danFbach , my main problem with inheritance, is that we are restricting the user to use our base class, so if they have their own base class for dtos, they will be unusable you are free to pick up the work here though, as I am currently extremely busy, there is a similar implementation in meilisearch-dart repo if you want it for reference |
Pull Request
Related issue
Fixes #315
What does this PR do?
IFormatContainer<TOriginal, TFormatted>
coupled with a json converterIFormatContainerJsonConverter<TOriginal, TFormatted>
and aIFormatContainerJsonConverterFactory
SearchAsync
overload_formatted
documents.FormattedMovie
in favor of the new APIUsage is simple:
SearchAsync<Model, Model>
SearchAsync<Model, FormattedModel>
PR checklist
Please check if your PR fulfills the following requirements:
Thank you so much for contributing to Meilisearch!
cc @alallema