diff --git a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/aggregation/impl/AbstractLuceneFieldAggregationBuilderFactory.java b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/aggregation/impl/AbstractLuceneFieldAggregationBuilderFactory.java new file mode 100644 index 00000000000..58b0b2f66cb --- /dev/null +++ b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/aggregation/impl/AbstractLuceneFieldAggregationBuilderFactory.java @@ -0,0 +1,64 @@ +/* + * Hibernate Search, full-text search for your domain model + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.search.backend.lucene.types.aggregation.impl; + +import java.lang.invoke.MethodHandles; + +import org.hibernate.search.backend.lucene.logging.impl.Log; +import org.hibernate.search.backend.lucene.types.codec.impl.LuceneFieldCodec; +import org.hibernate.search.engine.backend.types.converter.spi.DslConverter; +import org.hibernate.search.engine.backend.types.converter.spi.ProjectionConverter; +import org.hibernate.search.engine.reporting.spi.EventContexts; +import org.hibernate.search.util.common.logging.impl.LoggerFactory; + +public abstract class AbstractLuceneFieldAggregationBuilderFactory + implements LuceneFieldAggregationBuilderFactory { + protected static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() ); + + protected final boolean aggregable; + + protected final DslConverter toFieldValueConverter; + protected final ProjectionConverter fromFieldValueConverter; + + public AbstractLuceneFieldAggregationBuilderFactory( + boolean aggregable, DslConverter toFieldValueConverter, + ProjectionConverter fromFieldValueConverter) { + this.aggregable = aggregable; + this.toFieldValueConverter = toFieldValueConverter; + this.fromFieldValueConverter = fromFieldValueConverter; + } + + @Override + public boolean hasCompatibleCodec(LuceneFieldAggregationBuilderFactory other) { + if ( !getClass().equals( other.getClass() ) ) { + return false; + } + AbstractLuceneFieldAggregationBuilderFactory castedOther = + (AbstractLuceneFieldAggregationBuilderFactory) other; + return aggregable == castedOther.aggregable && getCodec().isCompatibleWith( castedOther.getCodec() ); + } + + @Override + public boolean hasCompatibleConverter(LuceneFieldAggregationBuilderFactory other) { + if ( !getClass().equals( other.getClass() ) ) { + return false; + } + AbstractLuceneFieldAggregationBuilderFactory castedOther = + (AbstractLuceneFieldAggregationBuilderFactory) other; + return toFieldValueConverter.isCompatibleWith( castedOther.toFieldValueConverter ) + && fromFieldValueConverter.isCompatibleWith( castedOther.fromFieldValueConverter ); + } + + protected abstract LuceneFieldCodec getCodec(); + + protected void checkAggregable(String absoluteFieldPath) { + if ( !aggregable ) { + throw log.nonAggregableField( absoluteFieldPath, + EventContexts.fromIndexFieldAbsolutePath( absoluteFieldPath ) ); + } + } +} diff --git a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/aggregation/impl/AbstractLuceneStandardFieldAggregationBuilderFactory.java b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/aggregation/impl/AbstractLuceneStandardFieldAggregationBuilderFactory.java index 1cba17f5449..eb4b7494ce1 100644 --- a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/aggregation/impl/AbstractLuceneStandardFieldAggregationBuilderFactory.java +++ b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/aggregation/impl/AbstractLuceneStandardFieldAggregationBuilderFactory.java @@ -6,26 +6,15 @@ */ package org.hibernate.search.backend.lucene.types.aggregation.impl; -import java.lang.invoke.MethodHandles; - -import org.hibernate.search.backend.lucene.logging.impl.Log; -import org.hibernate.search.backend.lucene.types.codec.impl.LuceneFieldCodec; import org.hibernate.search.engine.backend.types.converter.spi.ProjectionConverter; import org.hibernate.search.engine.backend.types.converter.spi.DslConverter; import org.hibernate.search.engine.reporting.spi.EventContexts; import org.hibernate.search.engine.search.common.ValueConvert; -import org.hibernate.search.util.common.logging.impl.LoggerFactory; abstract class AbstractLuceneStandardFieldAggregationBuilderFactory - implements LuceneFieldAggregationBuilderFactory { - - private static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() ); + extends AbstractLuceneFieldAggregationBuilderFactory { - private final boolean aggregable; - - private final DslConverter toFieldValueConverter; private final DslConverter rawToFieldValueConverter; - private final ProjectionConverter fromFieldValueConverter; private final ProjectionConverter rawFromFieldValueConverter; AbstractLuceneStandardFieldAggregationBuilderFactory(boolean aggregable, @@ -33,43 +22,11 @@ abstract class AbstractLuceneStandardFieldAggregationBuilderFactory DslConverter rawToFieldValueConverter, ProjectionConverter fromFieldValueConverter, ProjectionConverter rawFromFieldValueConverter) { - this.aggregable = aggregable; - this.toFieldValueConverter = toFieldValueConverter; + super( aggregable, toFieldValueConverter, fromFieldValueConverter ); this.rawToFieldValueConverter = rawToFieldValueConverter; - this.fromFieldValueConverter = fromFieldValueConverter; this.rawFromFieldValueConverter = rawFromFieldValueConverter; } - @Override - public boolean hasCompatibleCodec(LuceneFieldAggregationBuilderFactory other) { - if ( !getClass().equals( other.getClass() ) ) { - return false; - } - AbstractLuceneStandardFieldAggregationBuilderFactory castedOther = - (AbstractLuceneStandardFieldAggregationBuilderFactory) other; - return aggregable == castedOther.aggregable && getCodec().isCompatibleWith( castedOther.getCodec() ); - } - - @Override - public boolean hasCompatibleConverter(LuceneFieldAggregationBuilderFactory other) { - if ( !getClass().equals( other.getClass() ) ) { - return false; - } - AbstractLuceneStandardFieldAggregationBuilderFactory castedOther = - (AbstractLuceneStandardFieldAggregationBuilderFactory) other; - return toFieldValueConverter.isCompatibleWith( castedOther.toFieldValueConverter ) - && fromFieldValueConverter.isCompatibleWith( castedOther.fromFieldValueConverter ); - } - - protected abstract LuceneFieldCodec getCodec(); - - protected void checkAggregable(String absoluteFieldPath) { - if ( !aggregable ) { - throw log.nonAggregableField( absoluteFieldPath, - EventContexts.fromIndexFieldAbsolutePath( absoluteFieldPath ) ); - } - } - protected DslConverter getToFieldValueConverter( String absoluteFieldPath, Class expectedType, ValueConvert convert) { DslConverter result; diff --git a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/aggregation/impl/LuceneGeoPointFieldAggregationBuilderFactory.java b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/aggregation/impl/LuceneGeoPointFieldAggregationBuilderFactory.java index 87fdaa8a9ce..9480081a38c 100644 --- a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/aggregation/impl/LuceneGeoPointFieldAggregationBuilderFactory.java +++ b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/aggregation/impl/LuceneGeoPointFieldAggregationBuilderFactory.java @@ -21,23 +21,17 @@ import org.hibernate.search.util.common.logging.impl.LoggerFactory; public class LuceneGeoPointFieldAggregationBuilderFactory - implements LuceneFieldAggregationBuilderFactory { + extends AbstractLuceneFieldAggregationBuilderFactory { private static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() ); - private final boolean aggregable; - - private final DslConverter toFieldValueConverter; - private final ProjectionConverter fromFieldValueConverter; private final LuceneFieldCodec codec; public LuceneGeoPointFieldAggregationBuilderFactory(boolean aggregable, DslConverter toFieldValueConverter, ProjectionConverter fromFieldValueConverter, LuceneFieldCodec codec) { - this.aggregable = aggregable; - this.toFieldValueConverter = toFieldValueConverter; - this.fromFieldValueConverter = fromFieldValueConverter; + super( aggregable, toFieldValueConverter, fromFieldValueConverter ); this.codec = codec; } @@ -58,23 +52,7 @@ public RangeAggregationBuilder createRangeAggregationBuilder(LuceneSearch } @Override - public boolean hasCompatibleCodec(LuceneFieldAggregationBuilderFactory other) { - if ( !getClass().equals( other.getClass() ) ) { - return false; - } - LuceneGeoPointFieldAggregationBuilderFactory castedOther = - (LuceneGeoPointFieldAggregationBuilderFactory) other; - return aggregable == castedOther.aggregable && codec.isCompatibleWith( castedOther.codec ); - } - - @Override - public boolean hasCompatibleConverter(LuceneFieldAggregationBuilderFactory other) { - if ( !getClass().equals( other.getClass() ) ) { - return false; - } - LuceneGeoPointFieldAggregationBuilderFactory castedOther = - (LuceneGeoPointFieldAggregationBuilderFactory) other; - return toFieldValueConverter.isCompatibleWith( castedOther.toFieldValueConverter ) - && fromFieldValueConverter.isCompatibleWith( castedOther.fromFieldValueConverter ); + protected LuceneFieldCodec getCodec() { + return codec; } } diff --git a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/aggregation/impl/LuceneNumericFieldAggregationBuilderFactory.java b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/aggregation/impl/LuceneNumericFieldAggregationBuilderFactory.java index 44e1abf088e..eb09a54b63e 100644 --- a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/aggregation/impl/LuceneNumericFieldAggregationBuilderFactory.java +++ b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/aggregation/impl/LuceneNumericFieldAggregationBuilderFactory.java @@ -15,8 +15,7 @@ import org.hibernate.search.engine.search.common.ValueConvert; public class LuceneNumericFieldAggregationBuilderFactory - extends AbstractLuceneStandardFieldAggregationBuilderFactory - implements LuceneFieldAggregationBuilderFactory { + extends AbstractLuceneStandardFieldAggregationBuilderFactory { private final AbstractLuceneNumericFieldCodec codec; diff --git a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/dsl/impl/LuceneGeoPointIndexFieldTypeOptionsStep.java b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/dsl/impl/LuceneGeoPointIndexFieldTypeOptionsStep.java index b0bebcbf257..03ec629b142 100644 --- a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/dsl/impl/LuceneGeoPointIndexFieldTypeOptionsStep.java +++ b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/dsl/impl/LuceneGeoPointIndexFieldTypeOptionsStep.java @@ -53,7 +53,7 @@ public LuceneIndexFieldType toIndexFieldType() { new LuceneGeoPointFieldPredicateBuilderFactory( resolvedSearchable, dslConverter, codec ), - new LuceneGeoPointFieldSortBuilderFactory( resolvedSortable ), + new LuceneGeoPointFieldSortBuilderFactory( resolvedSortable, codec ), new LuceneGeoPointFieldProjectionBuilderFactory( resolvedProjectable, codec, projectionConverter, rawProjectionConverter ), diff --git a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/projection/impl/AbstractLuceneFieldProjectionBuilderFactory.java b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/projection/impl/AbstractLuceneFieldProjectionBuilderFactory.java new file mode 100644 index 00000000000..3002bb2e57d --- /dev/null +++ b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/projection/impl/AbstractLuceneFieldProjectionBuilderFactory.java @@ -0,0 +1,93 @@ +/* + * Hibernate Search, full-text search for your domain model + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.search.backend.lucene.types.projection.impl; + +import java.lang.invoke.MethodHandles; +import java.util.Set; + +import org.hibernate.search.backend.lucene.logging.impl.Log; +import org.hibernate.search.backend.lucene.search.projection.impl.LuceneFieldProjectionBuilder; +import org.hibernate.search.backend.lucene.types.codec.impl.LuceneFieldCodec; +import org.hibernate.search.engine.backend.types.converter.spi.ProjectionConverter; +import org.hibernate.search.engine.reporting.spi.EventContexts; +import org.hibernate.search.engine.search.common.ValueConvert; +import org.hibernate.search.engine.search.projection.spi.FieldProjectionBuilder; +import org.hibernate.search.util.common.logging.impl.LoggerFactory; + +public abstract class AbstractLuceneFieldProjectionBuilderFactory implements LuceneFieldProjectionBuilderFactory { + protected static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() ); + + protected final boolean projectable; + + protected final ProjectionConverter converter; + protected final ProjectionConverter rawConverter; + + protected final LuceneFieldCodec codec; + + public AbstractLuceneFieldProjectionBuilderFactory( + boolean projectable, ProjectionConverter converter, + ProjectionConverter rawConverter, LuceneFieldCodec codec) { + this.projectable = projectable; + this.converter = converter; + this.rawConverter = rawConverter; + this.codec = codec; + } + + @Override + @SuppressWarnings("unchecked") // We check the cast is legal by asking the converter + public FieldProjectionBuilder createFieldValueProjectionBuilder(Set indexNames, String absoluteFieldPath, String nestedDocumentPath, + Class expectedType, ValueConvert convert) { + checkProjectable( absoluteFieldPath ); + + ProjectionConverter requestConverter = getConverter( convert ); + if ( !requestConverter.isConvertedTypeAssignableTo( expectedType ) ) { + throw log.invalidProjectionInvalidType( absoluteFieldPath, expectedType, + EventContexts.fromIndexFieldAbsolutePath( absoluteFieldPath ) ); + } + + return (FieldProjectionBuilder) new LuceneFieldProjectionBuilder<>( + indexNames, absoluteFieldPath, nestedDocumentPath, requestConverter, codec + ); + } + + @Override + public boolean hasCompatibleCodec(LuceneFieldProjectionBuilderFactory other) { + if ( !getClass().equals( other.getClass() ) ) { + return false; + } + AbstractLuceneFieldProjectionBuilderFactory castedOther = + (AbstractLuceneFieldProjectionBuilderFactory) other; + return projectable == castedOther.projectable && codec.isCompatibleWith( castedOther.codec ); + } + + @Override + public boolean hasCompatibleConverter(LuceneFieldProjectionBuilderFactory other) { + if ( !getClass().equals( other.getClass() ) ) { + return false; + } + AbstractLuceneFieldProjectionBuilderFactory castedOther = + (AbstractLuceneFieldProjectionBuilderFactory) other; + return converter.isCompatibleWith( castedOther.converter ); + } + + protected void checkProjectable(String absoluteFieldPath) { + if ( !projectable ) { + throw log.nonProjectableField( absoluteFieldPath, + EventContexts.fromIndexFieldAbsolutePath( absoluteFieldPath ) ); + } + } + + protected ProjectionConverter getConverter(ValueConvert convert) { + switch ( convert ) { + case NO: + return rawConverter; + case YES: + default: + return converter; + } + } +} diff --git a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/projection/impl/LuceneGeoPointFieldProjectionBuilderFactory.java b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/projection/impl/LuceneGeoPointFieldProjectionBuilderFactory.java index a53574b7e3f..a84b04a5261 100644 --- a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/projection/impl/LuceneGeoPointFieldProjectionBuilderFactory.java +++ b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/projection/impl/LuceneGeoPointFieldProjectionBuilderFactory.java @@ -6,97 +6,28 @@ */ package org.hibernate.search.backend.lucene.types.projection.impl; -import java.lang.invoke.MethodHandles; import java.util.Set; -import org.hibernate.search.backend.lucene.logging.impl.Log; import org.hibernate.search.backend.lucene.search.projection.impl.LuceneDistanceToFieldProjectionBuilder; -import org.hibernate.search.backend.lucene.search.projection.impl.LuceneFieldProjectionBuilder; import org.hibernate.search.backend.lucene.types.codec.impl.LuceneFieldCodec; import org.hibernate.search.engine.backend.types.converter.spi.ProjectionConverter; -import org.hibernate.search.engine.reporting.spi.EventContexts; -import org.hibernate.search.engine.search.common.ValueConvert; import org.hibernate.search.engine.search.projection.spi.DistanceToFieldProjectionBuilder; -import org.hibernate.search.engine.search.projection.spi.FieldProjectionBuilder; import org.hibernate.search.engine.spatial.GeoPoint; -import org.hibernate.search.util.common.logging.impl.LoggerFactory; -public class LuceneGeoPointFieldProjectionBuilderFactory implements LuceneFieldProjectionBuilderFactory { - - private static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() ); - - private final boolean projectable; - - private final ProjectionConverter converter; - private final ProjectionConverter rawConverter; - private final LuceneFieldCodec codec; +public class LuceneGeoPointFieldProjectionBuilderFactory extends AbstractLuceneFieldProjectionBuilderFactory { public LuceneGeoPointFieldProjectionBuilderFactory(boolean projectable, LuceneFieldCodec codec, ProjectionConverter converter, ProjectionConverter rawConverter) { - this.projectable = projectable; - this.converter = converter; - this.rawConverter = rawConverter; - this.codec = codec; + super( projectable, converter, rawConverter, codec ); } @Override - @SuppressWarnings("unchecked") // We check the cast is legal by asking the converter - public FieldProjectionBuilder createFieldValueProjectionBuilder(Set indexNames, String absoluteFieldPath, String nestedDocumentPath, - Class expectedType, ValueConvert convert) { - checkProjectable( absoluteFieldPath, projectable ); - - ProjectionConverter requestConverter = getConverter( convert ); - if ( !requestConverter.isConvertedTypeAssignableTo( expectedType ) ) { - throw log.invalidProjectionInvalidType( absoluteFieldPath, expectedType, - EventContexts.fromIndexFieldAbsolutePath( absoluteFieldPath ) ); - } - - return (FieldProjectionBuilder) new LuceneFieldProjectionBuilder<>( indexNames, absoluteFieldPath, nestedDocumentPath, requestConverter, codec ); - } - - @Override - public DistanceToFieldProjectionBuilder createDistanceProjectionBuilder(Set indexNames, String absoluteFieldPath, String nestedDocumentPath, + public DistanceToFieldProjectionBuilder createDistanceProjectionBuilder(Set indexNames, + String absoluteFieldPath, String nestedDocumentPath, GeoPoint center) { - checkProjectable( absoluteFieldPath, projectable ); + checkProjectable( absoluteFieldPath ); return new LuceneDistanceToFieldProjectionBuilder( indexNames, absoluteFieldPath, nestedDocumentPath, center ); } - - @Override - public boolean hasCompatibleCodec(LuceneFieldProjectionBuilderFactory other) { - if ( !getClass().equals( other.getClass() ) ) { - return false; - } - LuceneGeoPointFieldProjectionBuilderFactory castedOther = - (LuceneGeoPointFieldProjectionBuilderFactory) other; - return projectable == castedOther.projectable && codec.isCompatibleWith( castedOther.codec ); - } - - @Override - public boolean hasCompatibleConverter(LuceneFieldProjectionBuilderFactory other) { - if ( !getClass().equals( other.getClass() ) ) { - return false; - } - LuceneGeoPointFieldProjectionBuilderFactory castedOther = - (LuceneGeoPointFieldProjectionBuilderFactory) other; - return converter.isCompatibleWith( castedOther.converter ); - } - - private static void checkProjectable(String absoluteFieldPath, boolean projectable) { - if ( !projectable ) { - throw log.nonProjectableField( absoluteFieldPath, - EventContexts.fromIndexFieldAbsolutePath( absoluteFieldPath ) ); - } - } - - private ProjectionConverter getConverter(ValueConvert convert) { - switch ( convert ) { - case NO: - return rawConverter; - case YES: - default: - return converter; - } - } } diff --git a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/projection/impl/LuceneStandardFieldProjectionBuilderFactory.java b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/projection/impl/LuceneStandardFieldProjectionBuilderFactory.java index 161bfffc8df..88b86d6224d 100644 --- a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/projection/impl/LuceneStandardFieldProjectionBuilderFactory.java +++ b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/projection/impl/LuceneStandardFieldProjectionBuilderFactory.java @@ -6,57 +6,24 @@ */ package org.hibernate.search.backend.lucene.types.projection.impl; -import java.lang.invoke.MethodHandles; import java.util.Set; -import org.hibernate.search.backend.lucene.logging.impl.Log; -import org.hibernate.search.backend.lucene.search.projection.impl.LuceneFieldProjectionBuilder; import org.hibernate.search.backend.lucene.types.codec.impl.LuceneFieldCodec; import org.hibernate.search.engine.backend.types.converter.spi.ProjectionConverter; import org.hibernate.search.engine.reporting.spi.EventContexts; -import org.hibernate.search.engine.search.common.ValueConvert; import org.hibernate.search.engine.search.projection.spi.DistanceToFieldProjectionBuilder; -import org.hibernate.search.engine.search.projection.spi.FieldProjectionBuilder; import org.hibernate.search.engine.spatial.GeoPoint; -import org.hibernate.search.util.common.logging.impl.LoggerFactory; /** * @param The field type exposed to the mapper. * @see LuceneFieldCodec */ -public class LuceneStandardFieldProjectionBuilderFactory implements LuceneFieldProjectionBuilderFactory { - - private static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() ); - - private final boolean projectable; - - private final ProjectionConverter converter; - private final ProjectionConverter rawConverter; - - private final LuceneFieldCodec codec; +public class LuceneStandardFieldProjectionBuilderFactory extends AbstractLuceneFieldProjectionBuilderFactory { public LuceneStandardFieldProjectionBuilderFactory(boolean projectable, ProjectionConverter converter, ProjectionConverter rawConverter, LuceneFieldCodec codec) { - this.projectable = projectable; - this.converter = converter; - this.rawConverter = rawConverter; - this.codec = codec; - } - - @Override - @SuppressWarnings("unchecked") // We check the cast is legal by asking the converter - public FieldProjectionBuilder createFieldValueProjectionBuilder(Set indexNames, String absoluteFieldPath, String nestedDocumentPath, - Class expectedType, ValueConvert convert) { - checkProjectable( absoluteFieldPath, projectable ); - - ProjectionConverter requestConverter = getConverter( convert ); - if ( !requestConverter.isConvertedTypeAssignableTo( expectedType ) ) { - throw log.invalidProjectionInvalidType( absoluteFieldPath, expectedType, - EventContexts.fromIndexFieldAbsolutePath( absoluteFieldPath ) ); - } - - return (FieldProjectionBuilder) new LuceneFieldProjectionBuilder<>( indexNames, absoluteFieldPath, nestedDocumentPath, requestConverter, codec ); + super( projectable, converter, rawConverter, codec ); } @Override @@ -67,40 +34,4 @@ public DistanceToFieldProjectionBuilder createDistanceProjectionBuilder(Set castedOther = - (LuceneStandardFieldProjectionBuilderFactory) other; - return projectable == castedOther.projectable && codec.isCompatibleWith( castedOther.codec ); - } - - @Override - public boolean hasCompatibleConverter(LuceneFieldProjectionBuilderFactory other) { - if ( !getClass().equals( other.getClass() ) ) { - return false; - } - LuceneStandardFieldProjectionBuilderFactory castedOther = - (LuceneStandardFieldProjectionBuilderFactory) other; - return converter.isCompatibleWith( castedOther.converter ); - } - - private static void checkProjectable(String absoluteFieldPath, boolean projectable) { - if ( !projectable ) { - throw log.nonProjectableField( absoluteFieldPath, - EventContexts.fromIndexFieldAbsolutePath( absoluteFieldPath ) ); - } - } - - private ProjectionConverter getConverter(ValueConvert convert) { - switch ( convert ) { - case NO: - return rawConverter; - case YES: - default: - return converter; - } - } } diff --git a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/sort/impl/AbstractLuceneFieldSortBuilderFactory.java b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/sort/impl/AbstractLuceneFieldSortBuilderFactory.java new file mode 100644 index 00000000000..d862faf41ff --- /dev/null +++ b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/sort/impl/AbstractLuceneFieldSortBuilderFactory.java @@ -0,0 +1,49 @@ +/* + * Hibernate Search, full-text search for your domain model + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.search.backend.lucene.types.sort.impl; + +import java.lang.invoke.MethodHandles; + +import org.hibernate.search.backend.lucene.logging.impl.Log; +import org.hibernate.search.backend.lucene.types.codec.impl.LuceneFieldCodec; +import org.hibernate.search.engine.reporting.spi.EventContexts; +import org.hibernate.search.util.common.logging.impl.LoggerFactory; + +public abstract class AbstractLuceneFieldSortBuilderFactory> + implements LuceneFieldSortBuilderFactory { + protected static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() ); + + protected final boolean sortable; + + protected final C codec; + + public AbstractLuceneFieldSortBuilderFactory(boolean sortable, C codec) { + this.sortable = sortable; + this.codec = codec; + } + + @Override + public boolean hasCompatibleCodec(LuceneFieldSortBuilderFactory other) { + if ( this == other ) { + return true; + } + if ( other.getClass() != this.getClass() ) { + return false; + } + + AbstractLuceneFieldSortBuilderFactory otherFactory = + (AbstractLuceneFieldSortBuilderFactory) other; + return sortable == otherFactory.sortable && codec.isCompatibleWith( otherFactory.codec ); + } + + protected void checkSortable(String absoluteFieldPath) { + if ( !sortable ) { + throw log.unsortableField( absoluteFieldPath, + EventContexts.fromIndexFieldAbsolutePath( absoluteFieldPath ) ); + } + } +} diff --git a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/sort/impl/AbstractLuceneStandardFieldSortBuilderFactory.java b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/sort/impl/AbstractLuceneStandardFieldSortBuilderFactory.java index d5c7c6d519e..6481991d946 100644 --- a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/sort/impl/AbstractLuceneStandardFieldSortBuilderFactory.java +++ b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/sort/impl/AbstractLuceneStandardFieldSortBuilderFactory.java @@ -6,16 +6,12 @@ */ package org.hibernate.search.backend.lucene.types.sort.impl; -import java.lang.invoke.MethodHandles; - -import org.hibernate.search.backend.lucene.logging.impl.Log; import org.hibernate.search.backend.lucene.search.sort.impl.LuceneSearchSortBuilder; import org.hibernate.search.backend.lucene.types.codec.impl.LuceneStandardFieldCodec; import org.hibernate.search.engine.backend.types.converter.spi.DslConverter; import org.hibernate.search.engine.reporting.spi.EventContexts; import org.hibernate.search.engine.search.sort.spi.DistanceSortBuilder; import org.hibernate.search.engine.spatial.GeoPoint; -import org.hibernate.search.util.common.logging.impl.LoggerFactory; /** * @param The field type exposed to the mapper. @@ -23,24 +19,17 @@ * @see LuceneStandardFieldCodec */ abstract class AbstractLuceneStandardFieldSortBuilderFactory> - implements LuceneFieldSortBuilderFactory { - - private static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() ); - - private final boolean sortable; + extends AbstractLuceneFieldSortBuilderFactory { protected final DslConverter converter; protected final DslConverter rawConverter; - protected final C codec; - protected AbstractLuceneStandardFieldSortBuilderFactory(boolean sortable, DslConverter converter, DslConverter rawConverter, C codec) { - this.sortable = sortable; + super( sortable, codec ); this.converter = converter; this.rawConverter = rawConverter; - this.codec = codec; } @Override @@ -51,19 +40,6 @@ public DistanceSortBuilder createDistanceSortBuilder(St ); } - @Override - public boolean hasCompatibleCodec(LuceneFieldSortBuilderFactory other) { - if ( this == other ) { - return true; - } - if ( other.getClass() != this.getClass() ) { - return false; - } - - AbstractLuceneStandardFieldSortBuilderFactory otherFactory = (AbstractLuceneStandardFieldSortBuilderFactory) other; - return sortable == otherFactory.sortable && codec.isCompatibleWith( otherFactory.codec ); - } - @Override public boolean hasCompatibleConverter(LuceneFieldSortBuilderFactory other) { if ( this == other ) { @@ -77,10 +53,4 @@ public boolean hasCompatibleConverter(LuceneFieldSortBuilderFactory other) { return converter.isCompatibleWith( otherFactory.converter ); } - protected void checkSortable(String absoluteFieldPath) { - if ( !sortable ) { - throw log.unsortableField( absoluteFieldPath, - EventContexts.fromIndexFieldAbsolutePath( absoluteFieldPath ) ); - } - } } diff --git a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/sort/impl/LuceneGeoPointFieldSortBuilderFactory.java b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/sort/impl/LuceneGeoPointFieldSortBuilderFactory.java index 53d673be134..dd32baec28c 100644 --- a/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/sort/impl/LuceneGeoPointFieldSortBuilderFactory.java +++ b/backend/lucene/src/main/java/org/hibernate/search/backend/lucene/types/sort/impl/LuceneGeoPointFieldSortBuilderFactory.java @@ -6,26 +6,20 @@ */ package org.hibernate.search.backend.lucene.types.sort.impl; -import java.lang.invoke.MethodHandles; - -import org.hibernate.search.backend.lucene.logging.impl.Log; import org.hibernate.search.backend.lucene.scope.model.impl.LuceneCompatibilityChecker; import org.hibernate.search.backend.lucene.search.impl.LuceneSearchContext; import org.hibernate.search.backend.lucene.search.sort.impl.LuceneSearchSortBuilder; +import org.hibernate.search.backend.lucene.types.codec.impl.LuceneGeoPointFieldCodec; import org.hibernate.search.engine.reporting.spi.EventContexts; import org.hibernate.search.engine.search.sort.spi.DistanceSortBuilder; import org.hibernate.search.engine.search.sort.spi.FieldSortBuilder; import org.hibernate.search.engine.spatial.GeoPoint; -import org.hibernate.search.util.common.logging.impl.LoggerFactory; - -public class LuceneGeoPointFieldSortBuilderFactory implements LuceneFieldSortBuilderFactory { - private static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() ); +public class LuceneGeoPointFieldSortBuilderFactory + extends AbstractLuceneFieldSortBuilderFactory { - private final boolean sortable; - - public LuceneGeoPointFieldSortBuilderFactory(boolean sortable) { - this.sortable = sortable; + public LuceneGeoPointFieldSortBuilderFactory(boolean sortable, LuceneGeoPointFieldCodec codec) { + super( sortable, codec ); } @Override @@ -43,25 +37,9 @@ public DistanceSortBuilder createDistanceSortBuilder(St return new LuceneGeoPointDistanceSortBuilder( absoluteFieldPath, nestedDocumentPath, center ); } - @Override - public boolean hasCompatibleCodec(LuceneFieldSortBuilderFactory other) { - if ( other.getClass() != this.getClass() ) { - return false; - } - - LuceneGeoPointFieldSortBuilderFactory otherFactory = (LuceneGeoPointFieldSortBuilderFactory) other; - return otherFactory.sortable == this.sortable; - } - @Override public boolean hasCompatibleConverter(LuceneFieldSortBuilderFactory other) { return true; } - protected void checkSortable(String absoluteFieldPath) { - if ( !sortable ) { - throw log.unsortableField( absoluteFieldPath, - EventContexts.fromIndexFieldAbsolutePath( absoluteFieldPath ) ); - } - } }