Hello,
i use HibernateSearch 3.1.1 GA with Spring 3.0 for the development of an webapplication.
HibernateSearch is configured through the application context within Springs LocalsessionFactoryBean (setting hibernate.search.default.indexBase and registering the FullTextIndexEventListener to the specific post-* events etc.).
This works just fine as long as things stay static.
In addition to the standard setup we use something similar to Spring's AbstractRoutingDataSource (
http://blog.springsource.com/2007/01/23 ... e-routing/).
The user can change the Datasource within the application. The Index should be changed at the same time. A similar Question already arose in
viewtopic.php?f=9&t=984619 i also checked some other topics on this forum about dynamic setting of the indexBase directory, but these were not 100% comparable (setting index.Base to the value of a JVM-Option value for example). My Problem seems to be that the location indexBase has to point to can change on virtually every new request.
What i did try is to extend the FSDirectoryProvider and override the initialize() method. Problem is that this is only called once when the whole configuration is set up. However i would require it to be called every time the currently active Datasource changes. Is there a way to re-initialize all the already existing FSDirectoryProviders? Maybe re-initialize the whole SearchFactory with the already existing Configurations/Mapped Classes etc. but with a dynamic change in the FSDirecotryPoviders?
I also tried overriding the getDirectory() method. As the javadoc already states this must be threadsafe. Thus this works for searching for elements (as getDirectory is called from the same thread there) but will not work for modifying events that write to the index (as these are fired from different threads and my threadlocal held active Datasource is thus not accessible :().
Is there any other solution / different approach to handle this kind of dynamic Datasource scenario?
Maybe use one index and add a prefix to the documents within it and filter for this prefix again when searching?
Thanks in advance for any answers.