Issue
I am developing a Spring boot application which is using spring data JPA as a persistence layer. I would like to enable a full text search with hibernate search, but because of some constraints i would like to persist the Lucene index into the database (instead of a file).
I have went through the documentation but was unable to find an example of persisting the index into a database. Also from reading it i understood that this is possible but i don't know where to start.
How should the configuration look like?
Solution
That's definitely not possible out of the box.
However, if you're willing to implement a solution yourself, you can plug it into Hibernate Search.
I've never done it, but I can offer some pointers.
You will need:
- A custom implementation of
org.apache.lucene.store.Directory
: this is the adapter between Lucene and your storage solution (in your case, the database). See this answer; that's about a very old version of Lucene, but at least it's a starting point. - A custom implementation of
org.hibernate.search.store.DirectoryProvider
: this is the component that configures and creates theDirectory
on startup. - Some configuration to tell Hibernate Search to use your
DirectoryProvider
. See this section of the documentation
This should also be possible in Hibernate Search 6, though the directory provider interface is different: org.hibernate.search.backend.lucene.lowlevel.directory.spi.DirectoryProvider
.
Answered By - yrodiere