-
-
Notifications
You must be signed in to change notification settings - Fork 246
HSEARCH-3671 Make SearchScope session-independent #2084
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
1e76dea to
512e996
Compare
| SearchScope<Book> scope = searchMapping.scope( Book.class ); // <2> | ||
|
|
||
| SearchResult<Book> result = scope.search() // <3> | ||
| SearchResult<Book> result = scope.search( entityManager ) // <3> |
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.
Is this mandatory? I must admit I'm not excited by the fact that we have to passe the EMF and the EM. It makes things far less fluid IMHO.
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.
Eventually, people who don't want to load entities will be allowed to call scope.search() (if using single-tenancy) or scope.search(tenantId) (if using multi-tenancy). That's not implemented yet.
For people who actually want to load entities, well, we need an entity manager. Yes, we have a factory, but I don't think creating the entity manager ourselves silently would be a good idea. The loaded entities would not be usable anyway.
I could provide a way to pass the scope to a SearchSession, e.g. searchSession.search( scope ), but then you need an entity manager to create the SearchSession, so it's just more verbose.
Also, please keep in mind this is just the syntax with scopes, which is not really the one I want to promote. Let's say it's an alternate, lower-level syntax. The first syntax, with a SearchSession, is much better in most cases.
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.
If the only problem you have is with the example itself, and the appearance of code for users who just don't want lambdas, I suppose I could also restore the scope() methods on the session. Then users will be able to trigger the search and create scope from a single object that was created from an entity manager.
However, the scopes will still be session-independent, so the search() method on those will still take an EntityManager in parameter. This method generally won't be useful though, since people can just call search on the session.
2c9b581 to
5c1ab4f
Compare
|
I just pushed a few other commits to not require passing an entity manager when creating a Rather than: ... but I suppose it's too verbose? :) |
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.
Making the scope session-independent has a lot of advantages it term of decoupling. I agree with you the scope should not be related to a session instance.
On the other hand, my concern I think is the same that @gsmet has: make the API less easy to use.
I think that a Hibernate user expects to work on a session instance. IMHO creating a scope from a mapping derived from a session factory, then apply a session instance to it could be seen from him too much complicated.
I know that the user can bypass the scope extraction and, in that case, the API to search is the same, but I have some concern about to give him an API that has too many steps, even if there is an alternative.
mapper/orm/src/main/java/org/hibernate/search/mapper/orm/Search.java
Outdated
Show resolved
Hide resolved
...ocumentation/gettingstarted/withhsearch/withoutanalysis/GettingStartedWithoutAnalysisIT.java
Outdated
Show resolved
Hide resolved
...rch/documentation/mapper/orm/indexedembedded/includepaths/IndexedEmbeddedIncludePathsIT.java
Outdated
Show resolved
Hide resolved
...n/mapper/orm/indexedembedded/includepathsanddepth/IndexedEmbeddedIncludePathsAndDepthIT.java
Outdated
Show resolved
Hide resolved
…in ToJpaIT Because this test is about JPA, and we don't need more than an EntityManagerFactory.
…he "mapping" package For consistency with the ORM mapper.
They've been deprecated since 6.0.0.Alpha7, and are getting in the way of new work.
…nager, SessionFactory, ...) to SPI (*Implementor)
…lementor from the MassIndexer Just to simplify the context passed by the SearchScope to the MassIndexer.
…nterfaces Scope creation is about to be moved to the mapping, so we won't be able to create scope from interfaces anymore (only from implementations).
…lar) to BackendSessionContext In an attempt to clarify what these interfaces were originally intended for, at least initially: they are a view of the mapping/session from the backend.
…cope.writer and SearchScope.massIndexer
…m a SearchSession The resulting scope is still session-independent, which is a bit weird, but it's a handy shortcut when one wants to perform a search immediately.
5c1ab4f to
678daea
Compare
|
I reverted some of the changes to keep the previous syntax So the syntax with object (which, keep that in mind, is an alternative syntax) will be: ... with the possibility to create the scope from the mapping directly, if need be (no example in the documentation yet, I'll introduce some when it's actually useful). It is, I think, fairly similar to what we used to have: |
…earch(scope) The implementation is ugly and requires casting, but at least the syntax is easier on the eye for users.
It was forgotten in a previous PR.
678daea to
00c9406
Compare
|
@fax4ever Actually never mind, I think you already have enough review work. I addressed your comments with the last few commits, so I'll merge once the CI build succeeds. |
… ...) directly from the mapping
00c9406 to
cdb630b
Compare
|
Anyway @yrodiere. seeing the API, not handling a full review of the changes, I can say we have reached a good compromise. |
https://hibernate.atlassian.net/browse/HSEARCH-3671