In our project we want to use Hibernate Search 6 and local Lucene indices. Data is stored in two data sources with identical database schemas but not necessarily storing the same data. Therefore we want to create two seperate indices. After doing the inital setup I realized that I cannot declare multiple indices for one entity and I’m not sure if this approach is feasible at all.
My questions:
First of all: Can we do this the way we intent to do it using Hibernate Search?
How would we create two seperate indices for one entity?
The setup is actually not worth mentioning:
A basic entity
@Entity
@Indexed
public class Person{
@Id
@GeneratedValue
private int id;
@FullTextField
String s;
...
}
… and an entity manager to the corresponding data source
If that’s the case, do you have two separate entity manager factories / session factories / persistence units? Because you should. And if you do, then you can simply configure index storage differently in each entity manager factory by setting hibernate.search.backend.directory.root to a different filesystem path.
Thank you for your reply. I set individual root paths (using commented out part) and achieved basic functionality of Hibernate Search in my project. I’m now struggling to set the path via application.properties file. I tried setting it via
I’m sorry but no, I don’t know how that part of Spring (@ConfigurationProperties(prefix = ...)) works. You’ll probably have better luck asking the Spring community.
@ConfigurationProperties(prefix = "hibernatesearchpropertiesxxx")
public class HibernateSearchPropertiesXXX extends HibernateSearchProperties
and used it to set the property in the EntityManagerFactory
Properties p = new Properties();
p.put("hibernate.search.backend.directory.root", hibernateSearchPropertiesXXX.getIndexRoot());
emfb.setJpaProperties(p);