Skip to content

Commit 72b16f3

Browse files
committed
HSEARCH-5160 Copy Lucene backend for Lucene 10
- no changes except the pom
1 parent 9adfd34 commit 72b16f3

File tree

512 files changed

+39798
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

512 files changed

+39798
-0
lines changed

backend/lucene10/pom.xml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?xml version="1.0"?>
2+
<project
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.hibernate.search</groupId>
8+
<artifactId>hibernate-search-parent-public</artifactId>
9+
<version>8.0.0-SNAPSHOT</version>
10+
<relativePath>../../build/parents/public</relativePath>
11+
</parent>
12+
<artifactId>hibernate-search-backend-lucene10</artifactId>
13+
14+
<name>Hibernate Search Backend - Lucene 10</name>
15+
<description>Hibernate Search Backend relying on embedded instances of Lucene (v10)</description>
16+
17+
<properties>
18+
<!-- This is a publicly distributed module that should be published: -->
19+
<deploy.skip>false</deploy.skip>
20+
<java.module.name>org.hibernate.search.backend.lucene</java.module.name>
21+
22+
<version.org.apache.lucene>10.0.0</version.org.apache.lucene>
23+
<java-version.main.release>21</java-version.main.release>
24+
</properties>
25+
26+
<dependencyManagement>
27+
<dependencies>
28+
<!-- Lucene backend -->
29+
<dependency>
30+
<groupId>org.apache.lucene</groupId>
31+
<artifactId>lucene-core</artifactId>
32+
<version>${version.org.apache.lucene}</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.apache.lucene</groupId>
36+
<artifactId>lucene-analysis-common</artifactId>
37+
<version>${version.org.apache.lucene}</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.apache.lucene</groupId>
41+
<artifactId>lucene-queryparser</artifactId>
42+
<version>${version.org.apache.lucene}</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.apache.lucene</groupId>
46+
<artifactId>lucene-join</artifactId>
47+
<version>${version.org.apache.lucene}</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.apache.lucene</groupId>
51+
<artifactId>lucene-facet</artifactId>
52+
<version>${version.org.apache.lucene}</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.apache.lucene</groupId>
56+
<artifactId>lucene-highlighter</artifactId>
57+
<version>${version.org.apache.lucene}</version>
58+
</dependency>
59+
<dependency>
60+
<groupId>com.carrotsearch</groupId>
61+
<artifactId>hppc</artifactId>
62+
<version>${version.com.carrotsearch.hppc}</version>
63+
</dependency>
64+
</dependencies>
65+
</dependencyManagement>
66+
67+
<dependencies>
68+
<dependency>
69+
<groupId>org.hibernate.search</groupId>
70+
<artifactId>hibernate-search-engine</artifactId>
71+
</dependency>
72+
73+
<dependency>
74+
<groupId>org.apache.lucene</groupId>
75+
<artifactId>lucene-core</artifactId>
76+
</dependency>
77+
<dependency>
78+
<groupId>org.apache.lucene</groupId>
79+
<artifactId>lucene-analysis-common</artifactId>
80+
</dependency>
81+
<dependency>
82+
<groupId>org.apache.lucene</groupId>
83+
<artifactId>lucene-queryparser</artifactId>
84+
</dependency>
85+
<dependency>
86+
<groupId>org.apache.lucene</groupId>
87+
<artifactId>lucene-join</artifactId>
88+
</dependency>
89+
<dependency>
90+
<groupId>org.apache.lucene</groupId>
91+
<artifactId>lucene-facet</artifactId>
92+
</dependency>
93+
<dependency>
94+
<groupId>com.carrotsearch</groupId>
95+
<artifactId>hppc</artifactId>
96+
</dependency>
97+
98+
<dependency>
99+
<groupId>org.jboss.logging</groupId>
100+
<artifactId>jboss-logging</artifactId>
101+
</dependency>
102+
<dependency>
103+
<groupId>org.jboss.logging</groupId>
104+
<artifactId>jboss-logging-annotations</artifactId>
105+
</dependency>
106+
<dependency>
107+
<groupId>org.apache.lucene</groupId>
108+
<artifactId>lucene-highlighter</artifactId>
109+
</dependency>
110+
111+
<!-- Test -->
112+
<dependency>
113+
<groupId>org.hibernate.search</groupId>
114+
<artifactId>hibernate-search-util-internal-test-common</artifactId>
115+
<scope>test</scope>
116+
</dependency>
117+
</dependencies>
118+
</project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.search.backend.lucene;
6+
7+
import java.util.Optional;
8+
9+
import org.hibernate.search.engine.backend.Backend;
10+
import org.hibernate.search.engine.backend.metamodel.IndexValueFieldTypeDescriptor;
11+
12+
import org.apache.lucene.analysis.Analyzer;
13+
14+
public interface LuceneBackend extends Backend {
15+
16+
/**
17+
* @param name An analyzer name, e.g. a name returned by {@link IndexValueFieldTypeDescriptor#analyzerName()}
18+
* or {@link IndexValueFieldTypeDescriptor#searchAnalyzerName()}.
19+
* @return The corresponding analyzer, or {@link Optional#empty()} if it doesn't exist.
20+
*/
21+
Optional<? extends Analyzer> analyzer(String name);
22+
23+
/**
24+
* @param name A normalizer name, e.g. a name returned by {@link IndexValueFieldTypeDescriptor#normalizerName()}.
25+
* @return The corresponding normalizer, or {@link Optional#empty()} if it doesn't exist.
26+
*/
27+
Optional<? extends Analyzer> normalizer(String name);
28+
29+
}
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.search.backend.lucene;
6+
7+
import java.util.Optional;
8+
9+
import org.hibernate.search.backend.lucene.logging.impl.LuceneMiscLog;
10+
import org.hibernate.search.backend.lucene.schema.management.LuceneIndexSchemaExport;
11+
import org.hibernate.search.backend.lucene.scope.LuceneIndexScope;
12+
import org.hibernate.search.backend.lucene.search.aggregation.dsl.LuceneSearchAggregationFactory;
13+
import org.hibernate.search.backend.lucene.search.predicate.dsl.LuceneSearchPredicateFactory;
14+
import org.hibernate.search.backend.lucene.search.projection.dsl.LuceneSearchProjectionFactory;
15+
import org.hibernate.search.backend.lucene.search.query.LuceneSearchQuery;
16+
import org.hibernate.search.backend.lucene.search.query.dsl.LuceneSearchQuerySelectStep;
17+
import org.hibernate.search.backend.lucene.search.query.dsl.impl.LuceneSearchQuerySelectStepImpl;
18+
import org.hibernate.search.backend.lucene.search.query.impl.LuceneSearchQueryIndexScope;
19+
import org.hibernate.search.backend.lucene.search.sort.dsl.LuceneSearchSortFactory;
20+
import org.hibernate.search.backend.lucene.types.dsl.LuceneIndexFieldTypeFactory;
21+
import org.hibernate.search.engine.backend.scope.IndexScopeExtension;
22+
import org.hibernate.search.engine.backend.scope.spi.IndexScope;
23+
import org.hibernate.search.engine.backend.session.spi.BackendSessionContext;
24+
import org.hibernate.search.engine.backend.types.dsl.IndexFieldTypeFactory;
25+
import org.hibernate.search.engine.backend.types.dsl.IndexFieldTypeFactoryExtension;
26+
import org.hibernate.search.engine.common.schema.management.SchemaExport;
27+
import org.hibernate.search.engine.common.schema.management.SchemaExportExtension;
28+
import org.hibernate.search.engine.search.aggregation.dsl.SearchAggregationFactory;
29+
import org.hibernate.search.engine.search.aggregation.dsl.SearchAggregationFactoryExtension;
30+
import org.hibernate.search.engine.search.loading.spi.SearchLoadingContext;
31+
import org.hibernate.search.engine.search.loading.spi.SearchLoadingContextBuilder;
32+
import org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory;
33+
import org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactoryExtension;
34+
import org.hibernate.search.engine.search.projection.dsl.SearchProjectionFactory;
35+
import org.hibernate.search.engine.search.projection.dsl.SearchProjectionFactoryExtension;
36+
import org.hibernate.search.engine.search.query.SearchQuery;
37+
import org.hibernate.search.engine.search.query.SearchQueryExtension;
38+
import org.hibernate.search.engine.search.query.dsl.SearchQueryDslExtension;
39+
import org.hibernate.search.engine.search.query.dsl.SearchQuerySelectStep;
40+
import org.hibernate.search.engine.search.query.spi.SearchQueryIndexScope;
41+
import org.hibernate.search.engine.search.sort.dsl.SearchSortFactory;
42+
import org.hibernate.search.engine.search.sort.dsl.SearchSortFactoryExtension;
43+
44+
/**
45+
* An extension for the Lucene backend, giving access to Lucene-specific features.
46+
* <p>
47+
* <strong>WARNING:</strong> while this type is API, because instances should be manipulated by users,
48+
* all of its methods are considered SPIs and therefore should never be called directly by users.
49+
* In short, users are only expected to get instances of this type from an API and pass it to another API.
50+
*
51+
* @param <H> The type of query hits.
52+
* Users should not have to care about this, as the parameter will automatically take the appropriate value when calling
53+
* {@code .extension( LuceneExtension.get() )}.
54+
* @param <R> The entity reference type for projections.
55+
* Users should not have to care about this, as the parameter will automatically take the appropriate value when calling
56+
* {@code .extension( LuceneExtension.get() )}.
57+
* @param <E> entity type for projections.
58+
* Users should not have to care about this, as the parameter will automatically take the appropriate value when calling
59+
* {@code .extension( LuceneExtension.get() )}.
60+
* @param <LOS> The type of the initial step of the loading options definition DSL.
61+
* Users should not have to care about this, as the parameter will automatically take the appropriate value when calling
62+
* {@code .extension( LuceneExtension.get() )}.
63+
*
64+
* @see #get()
65+
*/
66+
public final class LuceneExtension<H, R, E, LOS>
67+
implements SearchQueryDslExtension<LuceneSearchQuerySelectStep<R, E, LOS>, R, E, LOS>,
68+
SearchQueryExtension<LuceneSearchQuery<H>, H>,
69+
SearchPredicateFactoryExtension<LuceneSearchPredicateFactory>,
70+
SearchSortFactoryExtension<LuceneSearchSortFactory>,
71+
SearchProjectionFactoryExtension<LuceneSearchProjectionFactory<R, E>, R, E>,
72+
SearchAggregationFactoryExtension<LuceneSearchAggregationFactory>,
73+
IndexFieldTypeFactoryExtension<LuceneIndexFieldTypeFactory>,
74+
IndexScopeExtension<LuceneIndexScope>,
75+
SchemaExportExtension<LuceneIndexSchemaExport> {
76+
77+
private static final LuceneExtension<Object, Object, Object, Object> INSTANCE = new LuceneExtension<>();
78+
79+
/**
80+
* Get the extension with generic parameters automatically set as appropriate for the context in which it's used.
81+
*
82+
* @param <H> The type of query hits.
83+
* Users should not have to care about this, as the parameter will automatically take the appropriate value when calling
84+
* {@code .extension( LuceneExtension.get() }.
85+
* @param <R> The entity reference type for projections.
86+
* Users should not have to care about this, as the parameter will automatically take the appropriate value when calling
87+
* {@code .extension( LuceneExtension.get() }.
88+
* @param <E> entity type for projections.
89+
* Users should not have to care about this, as the parameter will automatically take the appropriate value when calling
90+
* {@code .extension( LuceneExtension.get() }.
91+
* @param <LOS> The type of the initial step of the loading options definition DSL.
92+
* Users should not have to care about this, as the parameter will automatically take the appropriate value when calling
93+
* {@code .extension( LuceneExtension.get() }.
94+
* @return The extension.
95+
*/
96+
@SuppressWarnings("unchecked") // The instance works for any H, R and E
97+
public static <H, R, E, LOS> LuceneExtension<H, R, E, LOS> get() {
98+
return (LuceneExtension<H, R, E, LOS>) INSTANCE;
99+
}
100+
101+
private LuceneExtension() {
102+
// Private constructor, use get() instead.
103+
}
104+
105+
/**
106+
* {@inheritDoc}
107+
*/
108+
@Override
109+
public Optional<LuceneSearchQuerySelectStep<R, E, LOS>> extendOptional(
110+
SearchQuerySelectStep<?, R, E, LOS, ?, ?> original,
111+
SearchQueryIndexScope<?> scope,
112+
BackendSessionContext sessionContext,
113+
SearchLoadingContextBuilder<E, LOS> loadingContextBuilder) {
114+
if ( scope instanceof LuceneSearchQueryIndexScope ) {
115+
return Optional.of( new LuceneSearchQuerySelectStepImpl<>(
116+
(LuceneSearchQueryIndexScope<?>) scope, sessionContext, loadingContextBuilder
117+
) );
118+
}
119+
else {
120+
return Optional.empty();
121+
}
122+
}
123+
124+
/**
125+
* {@inheritDoc}
126+
*/
127+
@Override
128+
public Optional<LuceneSearchQuery<H>> extendOptional(SearchQuery<H> original,
129+
SearchLoadingContext<?> loadingContext) {
130+
if ( original instanceof LuceneSearchQuery ) {
131+
return Optional.of( (LuceneSearchQuery<H>) original );
132+
}
133+
else {
134+
return Optional.empty();
135+
}
136+
}
137+
138+
/**
139+
* {@inheritDoc}
140+
*/
141+
@Override
142+
public Optional<LuceneSearchPredicateFactory> extendOptional(SearchPredicateFactory original) {
143+
if ( original instanceof LuceneSearchPredicateFactory ) {
144+
return Optional.of( (LuceneSearchPredicateFactory) original );
145+
}
146+
else {
147+
return Optional.empty();
148+
}
149+
}
150+
151+
/**
152+
* {@inheritDoc}
153+
*/
154+
@Override
155+
public Optional<LuceneSearchSortFactory> extendOptional(
156+
SearchSortFactory original) {
157+
if ( original instanceof LuceneSearchSortFactory ) {
158+
return Optional.of( (LuceneSearchSortFactory) original );
159+
}
160+
else {
161+
return Optional.empty();
162+
}
163+
}
164+
165+
/**
166+
* {@inheritDoc}
167+
*/
168+
@Override
169+
public Optional<LuceneSearchProjectionFactory<R, E>> extendOptional(SearchProjectionFactory<R, E> original) {
170+
if ( original instanceof LuceneSearchProjectionFactory ) {
171+
return Optional.of( (LuceneSearchProjectionFactory<R, E>) original );
172+
}
173+
else {
174+
return Optional.empty();
175+
}
176+
}
177+
178+
/**
179+
* {@inheritDoc}
180+
*/
181+
@Override
182+
public Optional<LuceneSearchAggregationFactory> extendOptional(SearchAggregationFactory original) {
183+
if ( original instanceof LuceneSearchAggregationFactory ) {
184+
return Optional.of( (LuceneSearchAggregationFactory) original );
185+
}
186+
else {
187+
return Optional.empty();
188+
}
189+
}
190+
191+
/**
192+
* {@inheritDoc}
193+
*/
194+
@Override
195+
public LuceneIndexFieldTypeFactory extendOrFail(IndexFieldTypeFactory original) {
196+
if ( original instanceof LuceneIndexFieldTypeFactory ) {
197+
return (LuceneIndexFieldTypeFactory) original;
198+
}
199+
else {
200+
throw LuceneMiscLog.INSTANCE.luceneExtensionOnUnknownType( original );
201+
}
202+
}
203+
204+
/**
205+
* {@inheritDoc}
206+
*/
207+
@Override
208+
public LuceneIndexScope extendOrFail(IndexScope original) {
209+
if ( original instanceof LuceneIndexScope ) {
210+
return (LuceneIndexScope) original;
211+
}
212+
else {
213+
throw LuceneMiscLog.INSTANCE.luceneExtensionOnUnknownType( original );
214+
}
215+
}
216+
217+
/**
218+
* {@inheritDoc}
219+
*/
220+
@Override
221+
public LuceneIndexSchemaExport extendOrFail(SchemaExport original) {
222+
if ( original instanceof LuceneIndexSchemaExport ) {
223+
return (LuceneIndexSchemaExport) original;
224+
}
225+
else {
226+
throw LuceneMiscLog.INSTANCE.luceneExtensionOnUnknownType( original );
227+
}
228+
}
229+
}

0 commit comments

Comments
 (0)