Skip to content

HSEARCH-3319 Type-safe field references / HSEARCH-5300 Annotation processor for the Search static metamodel #4156

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d3f01dd
HSEARCH-3319 Add base scope/scope provider to the engine
marko-bekhta May 7, 2024
97be2ed
HSEARCH-3319 Create reference traits interfaces
marko-bekhta May 7, 2024
683e87c
HSEARCH-3319 Add context type
marko-bekhta May 9, 2024
2ce9059
HSEARCH-3319 Add references to the DSL
marko-bekhta May 9, 2024
11e72d8
HSEARCH-3319 Simple test
marko-bekhta May 9, 2024
b5edf0a
HSEARCH-3319 Address super-type references
marko-bekhta May 15, 2024
98226f8
HSEARCH-3319 Use mapper specific root-scope-creators
marko-bekhta May 16, 2024
ac09fca
HSEARCH-3319 Test: Model properties with interfaces
marko-bekhta May 16, 2024
bf64112
HSEARCH-3319 Remove now unnecessary withRoot(Reference)
marko-bekhta May 17, 2024
b8aed56
HSEARCH-3319 Test
marko-bekhta May 17, 2024
359dd67
HSEARCH-3319 Use single impl for field sort options
marko-bekhta May 20, 2024
4ae94ea
HSEARCH-3319 Address scope changes in the Lucene - next backend
marko-bekhta Dec 12, 2024
c6abe95
HSEARCH-3319 More field references
marko-bekhta Mar 10, 2025
69d7ef3
HSEARCH-5300 Experiment with the annotation processor to generate the…
marko-bekhta Jan 14, 2025
0beccb8
HSEARCH-5300 Add integration tests modules for the metamodel processor
marko-bekhta Mar 19, 2025
8fadd23
HSEARCH-5300 More cleanups and improvements
marko-bekhta Mar 19, 2025
7accf74
HSEARCH-5300 Address various eclipse compiler + Sonar issues
marko-bekhta Apr 17, 2025
d52babd
HSEARCH-5300 Start adjusting the migration guide
marko-bekhta Apr 23, 2025
786f5f4
HSEARCH-5300 Add even more @Incubating to various field references
marko-bekhta Apr 23, 2025
c7f6ac3
HSEARCH-5300 Introduce "generic" Any*Reference mostly for simple case…
marko-bekhta Apr 23, 2025
bb2151d
HSEARCH-5300 Mention search DSL changes in the migration guide
marko-bekhta Apr 23, 2025
1158e1d
HSEARCH-5300 Add documentation for static metamodel
marko-bekhta Apr 24, 2025
8833515
HSEARCH-5300 Adjust the processor configuration properties
marko-bekhta Apr 24, 2025
b32c587
HSEARCH-5300 More tests and addressing enum for all (?) scenarios
marko-bekhta Apr 24, 2025
4b6a186
HSEARCH-5300 Rename package/processor and clean up the docs
marko-bekhta Apr 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ stage('Non-default environments') {
// we'd better recompile everything with the same compiler rather than get some strange errors
mavenNonDefaultBuild buildEnv, """ \
-DskipTests -DskipITs \
-P${buildEnv.mavenProfile},!javaModuleITs \
-P${buildEnv.mavenProfile},!javaModuleITs,!metamodelITs -pl '!:hibernate-search-documentation,!:hibernate-search-documentation-lucene-next,!:hibernate-search-reports' \
-Dgib.buildAll=true \
"""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,23 @@
*
* @see #get()
*/
public final class ElasticsearchExtension<H, R, E, LOS>
implements SearchQueryDslExtension<ElasticsearchSearchQuerySelectStep<R, E, LOS>, R, E, LOS>,
public final class ElasticsearchExtension<SR, H, R, E, LOS>
implements SearchQueryDslExtension<SR, ElasticsearchSearchQuerySelectStep<SR, R, E, LOS>, R, E, LOS>,
SearchQueryExtension<ElasticsearchSearchQuery<H>, H>,
SearchPredicateFactoryExtension<ElasticsearchSearchPredicateFactory>,
SearchSortFactoryExtension<ElasticsearchSearchSortFactory>,
SearchProjectionFactoryExtension<ElasticsearchSearchProjectionFactory<R, E>, R, E>,
SearchAggregationFactoryExtension<ElasticsearchSearchAggregationFactory>,
SearchPredicateFactoryExtension<SR, ElasticsearchSearchPredicateFactory<SR>>,
SearchSortFactoryExtension<SR, ElasticsearchSearchSortFactory<SR>>,
SearchProjectionFactoryExtension<SR, ElasticsearchSearchProjectionFactory<SR, R, E>, R, E>,
SearchAggregationFactoryExtension<SR, ElasticsearchSearchAggregationFactory<SR>>,
IndexFieldTypeFactoryExtension<ElasticsearchIndexFieldTypeFactory>,
SchemaExportExtension<ElasticsearchIndexSchemaExport> {

private static final ElasticsearchExtension<Object, Object, Object, Object> INSTANCE = new ElasticsearchExtension<>();
private static final ElasticsearchExtension<Object, Object, Object, Object, Object> INSTANCE =
new ElasticsearchExtension<>();

/**
* Get the extension with generic parameters automatically set as appropriate for the context in which it's used.
*
* @param <SR> Scope root type.
* @param <H> The type of query hits.
* Users should not have to care about this, as the parameter will automatically take the appropriate value when calling
* {@code .extension( ElasticsearchExtension.get() )}.
Expand All @@ -90,8 +92,8 @@ public final class ElasticsearchExtension<H, R, E, LOS>
* @return The extension.
*/
@SuppressWarnings("unchecked") // The instance works for any H, R, E and LOS
public static <H, R, E, LOS> ElasticsearchExtension<H, R, E, LOS> get() {
return (ElasticsearchExtension<H, R, E, LOS>) INSTANCE;
public static <SR, H, R, E, LOS> ElasticsearchExtension<SR, H, R, E, LOS> get() {
return (ElasticsearchExtension<SR, H, R, E, LOS>) INSTANCE;
}

private ElasticsearchExtension() {
Expand All @@ -102,8 +104,8 @@ private ElasticsearchExtension() {
* {@inheritDoc}
*/
@Override
public Optional<ElasticsearchSearchQuerySelectStep<R, E, LOS>> extendOptional(
SearchQuerySelectStep<?, R, E, LOS, ?, ?> original,
public Optional<ElasticsearchSearchQuerySelectStep<SR, R, E, LOS>> extendOptional(
SearchQuerySelectStep<SR, ?, R, E, LOS, ?, ?> original,
SearchQueryIndexScope<?> scope,
BackendSessionContext sessionContext,
SearchLoadingContextBuilder<E, LOS> loadingContextBuilder) {
Expand Down Expand Up @@ -135,9 +137,9 @@ public Optional<ElasticsearchSearchQuery<H>> extendOptional(SearchQuery<H> origi
* {@inheritDoc}
*/
@Override
public Optional<ElasticsearchSearchPredicateFactory> extendOptional(SearchPredicateFactory original) {
public Optional<ElasticsearchSearchPredicateFactory<SR>> extendOptional(SearchPredicateFactory<SR> original) {
if ( original instanceof ElasticsearchSearchPredicateFactory ) {
return Optional.of( (ElasticsearchSearchPredicateFactory) original );
return Optional.of( (ElasticsearchSearchPredicateFactory<SR>) original );
}
else {
return Optional.empty();
Expand All @@ -148,10 +150,10 @@ public Optional<ElasticsearchSearchPredicateFactory> extendOptional(SearchPredic
* {@inheritDoc}
*/
@Override
public Optional<ElasticsearchSearchSortFactory> extendOptional(
SearchSortFactory original) {
public Optional<ElasticsearchSearchSortFactory<SR>> extendOptional(
SearchSortFactory<SR> original) {
if ( original instanceof ElasticsearchSearchSortFactory ) {
return Optional.of( (ElasticsearchSearchSortFactory) original );
return Optional.of( (ElasticsearchSearchSortFactory<SR>) original );
}
else {
return Optional.empty();
Expand All @@ -162,9 +164,9 @@ public Optional<ElasticsearchSearchSortFactory> extendOptional(
* {@inheritDoc}
*/
@Override
public Optional<ElasticsearchSearchProjectionFactory<R, E>> extendOptional(SearchProjectionFactory<R, E> original) {
public Optional<ElasticsearchSearchProjectionFactory<SR, R, E>> extendOptional(SearchProjectionFactory<SR, R, E> original) {
if ( original instanceof ElasticsearchSearchProjectionFactory ) {
return Optional.of( (ElasticsearchSearchProjectionFactory<R, E>) original );
return Optional.of( (ElasticsearchSearchProjectionFactory<SR, R, E>) original );
}
else {
return Optional.empty();
Expand All @@ -175,10 +177,10 @@ public Optional<ElasticsearchSearchProjectionFactory<R, E>> extendOptional(Searc
* {@inheritDoc}
*/
@Override
public Optional<ElasticsearchSearchAggregationFactory> extendOptional(
SearchAggregationFactory original) {
public Optional<ElasticsearchSearchAggregationFactory<SR>> extendOptional(
SearchAggregationFactory<SR> original) {
if ( original instanceof ElasticsearchSearchAggregationFactory ) {
return Optional.of( (ElasticsearchSearchAggregationFactory) original );
return Optional.of( (ElasticsearchSearchAggregationFactory<SR>) original );
}
else {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,25 @@ public <P> ElasticsearchSearchQueryBuilder<P> select(BackendSessionContext sessi
}

@Override
public ElasticsearchSearchPredicateFactory predicateFactory() {
return new ElasticsearchSearchPredicateFactoryImpl( SearchPredicateDslContext.root( this ) );
public <SR> ElasticsearchSearchPredicateFactory<SR> predicateFactory() {
return new ElasticsearchSearchPredicateFactoryImpl<>( SearchPredicateDslContext.root( this ) );
}

@Override
public ElasticsearchSearchSortFactory sortFactory() {
return new ElasticsearchSearchSortFactoryImpl( SearchSortDslContext
public <SR> ElasticsearchSearchSortFactory<SR> sortFactory() {
return new ElasticsearchSearchSortFactoryImpl<>( SearchSortDslContext
.root( this, ElasticsearchSearchSortFactoryImpl::new, predicateFactory() ) );
}

@Override
public <R, E> ElasticsearchSearchProjectionFactory<R, E> projectionFactory() {
public <SR, R, E> ElasticsearchSearchProjectionFactory<SR, R, E> projectionFactory() {
return new ElasticsearchSearchProjectionFactoryImpl<>( SearchProjectionDslContext.root( this ) );
}

@Override
public ElasticsearchSearchAggregationFactory aggregationFactory() {
return new ElasticsearchSearchAggregationFactoryImpl( SearchAggregationDslContext.root( this, predicateFactory() ) );
public <SR> ElasticsearchSearchAggregationFactory<SR> aggregationFactory() {
return new ElasticsearchSearchAggregationFactoryImpl<>(
SearchAggregationDslContext.root( this, predicateFactory() ) );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

import com.google.gson.JsonObject;

public interface ElasticsearchSearchAggregationFactory
extends ExtendedSearchAggregationFactory<ElasticsearchSearchAggregationFactory, ElasticsearchSearchPredicateFactory> {
public interface ElasticsearchSearchAggregationFactory<SR>
extends
ExtendedSearchAggregationFactory<SR,
ElasticsearchSearchAggregationFactory<SR>,
ElasticsearchSearchPredicateFactory<SR>> {

/**
* Create an aggregation from JSON.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@

import com.google.gson.JsonObject;

public class ElasticsearchSearchAggregationFactoryImpl
public class ElasticsearchSearchAggregationFactoryImpl<SR>
extends AbstractSearchAggregationFactory<
ElasticsearchSearchAggregationFactory,
SR,
ElasticsearchSearchAggregationFactory<SR>,
ElasticsearchSearchAggregationIndexScope<?>,
ElasticsearchSearchPredicateFactory>
implements ElasticsearchSearchAggregationFactory {
ElasticsearchSearchPredicateFactory<SR>>
implements ElasticsearchSearchAggregationFactory<SR> {

public ElasticsearchSearchAggregationFactoryImpl(
SearchAggregationDslContext<ElasticsearchSearchAggregationIndexScope<?>,
ElasticsearchSearchPredicateFactory> dslContext) {
SearchAggregationDslContext<SR,
ElasticsearchSearchAggregationIndexScope<?>,
ElasticsearchSearchPredicateFactory<SR>> dslContext) {
super( dslContext );
}

@Override
public ElasticsearchSearchAggregationFactory withRoot(String objectFieldPath) {
return new ElasticsearchSearchAggregationFactoryImpl( dslContext.rescope(
public ElasticsearchSearchAggregationFactory<SR> withRoot(String objectFieldPath) {
return new ElasticsearchSearchAggregationFactoryImpl<>( dslContext.rescope(
dslContext.scope().withRoot( objectFieldPath ),
dslContext.predicateFactory().withRoot( objectFieldPath ) ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

/**
* A factory for search predicates with some Elasticsearch-specific methods.
*
* @param <SR> Scope root type.
*/
public interface ElasticsearchSearchPredicateFactory
extends ExtendedSearchPredicateFactory<ElasticsearchSearchPredicateFactory> {
public interface ElasticsearchSearchPredicateFactory<SR>
extends ExtendedSearchPredicateFactory<SR, ElasticsearchSearchPredicateFactory<SR>> {

/**
* Create a predicate from JSON.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@

import com.google.gson.JsonObject;

public class ElasticsearchSearchPredicateFactoryImpl
public class ElasticsearchSearchPredicateFactoryImpl<SR>
extends AbstractSearchPredicateFactory<
ElasticsearchSearchPredicateFactory,
SR,
ElasticsearchSearchPredicateFactory<SR>,
ElasticsearchSearchPredicateIndexScope<?>>
implements ElasticsearchSearchPredicateFactory {
implements ElasticsearchSearchPredicateFactory<SR> {

public ElasticsearchSearchPredicateFactoryImpl(
SearchPredicateDslContext<ElasticsearchSearchPredicateIndexScope<?>> dslContext) {
super( dslContext );
}

@Override
public ElasticsearchSearchPredicateFactory withRoot(String objectFieldPath) {
return new ElasticsearchSearchPredicateFactoryImpl( dslContext.rescope(
public ElasticsearchSearchPredicateFactory<SR> withRoot(String objectFieldPath) {
return new ElasticsearchSearchPredicateFactoryImpl<>( dslContext.rescope(
dslContext.scope().withRoot( objectFieldPath ) ) );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private static class Builder extends AbstractBuilder implements NamedPredicateBu
private final PredicateDefinition definition;
private final String predicateName;
private final ElasticsearchSearchIndexCompositeNodeContext field;
private SearchPredicateFactory factory;
private SearchPredicateFactory<?> factory;
private final Map<String, Object> params = new LinkedHashMap<>();

Builder(PredicateDefinition definition, String predicateName,
Expand All @@ -84,7 +84,7 @@ private static class Builder extends AbstractBuilder implements NamedPredicateBu
}

@Override
public void factory(SearchPredicateFactory factory) {
public void factory(SearchPredicateFactory<?> factory) {
this.factory = factory;
}

Expand All @@ -95,8 +95,9 @@ public void param(String name, Object value) {

@Override
public SearchPredicate build() {
NamedValuesBasedPredicateDefinitionContext ctx = new NamedValuesBasedPredicateDefinitionContext( factory, params,
name -> QueryLog.INSTANCE.paramNotDefined( name, predicateName, field.eventContext() ) );
NamedValuesBasedPredicateDefinitionContext<?> ctx =
new NamedValuesBasedPredicateDefinitionContext<>( factory, params,
name -> QueryLog.INSTANCE.paramNotDefined( name, predicateName, field.eventContext() ) );

ElasticsearchSearchPredicate providedPredicate = ElasticsearchSearchPredicate.from(
scope, definition.create( ctx ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
/**
* A factory for search projections with some Elasticsearch-specific methods.
*
* @param <SR> Scope root type.
* @param <R> The type of entity references.
* @param <E> The type of entities.
* @see SearchProjectionFactory
*/
public interface ElasticsearchSearchProjectionFactory<R, E>
extends ExtendedSearchProjectionFactory<ElasticsearchSearchProjectionFactory<R, E>, R, E> {
public interface ElasticsearchSearchProjectionFactory<SR, R, E>
extends ExtendedSearchProjectionFactory<SR, ElasticsearchSearchProjectionFactory<SR, R, E>, R, E> {

/**
* Project to a {@link JsonObject} representing the document as stored in Elasticsearch.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@

import com.google.gson.JsonObject;

public class ElasticsearchSearchProjectionFactoryImpl<R, E>
public class ElasticsearchSearchProjectionFactoryImpl<SR, R, E>
extends AbstractSearchProjectionFactory<
ElasticsearchSearchProjectionFactory<R, E>,
SR,
ElasticsearchSearchProjectionFactory<SR, R, E>,
ElasticsearchSearchProjectionIndexScope<?>,
R,
E>
implements ElasticsearchSearchProjectionFactory<R, E> {
implements ElasticsearchSearchProjectionFactory<SR, R, E> {

public ElasticsearchSearchProjectionFactoryImpl(
SearchProjectionDslContext<ElasticsearchSearchProjectionIndexScope<?>> dslContext) {
super( dslContext );
}

@Override
public ElasticsearchSearchProjectionFactory<R, E> withRoot(String objectFieldPath) {
public ElasticsearchSearchProjectionFactory<SR, R, E> withRoot(String objectFieldPath) {
return new ElasticsearchSearchProjectionFactoryImpl<>( dslContext.rescope(
dslContext.scope().withRoot( objectFieldPath ) ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
import org.hibernate.search.engine.search.query.dsl.SearchQueryOptionsStep;
import org.hibernate.search.util.common.annotation.Incubating;

public interface ElasticsearchSearchQueryOptionsStep<H, LOS>
public interface ElasticsearchSearchQueryOptionsStep<SR, H, LOS>
extends SearchQueryOptionsStep<
ElasticsearchSearchQueryOptionsStep<H, LOS>,
SR,
ElasticsearchSearchQueryOptionsStep<SR, H, LOS>,
H,
LOS,
ElasticsearchSearchSortFactory,
ElasticsearchSearchAggregationFactory>,
ElasticsearchSearchSortFactory<SR>,
ElasticsearchSearchAggregationFactory<SR>>,
ElasticsearchSearchFetchable<H> {

/**
Expand All @@ -34,7 +35,7 @@ public interface ElasticsearchSearchQueryOptionsStep<H, LOS>
* @return {@code this}, for method chaining.
*/
@Incubating
ElasticsearchSearchQueryOptionsStep<H, LOS> requestTransformer(ElasticsearchSearchRequestTransformer transformer);
ElasticsearchSearchQueryOptionsStep<SR, H, LOS> requestTransformer(ElasticsearchSearchRequestTransformer transformer);

@Override
ElasticsearchSearchQuery<H> toQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,35 @@
import org.hibernate.search.engine.search.projection.dsl.ProjectionFinalStep;
import org.hibernate.search.engine.search.query.dsl.SearchQuerySelectStep;

public interface ElasticsearchSearchQuerySelectStep<R, E, LOS>
public interface ElasticsearchSearchQuerySelectStep<SR, R, E, LOS>
extends SearchQuerySelectStep<
ElasticsearchSearchQueryOptionsStep<E, LOS>,
SR,
ElasticsearchSearchQueryOptionsStep<SR, E, LOS>,
R,
E,
LOS,
ElasticsearchSearchProjectionFactory<R, E>,
ElasticsearchSearchPredicateFactory>,
ElasticsearchSearchQueryWhereStep<E, LOS> {
ElasticsearchSearchProjectionFactory<SR, R, E>,
ElasticsearchSearchPredicateFactory<SR>>,
ElasticsearchSearchQueryWhereStep<SR, E, LOS> {

@Override
ElasticsearchSearchQueryWhereStep<E, LOS> selectEntity();
ElasticsearchSearchQueryWhereStep<SR, E, LOS> selectEntity();

@Override
ElasticsearchSearchQueryWhereStep<R, LOS> selectEntityReference();
ElasticsearchSearchQueryWhereStep<SR, R, LOS> selectEntityReference();

@Override
<P> ElasticsearchSearchQueryWhereStep<P, LOS> select(Class<P> objectClass);
<P> ElasticsearchSearchQueryWhereStep<SR, P, LOS> select(Class<P> objectClass);

@Override
<P> ElasticsearchSearchQueryWhereStep<P, LOS> select(
Function<? super ElasticsearchSearchProjectionFactory<R, E>,
<P> ElasticsearchSearchQueryWhereStep<SR, P, LOS> select(
Function<? super ElasticsearchSearchProjectionFactory<SR, R, E>,
? extends ProjectionFinalStep<P>> projectionContributor);

@Override
<P> ElasticsearchSearchQueryWhereStep<P, LOS> select(SearchProjection<P> projection);
<P> ElasticsearchSearchQueryWhereStep<SR, P, LOS> select(SearchProjection<P> projection);

@Override
ElasticsearchSearchQueryWhereStep<List<?>, LOS> select(SearchProjection<?>... projections);
ElasticsearchSearchQueryWhereStep<SR, List<?>, LOS> select(SearchProjection<?>... projections);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import org.hibernate.search.backend.elasticsearch.search.predicate.dsl.ElasticsearchSearchPredicateFactory;
import org.hibernate.search.engine.search.query.dsl.SearchQueryWhereStep;

public interface ElasticsearchSearchQueryWhereStep<H, LOS>
extends SearchQueryWhereStep<ElasticsearchSearchQueryOptionsStep<H, LOS>, H, LOS, ElasticsearchSearchPredicateFactory> {
public interface ElasticsearchSearchQueryWhereStep<SR, H, LOS>
extends
SearchQueryWhereStep<SR,
ElasticsearchSearchQueryOptionsStep<SR, H, LOS>,
H,
LOS,
ElasticsearchSearchPredicateFactory<SR>> {

}
Loading