forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the index layout strategy to the Search runtime config
- Loading branch information
1 parent
8e6e43d
commit affaf3e
Showing
16 changed files
with
407 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...va/io/quarkus/it/hibernate/search/orm/elasticsearch/layout/CustomIndexLayoutStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.quarkus.it.hibernate.search.orm.elasticsearch.layout; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Named; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.hibernate.search.backend.elasticsearch.index.layout.IndexLayoutStrategy; | ||
|
||
@ApplicationScoped | ||
@Named("CustomIndexLayoutStrategy") | ||
public class CustomIndexLayoutStrategy implements IndexLayoutStrategy { | ||
|
||
@ConfigProperty(name = "test.index-layout.prefix", defaultValue = "-") | ||
String prefix; | ||
|
||
@Override | ||
public String createInitialElasticsearchIndexName(String hibernateSearchIndexName) { | ||
return "%s%s-000001".formatted(prefix, hibernateSearchIndexName); | ||
} | ||
|
||
@Override | ||
public String createWriteAlias(String hibernateSearchIndexName) { | ||
return "%s%s-write".formatted(prefix, hibernateSearchIndexName); | ||
} | ||
|
||
@Override | ||
public String createReadAlias(String hibernateSearchIndexName) { | ||
return "%s%s-read".formatted(prefix, hibernateSearchIndexName); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...arkus/it/hibernate/search/orm/elasticsearch/layout/HibernateSearchLayoutTestResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.quarkus.it.hibernate.search.orm.elasticsearch.layout; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.hibernate.SessionFactory; | ||
import org.hibernate.search.backend.elasticsearch.index.ElasticsearchIndexManager; | ||
import org.hibernate.search.engine.environment.bean.BeanReference; | ||
import org.hibernate.search.mapper.orm.mapping.SearchMapping; | ||
|
||
@Path("/test/layout-strategy") | ||
public class HibernateSearchLayoutTestResource { | ||
|
||
@Inject | ||
SessionFactory sessionFactory; | ||
|
||
@Inject | ||
SearchMapping searchMapping; | ||
|
||
@GET | ||
@Path("/property") | ||
@Transactional | ||
public String layoutStrategy() { | ||
return ((BeanReference<?>) sessionFactory.getProperties().get("hibernate.search.backend.layout.strategy")).toString(); | ||
} | ||
|
||
@GET | ||
@Path("/index-name") | ||
@Transactional | ||
public String name() { | ||
var descriptor = searchMapping.indexedEntity(LayoutEntity.class) | ||
.indexManager() | ||
.unwrap(ElasticsearchIndexManager.class) | ||
.descriptor(); | ||
|
||
return "%s - %s - %s".formatted(descriptor.hibernateSearchName(), descriptor.readName(), descriptor.writeName()); | ||
} | ||
} |
Oops, something went wrong.