Skip to content

Commit

Permalink
Merge pull request #4478 from yrodiere/hsearch-6-0-0-beta1
Browse files Browse the repository at this point in the history
Upgrade Hibernate Search to 6.0.0.Beta1
  • Loading branch information
gsmet authored Oct 14, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 4223d45 + 664cb76 commit 89083cd
Showing 12 changed files with 122 additions and 97 deletions.
2 changes: 1 addition & 1 deletion bom/runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@
<javax.el-impl.version>3.0.1-b11</javax.el-impl.version>
<hibernate-validator.version>6.1.0.Alpha6</hibernate-validator.version>
<hibernate-orm.version>5.4.6.Final</hibernate-orm.version>
<hibernate-search.version>6.0.0.Alpha9</hibernate-search.version>
<hibernate-search.version>6.0.0.Beta1</hibernate-search.version>
<narayana.version>5.9.8.Final</narayana.version>
<jboss-transaction-api_1.2_spec.version>1.1.1.Final</jboss-transaction-api_1.2_spec.version>
<agroal.version>1.6</agroal.version>
4 changes: 2 additions & 2 deletions build-parent/pom.xml
Original file line number Diff line number Diff line change
@@ -16,8 +16,8 @@

<properties>
<!-- Maven plugin versions -->
<elasticsearch-maven-plugin.version>6.13</elasticsearch-maven-plugin.version>
<elasticsearch-server.version>7.3.0</elasticsearch-server.version>
<elasticsearch-maven-plugin.version>6.14</elasticsearch-maven-plugin.version>
<elasticsearch-server.version>7.3.1</elasticsearch-server.version>
<scala-maven-plugin.version>4.1.1</scala-maven-plugin.version>

<!-- These properties are needed in order for them to be resolvable by the generated projects -->
39 changes: 21 additions & 18 deletions docs/src/main/asciidoc/hibernate-search-guide.adoc
Original file line number Diff line number Diff line change
@@ -14,9 +14,10 @@ We will also explore how you can can query your Elasticsearch cluster using the

[WARNING]
====
The version of Hibernate Search shipped with Quarkus is still an Alpha.
The version of Hibernate Search shipped with Quarkus is still a Beta.
While the code is of production quality and thoroughly tested, some features are still missing, performance might not be optimal and some APIs might change before the final release.
While APIs are quite stable and the code is of production quality and thoroughly tested,
some features are still missing, performance might not be optimal and some APIs might change before the final release.
====

