Make SearchScope session-independent

Description

Currently SearchScope is a very niche interface, most users being expected to use the SearchSession methods that simply delegate to the scope.

The main (only?) use for SearchScope is when users want to build re-usable predicates/sorts/projections etc. Then, using the scope, they can build objects that they'll be able to re-use in other

These objects are session-independent, so they could be used from one session to another, but unfortunately the scope is not, which makes creating re-usable objects rather weird: you have to open a session for something that doesn't need a session.

It would be nice if we could make SearchScope session-independent. Basically the SearchScope would only represent a set of indexed types, and expose operations on this set. Only some operations will require a session, which will be passed as a parameter: search() would become search(EntityManager), massIndexer() would become massIndexer(EntityManager), and so on.

The SearchScope will no longer be retrieved from the SearchSession. Instead, we will introduce a SearchMapping interface (as mentioned in ), and retrieving a scope will go something like this:

1 2 3 4 SearchMapping mapping = Search.mapping(entityManagerFactory); SearchScope<MyAbstractType> scope = mapping.scope(MyType1.class, MyType2.class); SearchPredicate predicate = scope.predicate().....toPredicate(); SearchResult<MyAbstractType> = scope.search(entityManager).predicate(predicate).fetch();

Which is really not far from what we currently have:

1 2 3 4 SearchSession session = Search.session(entityManager); SearchScope<MyAbstractType> scope = session.scope(MyType1.class, MyType2.class); SearchPredicate predicate = scope.predicate().....toPredicate(); SearchResult<MyAbstractType> = scope.search().predicate(predicate).fetch();

Nothing will change on SearchSession, as implementations will only pass an additional parameter to the scope, which will be transparent to users. We will just remove (or at least deprecate for later removal) the .scope() methods on SearchSession.

Environment

None

Status

Assignee

Yoann Rodière

Reporter

Yoann Rodière

Labels

None

Suitable for new contributors

None

Feedback Requested

None

Fix versions

Priority

Major
Configure