Skip to content

Commit

Permalink
HSEARCH-3319 Address scope changes in the Lucene - next backend
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta committed Dec 13, 2024
1 parent 43b838c commit cbfcec9
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,23 @@
*
* @see #get()
*/
public final class LuceneExtension<H, R, E, LOS>
implements SearchQueryDslExtension<LuceneSearchQuerySelectStep<R, E, LOS>, R, E, LOS>,
public final class LuceneExtension<SR, H, R, E, LOS>
implements SearchQueryDslExtension<SR, LuceneSearchQuerySelectStep<SR, R, E, LOS>, R, E, LOS>,
SearchQueryExtension<LuceneSearchQuery<H>, H>,
SearchPredicateFactoryExtension<LuceneSearchPredicateFactory>,
SearchSortFactoryExtension<LuceneSearchSortFactory>,
SearchProjectionFactoryExtension<LuceneSearchProjectionFactory<R, E>, R, E>,
SearchAggregationFactoryExtension<LuceneSearchAggregationFactory>,
SearchPredicateFactoryExtension<SR, LuceneSearchPredicateFactory<SR>>,
SearchSortFactoryExtension<SR, LuceneSearchSortFactory<SR>>,
SearchProjectionFactoryExtension<SR, LuceneSearchProjectionFactory<SR, R, E>, R, E>,
SearchAggregationFactoryExtension<SR, LuceneSearchAggregationFactory<SR>>,
IndexFieldTypeFactoryExtension<LuceneIndexFieldTypeFactory>,
IndexScopeExtension<LuceneIndexScope>,
SchemaExportExtension<LuceneIndexSchemaExport> {

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

/**
* 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( LuceneExtension.get() }.
Expand All @@ -94,8 +95,8 @@ public final class LuceneExtension<H, R, E, LOS>
* @return The extension.
*/
@SuppressWarnings("unchecked") // The instance works for any H, R and E
public static <H, R, E, LOS> LuceneExtension<H, R, E, LOS> get() {
return (LuceneExtension<H, R, E, LOS>) INSTANCE;
public static <SR, H, R, E, LOS> LuceneExtension<SR, H, R, E, LOS> get() {
return (LuceneExtension<SR, H, R, E, LOS>) INSTANCE;
}

private LuceneExtension() {
Expand All @@ -106,8 +107,8 @@ private LuceneExtension() {
* {@inheritDoc}
*/
@Override
public Optional<LuceneSearchQuerySelectStep<R, E, LOS>> extendOptional(
SearchQuerySelectStep<?, R, E, LOS, ?, ?> original,
public Optional<LuceneSearchQuerySelectStep<SR, R, E, LOS>> extendOptional(
SearchQuerySelectStep<SR, ?, R, E, LOS, ?, ?> original,
SearchQueryIndexScope<?> scope,
BackendSessionContext sessionContext,
SearchLoadingContextBuilder<E, LOS> loadingContextBuilder) {
Expand Down Expand Up @@ -139,9 +140,9 @@ public Optional<LuceneSearchQuery<H>> extendOptional(SearchQuery<H> original,
* {@inheritDoc}
*/
@Override
public Optional<LuceneSearchPredicateFactory> extendOptional(SearchPredicateFactory original) {
public Optional<LuceneSearchPredicateFactory<SR>> extendOptional(SearchPredicateFactory<SR> original) {
if ( original instanceof LuceneSearchPredicateFactory ) {
return Optional.of( (LuceneSearchPredicateFactory) original );
return Optional.of( (LuceneSearchPredicateFactory<SR>) original );
}
else {
return Optional.empty();
Expand All @@ -152,10 +153,10 @@ public Optional<LuceneSearchPredicateFactory> extendOptional(SearchPredicateFact
* {@inheritDoc}
*/
@Override
public Optional<LuceneSearchSortFactory> extendOptional(
SearchSortFactory original) {
public Optional<LuceneSearchSortFactory<SR>> extendOptional(
SearchSortFactory<SR> original) {
if ( original instanceof LuceneSearchSortFactory ) {
return Optional.of( (LuceneSearchSortFactory) original );
return Optional.of( (LuceneSearchSortFactory<SR>) original );
}
else {
return Optional.empty();
Expand All @@ -166,9 +167,9 @@ public Optional<LuceneSearchSortFactory> extendOptional(
* {@inheritDoc}
*/
@Override
public Optional<LuceneSearchProjectionFactory<R, E>> extendOptional(SearchProjectionFactory<R, E> original) {
public Optional<LuceneSearchProjectionFactory<SR, R, E>> extendOptional(SearchProjectionFactory<SR, R, E> original) {
if ( original instanceof LuceneSearchProjectionFactory ) {
return Optional.of( (LuceneSearchProjectionFactory<R, E>) original );
return Optional.of( (LuceneSearchProjectionFactory<SR, R, E>) original );
}
else {
return Optional.empty();
Expand All @@ -179,9 +180,9 @@ public Optional<LuceneSearchProjectionFactory<R, E>> extendOptional(SearchProjec
* {@inheritDoc}
*/
@Override
public Optional<LuceneSearchAggregationFactory> extendOptional(SearchAggregationFactory original) {
public Optional<LuceneSearchAggregationFactory<SR>> extendOptional(SearchAggregationFactory<SR> original) {
if ( original instanceof LuceneSearchAggregationFactory ) {
return Optional.of( (LuceneSearchAggregationFactory) original );
return Optional.of( (LuceneSearchAggregationFactory<SR>) original );
}
else {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,24 +162,24 @@ public <P> LuceneSearchQueryBuilder<P> select(BackendSessionContext sessionConte
}

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

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

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

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.hibernate.search.backend.lucene.search.predicate.dsl.LuceneSearchPredicateFactory;
import org.hibernate.search.engine.search.aggregation.dsl.ExtendedSearchAggregationFactory;

public interface LuceneSearchAggregationFactory
extends ExtendedSearchAggregationFactory<LuceneSearchAggregationFactory, LuceneSearchPredicateFactory> {
public interface LuceneSearchAggregationFactory<SR>
extends ExtendedSearchAggregationFactory<SR, LuceneSearchAggregationFactory<SR>, LuceneSearchPredicateFactory<SR>> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@
import org.hibernate.search.engine.search.aggregation.dsl.spi.AbstractSearchAggregationFactory;
import org.hibernate.search.engine.search.aggregation.dsl.spi.SearchAggregationDslContext;

public class LuceneSearchAggregationFactoryImpl
public class LuceneSearchAggregationFactoryImpl<SR>
extends AbstractSearchAggregationFactory<
LuceneSearchAggregationFactory,
SR,
LuceneSearchAggregationFactory<SR>,
LuceneSearchAggregationIndexScope<?>,
LuceneSearchPredicateFactory>
implements LuceneSearchAggregationFactory {
LuceneSearchPredicateFactory<SR>>
implements LuceneSearchAggregationFactory<SR> {

public LuceneSearchAggregationFactoryImpl(
SearchAggregationDslContext<LuceneSearchAggregationIndexScope<?>, LuceneSearchPredicateFactory> dslContext) {
SearchAggregationDslContext<SR,
LuceneSearchAggregationIndexScope<?>,
LuceneSearchPredicateFactory<SR>> dslContext) {
super( dslContext );
}

@Override
public LuceneSearchAggregationFactory withRoot(String objectFieldPath) {
return new LuceneSearchAggregationFactoryImpl( dslContext.rescope(
public LuceneSearchAggregationFactory<SR> withRoot(String objectFieldPath) {
return new LuceneSearchAggregationFactoryImpl<SR>( dslContext.rescope(
dslContext.scope().withRoot( objectFieldPath ),
dslContext.predicateFactory().withRoot( objectFieldPath ) ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* A factory for search predicates with some Lucene-specific methods.
*/
public interface LuceneSearchPredicateFactory extends ExtendedSearchPredicateFactory<LuceneSearchPredicateFactory> {
public interface LuceneSearchPredicateFactory<SR> extends ExtendedSearchPredicateFactory<SR, LuceneSearchPredicateFactory<SR>> {

/**
* Create a predicate from a Lucene {@link Query}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@

import org.apache.lucene.search.Query;

public class LuceneSearchPredicateFactoryImpl
public class LuceneSearchPredicateFactoryImpl<SR>
extends AbstractSearchPredicateFactory<
LuceneSearchPredicateFactory,
SR,
LuceneSearchPredicateFactory<SR>,
LuceneSearchPredicateIndexScope<?>>
implements LuceneSearchPredicateFactory {
implements LuceneSearchPredicateFactory<SR> {

public LuceneSearchPredicateFactoryImpl(SearchPredicateDslContext<LuceneSearchPredicateIndexScope<?>> dslContext) {
super( dslContext );
}

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

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

Builder(PredicateDefinition definition, String predicateName, LuceneSearchIndexScope<?> scope,
Expand All @@ -82,7 +82,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 @@ -93,8 +93,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() ) );

LuceneSearchPredicate providedPredicate = LuceneSearchPredicate.from( scope, definition.create( ctx ) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
/**
* A factory for search projections with some Lucene-specific methods.
*
* @param <SR> Scope root type.
* @param <R> The type of entity references.
* @param <E> The type of entities.
* @see SearchProjectionFactory
*/
public interface LuceneSearchProjectionFactory<R, E>
extends ExtendedSearchProjectionFactory<LuceneSearchProjectionFactory<R, E>, R, E> {
public interface LuceneSearchProjectionFactory<SR, R, E>
extends ExtendedSearchProjectionFactory<SR, LuceneSearchProjectionFactory<SR, R, E>, R, E> {

/**
* Project to a Lucene {@link Document} containing all the stored fields.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.search.Explanation;

public class LuceneSearchProjectionFactoryImpl<R, E>
public class LuceneSearchProjectionFactoryImpl<SR, R, E>
extends AbstractSearchProjectionFactory<
LuceneSearchProjectionFactory<R, E>,
SR,
LuceneSearchProjectionFactory<SR, R, E>,
LuceneSearchProjectionIndexScope<?>,
R,
E>
implements LuceneSearchProjectionFactory<R, E> {
implements LuceneSearchProjectionFactory<SR, R, E> {

public LuceneSearchProjectionFactoryImpl(SearchProjectionDslContext<LuceneSearchProjectionIndexScope<?>> dslContext) {
super( dslContext );
}

@Override
public LuceneSearchProjectionFactory<R, E> withRoot(String objectFieldPath) {
public LuceneSearchProjectionFactory<SR, R, E> withRoot(String objectFieldPath) {
return new LuceneSearchProjectionFactoryImpl<>( dslContext.rescope(
dslContext.scope().withRoot( objectFieldPath ) ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
import org.hibernate.search.backend.lucene.search.sort.dsl.LuceneSearchSortFactory;
import org.hibernate.search.engine.search.query.dsl.SearchQueryOptionsStep;

public interface LuceneSearchQueryOptionsStep<H, LOS>
public interface LuceneSearchQueryOptionsStep<SR, H, LOS>
extends SearchQueryOptionsStep<
LuceneSearchQueryOptionsStep<H, LOS>,
SR,
LuceneSearchQueryOptionsStep<SR, H, LOS>,
H,
LOS,
LuceneSearchSortFactory,
LuceneSearchAggregationFactory>,
LuceneSearchSortFactory<SR>,
LuceneSearchAggregationFactory<SR>>,
LuceneSearchFetchable<H> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,34 @@
import org.hibernate.search.engine.search.projection.dsl.ProjectionFinalStep;
import org.hibernate.search.engine.search.query.dsl.SearchQuerySelectStep;

public interface LuceneSearchQuerySelectStep<R, E, LOS>
public interface LuceneSearchQuerySelectStep<SR, R, E, LOS>
extends SearchQuerySelectStep<
LuceneSearchQueryOptionsStep<E, LOS>,
SR,
LuceneSearchQueryOptionsStep<SR, E, LOS>,
R,
E,
LOS,
LuceneSearchProjectionFactory<R, E>,
LuceneSearchPredicateFactory>,
LuceneSearchQueryWhereStep<E, LOS> {
LuceneSearchProjectionFactory<SR, R, E>,
LuceneSearchPredicateFactory<SR>>,
LuceneSearchQueryWhereStep<SR, E, LOS> {

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

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

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

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

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

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

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

public interface LuceneSearchQueryWhereStep<H, LOS>
extends SearchQueryWhereStep<LuceneSearchQueryOptionsStep<H, LOS>, H, LOS, LuceneSearchPredicateFactory> {
public interface LuceneSearchQueryWhereStep<SR, H, LOS>
extends SearchQueryWhereStep<SR, LuceneSearchQueryOptionsStep<SR, H, LOS>, H, LOS, LuceneSearchPredicateFactory<SR>> {

}
Loading

0 comments on commit cbfcec9

Please sign in to comment.