== Prerequisites
@@ -437,15 +438,15 @@ public class AnalysisConfigurer implements ElasticsearchAnalysisConfigurer {
@Override
public void configure(ElasticsearchAnalysisDefinitionContainerContext context) {
context.analyzer("name").custom() // <1>
.withTokenizer("standard")
.withTokenFilters("asciifolding", "lowercase");
.tokenizer("standard")
.tokenFilters("asciifolding", "lowercase");
context.analyzer("english").custom() // <2>
.withTokenizer("standard")
.withTokenFilters("asciifolding", "lowercase", "porter_stem");
.tokenizer("standard")
.tokenFilters("asciifolding", "lowercase", "porter_stem");
context.normalizer("sort").custom() // <3>
.withTokenFilters("asciifolding", "lowercase");
.tokenFilters("asciifolding", "lowercase");
}
}
----
@@ -474,17 +475,18 @@ In our existing `LibraryResource`, we just need to inject the following methods
@GET
@Path("author/search")
@Transactional
public List<Author> searchAuthors(@QueryParam("pattern") String pattern) { // <3>
public List<Author> searchAuthors(@QueryParam("pattern") String pattern, // <3>
@QueryParam("size") Optional<Integer> size) {
return Search.session(em) // <4>
.search(Author.class) // <5>
.predicate(f ->
pattern == null || pattern.trim().isEmpty() ?
f.matchAll() : // <6>
f.simpleQueryString()
.onFields("firstName", "lastName", "books.title").matching(pattern) // <7>
.fields("firstName", "lastName", "books.title").matching(pattern) // <7>
)
.sort(f -> f.byField("lastName_sort").then().byField("firstName_sort")) // <8>
.fetchHits(); // <9>
.sort(f -> f.field("lastName_sort").then().field("firstName_sort")) // <8>
.fetchHits(size.orElse(20)); // <9>
}
----
<1> Important point: we need a transactional context for these methods.
@@ -499,7 +501,7 @@ the mass indexer should then only be used when you change your indexing configur
<6> We create a predicate: if the pattern is empty, we use a `matchAll()` predicate.
<7> If we have a valid pattern, we create a https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html[`simpleQueryString()`] predicate on the `firstName`, `lastName` and `books.title` fields matching our pattern.
<8> We define the sort order of our results. Here we sort by last name, then by first name. Note that we use the specific fields we created for sorting.
<9> This is self explanatory. Obviously, paging is also supported.
<9> Fetch the `size` top hits, `20` by default. Obviously, paging is also supported.

[NOTE]
====
@@ -526,8 +528,8 @@ quarkus.hibernate-orm.database.generation=drop-and-create <3>
quarkus.hibernate-orm.sql-load-script=import.sql <4>
quarkus.hibernate-search.elasticsearch.version=7 <5>
quarkus.hibernate-search.elasticsearch.analysis-configurer=org.acme.hibernate.search.elasticsearch.config.AnalysisConfigurer <6>
quarkus.hibernate-search.elasticsearch.automatic-indexing.synchronization-strategy=searchable <7>
quarkus.hibernate-search.elasticsearch.analysis.configurer=org.acme.hibernate.search.elasticsearch.config.AnalysisConfigurer <6>
quarkus.hibernate-search.elasticsearch.automatic-indexing.synchronization.strategy=searchable <7>
quarkus.hibernate-search.elasticsearch.index-defaults.lifecycle.strategy=drop-and-create <8>
quarkus.hibernate-search.elasticsearch.index-defaults.lifecycle.required-status=yellow <9>
----
@@ -590,7 +592,7 @@ Let's use Docker to start one of each:

[source, shell]
----
docker run -it --rm=true --name elasticsearch_quarkus_test -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.0.1
docker run -it --rm=true --name elasticsearch_quarkus_test -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.3.1
----

[source, shell]
@@ -636,19 +638,20 @@ In a real life application, it is obviously something you won't do at startup.

If you are interested into learning more about Hibernate Search 6, the Hibernate team has https://docs.jboss.org/hibernate/search/6.0/reference/en-US/html_single/[some documentation] in the works.

It is still very much a work in progress but it can guide you in your exploration.
It is still work in progress but covers all main concepts and features,
so it can guide you in your exploration.

== FAQ

=== Why Hibernate Search 6 (and not a fully supported version)?

To optimize the Hibernate Search bootstrap for Quarkus, the Hibernate team had to reorganize things a bit (collect the metadata offline, start the Elasticsearch client later...).

This couldn't be done in the 5.x code base so we decided to go with the in progress Hibernate Search 6.
This couldn't be done in the 5.x code base so we decided to go with the in-progress Hibernate Search 6.

=== Can I really use it?

While Hibernate Search 6 is still at Alpha stage, the code is of production quality and can be relied on.
While Hibernate Search 6 is still at Beta stage, the code is of production quality and can be relied on.

What we don't guarantee is that there might be API changes along the way to the final release of Hibernate Search 6 and you might have to adapt your code.

Original file line number Diff line number Diff line change
@@ -3,28 +3,28 @@
import java.util.Arrays;
import java.util.List;

import org.hibernate.search.backend.elasticsearch.analysis.model.impl.esnative.AbstractCompositeAnalysisDefinition;
import org.hibernate.search.backend.elasticsearch.analysis.model.impl.esnative.AnalysisDefinition;
import org.hibernate.search.backend.elasticsearch.analysis.model.impl.esnative.AnalysisDefinitionJsonAdapterFactory;
import org.hibernate.search.backend.elasticsearch.analysis.model.impl.esnative.AnalyzerDefinition;
import org.hibernate.search.backend.elasticsearch.analysis.model.impl.esnative.AnalyzerDefinitionJsonAdapterFactory;
import org.hibernate.search.backend.elasticsearch.analysis.model.impl.esnative.CharFilterDefinition;
import org.hibernate.search.backend.elasticsearch.analysis.model.impl.esnative.NormalizerDefinition;
import org.hibernate.search.backend.elasticsearch.analysis.model.impl.esnative.NormalizerDefinitionJsonAdapterFactory;
import org.hibernate.search.backend.elasticsearch.analysis.model.impl.esnative.TokenFilterDefinition;
import org.hibernate.search.backend.elasticsearch.analysis.model.impl.esnative.TokenizerDefinition;
import org.hibernate.search.backend.elasticsearch.document.model.impl.esnative.AbstractTypeMapping;
import org.hibernate.search.backend.elasticsearch.document.model.impl.esnative.AbstractTypeMappingJsonAdapterFactory;
import org.hibernate.search.backend.elasticsearch.document.model.impl.esnative.DynamicType;
import org.hibernate.search.backend.elasticsearch.document.model.impl.esnative.ElasticsearchFormatJsonAdapter;
import org.hibernate.search.backend.elasticsearch.document.model.impl.esnative.ElasticsearchRoutingTypeJsonAdapter;
import org.hibernate.search.backend.elasticsearch.document.model.impl.esnative.PropertyMapping;
import org.hibernate.search.backend.elasticsearch.document.model.impl.esnative.PropertyMappingJsonAdapterFactory;
import org.hibernate.search.backend.elasticsearch.document.model.impl.esnative.RootTypeMapping;
import org.hibernate.search.backend.elasticsearch.document.model.impl.esnative.RootTypeMappingJsonAdapterFactory;
import org.hibernate.search.backend.elasticsearch.document.model.impl.esnative.RoutingType;
import org.hibernate.search.backend.elasticsearch.index.settings.impl.esnative.Analysis;
import org.hibernate.search.backend.elasticsearch.index.settings.impl.esnative.IndexSettings;
import org.hibernate.search.backend.elasticsearch.analysis.model.esnative.impl.AbstractCompositeAnalysisDefinition;
import org.hibernate.search.backend.elasticsearch.analysis.model.esnative.impl.AnalysisDefinition;
import org.hibernate.search.backend.elasticsearch.analysis.model.esnative.impl.AnalysisDefinitionJsonAdapterFactory;
import org.hibernate.search.backend.elasticsearch.analysis.model.esnative.impl.AnalyzerDefinition;
import org.hibernate.search.backend.elasticsearch.analysis.model.esnative.impl.AnalyzerDefinitionJsonAdapterFactory;
import org.hibernate.search.backend.elasticsearch.analysis.model.esnative.impl.CharFilterDefinition;
import org.hibernate.search.backend.elasticsearch.analysis.model.esnative.impl.NormalizerDefinition;
import org.hibernate.search.backend.elasticsearch.analysis.model.esnative.impl.NormalizerDefinitionJsonAdapterFactory;
import org.hibernate.search.backend.elasticsearch.analysis.model.esnative.impl.TokenFilterDefinition;
import org.hibernate.search.backend.elasticsearch.analysis.model.esnative.impl.TokenizerDefinition;
import org.hibernate.search.backend.elasticsearch.document.model.esnative.impl.AbstractTypeMapping;
import org.hibernate.search.backend.elasticsearch.document.model.esnative.impl.AbstractTypeMappingJsonAdapterFactory;
import org.hibernate.search.backend.elasticsearch.document.model.esnative.impl.DynamicType;
import org.hibernate.search.backend.elasticsearch.document.model.esnative.impl.ElasticsearchFormatJsonAdapter;
import org.hibernate.search.backend.elasticsearch.document.model.esnative.impl.ElasticsearchRoutingTypeJsonAdapter;
import org.hibernate.search.backend.elasticsearch.document.model.esnative.impl.PropertyMapping;
import org.hibernate.search.backend.elasticsearch.document.model.esnative.impl.PropertyMappingJsonAdapterFactory;
import org.hibernate.search.backend.elasticsearch.document.model.esnative.impl.RootTypeMapping;
import org.hibernate.search.backend.elasticsearch.document.model.esnative.impl.RootTypeMappingJsonAdapterFactory;
import org.hibernate.search.backend.elasticsearch.document.model.esnative.impl.RoutingType;
import org.hibernate.search.backend.elasticsearch.index.settings.esnative.impl.Analysis;
import org.hibernate.search.backend.elasticsearch.index.settings.esnative.impl.IndexSettings;
import org.hibernate.search.mapper.pojo.bridge.mapping.annotation.declaration.MarkerBinding;
import org.hibernate.search.mapper.pojo.bridge.mapping.annotation.declaration.PropertyBinding;
import org.hibernate.search.mapper.pojo.bridge.mapping.annotation.declaration.RoutingKeyBinding;
@@ -35,6 +35,7 @@
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexingDependency;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.KeywordField;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.ScaledNumberField;
import org.jboss.jandex.DotName;
@@ -50,7 +51,8 @@ class HibernateSearchClasses {
DotName.createSimple(KeywordField.class.getName()),
DotName.createSimple(ScaledNumberField.class.getName()),
DotName.createSimple(IndexedEmbedded.class.getName()),
DotName.createSimple(AssociationInverseSide.class.getName()));
DotName.createSimple(AssociationInverseSide.class.getName()),
DotName.createSimple(IndexingDependency.class.getName()));

