Skip to content

Add Query by Example feature #2418 #2422

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

Conversation

ezequielantunez
Copy link
Contributor

Added Query by Example repositories fragments
Added Criteria.regexp

Closes #2418

Added Query by Example repositories fragments
Added Criteria.regexp
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 5, 2023
@sothawo
Copy link
Collaborator

sothawo commented Jan 8, 2023

Sorry I didn't comment earlier, thanks for the PR. I had no time yet to look at it (I was busy on #2419). Will have a look these days.

Copy link
Collaborator

@sothawo sothawo left a comment

Choose a reason for hiding this comment

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

Impressive work, thanks a lot for that. I have some minor comments, and one place where I think the logic for getting the property name is not correct.

One thing that I don't like - and that has nothing to do with your implementation - is that by implementing org.springframework.data.repository.query.QueryByExampleExecutor we have to do this unwrapping in the methods of QueryByExampleElasticsearchExecutor; we discard all the additional information that is available in the SearchHit<T> objects.

This could be solved by creating a new interface SearchHitsQueryByExampleExecutor (I don't have a better name currently) where we have the same methods, but different return types (SearchHits<T> or maybe List<SearchHit<T>>). The implementation for that would be similar to what you did but without the unwrapping.

Maybe we could have both, and the unwrapping implementation might use the other one to get the SearchHits and then unwrap them.

What do you think about that? We can merge your changes and have that other as an additional feature later.

@sothawo sothawo removed the status: waiting-for-triage An issue we've not yet triaged label Jan 10, 2023
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 10, 2023
@sothawo
Copy link
Collaborator

sothawo commented Jan 10, 2023

This could be solved by creating a new interface SearchHitsQueryByExampleExecutor (I don't have a better name currently) where we have the same methods, but different return types (SearchHits<T> or maybe List<SearchHit<T>>). The implementation for that would be similar to what you did but without the unwrapping.

In addition this would allow to have method overloads that not only accept a Sort, but a Pageable as well.

Fixed Criteria.regexp
Minor fixes in QueryByExample fragments and mapper
Improved test coverage
@ezequielantunez
Copy link
Contributor Author

ezequielantunez commented Jan 11, 2023

Comments solved in bbadfe9

About creating a new interface I think we could work on it on another PR.
In fact we could have a base repository fragment implementation for Query By Example returning SearchHit, and refactor the fragments included in this PR to use the potentially new SearchHit implementation and just unwrap the results as you mentioned before.

@sothawo sothawo merged commit 5a36f5e into spring-projects:main Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Query by Example feature
3 participants