static final List<DotName> BINDING_DECLARATION_ANNOTATIONS_ON_PROPERTIES = Arrays.asList(
DotName.createSimple(PropertyBinding.class.getName()),
Original file line number Diff line number Diff line change
@@ -131,9 +131,9 @@ private void registerReflection(IndexView index, BuildProducer<ReflectiveClassBu
Set<DotName> reflectiveClassCollector = new HashSet<>();
Set<DotName> reflectiveTypeCollector = new HashSet<>();

if (buildTimeConfig.elasticsearch.analysisConfigurer.isPresent()) {
if (buildTimeConfig.elasticsearch.analysis.configurer.isPresent()) {
reflectiveClass.produce(
new ReflectiveClassBuildItem(true, false, buildTimeConfig.elasticsearch.analysisConfigurer.get()));
new ReflectiveClassBuildItem(true, false, buildTimeConfig.elasticsearch.analysis.configurer.get()));
}

for (DotName fieldAnnotation : FIELD_ANNOTATIONS) {
Original file line number Diff line number Diff line change
@@ -7,17 +7,16 @@

import org.hibernate.search.engine.cfg.BackendSettings;
import org.hibernate.search.engine.cfg.EngineSettings;
import org.hibernate.search.mapper.orm.cfg.HibernateOrmMapperSettings;

public class HibernateSearchConfigUtil {

public static <T> void addConfig(BiConsumer<String, Object> propertyCollector, String configPath, T value) {
propertyCollector.accept(configKey(configPath), value);
propertyCollector.accept(configPath, value);
}

public static void addConfig(BiConsumer<String, Object> propertyCollector, String configPath, Optional<?> value) {
if (value.isPresent()) {
propertyCollector.accept(configKey(configPath), value.get());
propertyCollector.accept(configPath, value.get());
}
}

@@ -80,11 +79,7 @@ public static <T> void addBackendIndexConfig(BiConsumer<String, Object> property
shouldBeAdded, getValue);
}

private static String configKey(String configPath) {
return HibernateOrmMapperSettings.PREFIX + configPath;
}

private static String backendConfigKey(String backendName, String configPath) {
return configKey(EngineSettings.BACKENDS + "." + backendName + "." + configPath);
return EngineSettings.BACKENDS + "." + backendName + "." + configPath;
}
}
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
import java.util.Map;
import java.util.Optional;

import org.hibernate.search.backend.elasticsearch.cfg.ElasticsearchVersion;
import org.hibernate.search.backend.elasticsearch.ElasticsearchVersion;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
@@ -48,10 +48,19 @@ public static class ElasticsearchBackendBuildTimeConfig {
@ConfigItem
public Optional<ElasticsearchVersion> version;

/**
* Configuration for full-text analysis.
*/
@ConfigItem
public AnalysisConfig analysis;
}

@ConfigGroup
public static class AnalysisConfig {
/**
* The class or the name of the bean used to configure full text analysis (e.g. analyzers, normalizers).
*/
@ConfigItem
public Optional<Class<?>> analysisConfigurer;
public Optional<Class<?>> configurer;
}
}
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@ private HibernateSearchIntegrationListener(HibernateSearchElasticsearchBuildTime

@Override
public void contributeBootProperties(BiConsumer<String, Object> propertyCollector) {
// Use the radical only as a workaround for https://hibernate.atlassian.net/browse/HSEARCH-3734
addConfig(propertyCollector, HibernateOrmMapperSpiSettings.Radicals.REFLECTION_STRATEGY,
HibernateOrmReflectionStrategyName.JAVA_LANG_REFLECT);

@@ -85,16 +86,16 @@ public void onMetadataInitialized(Metadata metadata, BootstrapContext bootstrapC
@Override
public void contributeRuntimeProperties(BiConsumer<String, Object> propertyCollector) {
addConfig(propertyCollector,
HibernateOrmMapperSettings.Radicals.AUTOMATIC_INDEXING_SYNCHRONIZATION_STRATEGY,
runtimeConfig.automaticIndexing.synchronizationStrategy);
HibernateOrmMapperSettings.AUTOMATIC_INDEXING_SYNCHRONIZATION_STRATEGY,
runtimeConfig.automaticIndexing.synchronization.strategy);
addConfig(propertyCollector,
HibernateOrmMapperSettings.Radicals.AUTOMATIC_INDEXING_ENABLE_DIRTY_CHECK,
HibernateOrmMapperSettings.AUTOMATIC_INDEXING_ENABLE_DIRTY_CHECK,
runtimeConfig.automaticIndexing.enableDirtyCheck);
addConfig(propertyCollector,
HibernateOrmMapperSettings.Radicals.QUERY_LOADING_CACHE_LOOKUP_STRATEGY,
runtimeConfig.queryLoading.cacheLookupStrategy);
HibernateOrmMapperSettings.QUERY_LOADING_CACHE_LOOKUP_STRATEGY,
runtimeConfig.queryLoading.cacheLookup.strategy);
addConfig(propertyCollector,
HibernateOrmMapperSettings.Radicals.QUERY_LOADING_FETCH_SIZE,
HibernateOrmMapperSettings.QUERY_LOADING_FETCH_SIZE,
runtimeConfig.queryLoading.fetchSize);

contributeBackendRuntimeProperties(propertyCollector, DEFAULT_BACKEND, runtimeConfig.defaultBackend);
@@ -112,7 +113,7 @@ private void contributeBackendBuildTimeProperties(BiConsumer<String, Object> pro
elasticsearchBackendConfig.version);
addBackendConfig(propertyCollector, backendName,
ElasticsearchBackendSettings.ANALYSIS_CONFIGURER,
elasticsearchBackendConfig.analysisConfigurer,
elasticsearchBackendConfig.analysis.configurer,
Optional::isPresent, c -> c.get().getName());
}

Loading

0 comments on commit 89083cd

Please sign in to comment.