Hibernate version: svn head (r10305)
Assume the following sessionfactory using the Spring Framework:
Code:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="annotatedClasses">
<list>
<!-- list of annotation mapped classes-->
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.lucene.default.directory_provider">org.hibernate.lucene.store.RAMDirectoryProvider</prop>
</props>
</property>
<property name="eventListeners">
<map>
<entry key="post-commit-update" value-ref="luceneListener"/>
<entry key="post-commit-insert" value-ref="luceneListener"/>
<entry key="post-commit-delete" value-ref="luceneListener"/>
</map>
</property>
</bean>
<bean id="luceneListener" class="org.hibernate.lucene.event.LuceneEventListener"/>
When performing CRUD operations on the mapped classes, the logs show that they get indexed correctly. How can I access the lucene index directory (RamDirectory in this case) in order to run searches? In the current API I can't see any way to do this.
My idea is to add a methode "public Directory getDirectory(Class)" to LuceneEventListener. The searcher code might then use
Code:
LuceneEventListener listener = .... // get e.g. from Spring's applicationContext
Directory dir = listener.getDirectory(Car.class);
Searcher searcher = new IndexSearcher(dir);
QueryParser qp = new QueryParser("Manufacturer", new StandardAnalyzer());
Hits hits = searcher.search(qp.parse("mercedes"));
Do you have a different way to get the Directory? If desired, I'll create a patch for my approach.
In general, I do not completly understand the DirectoryProviderFactory. Since I'm fairly new to Lucene, the following might be complete pribble-prabble, so be warned ;-)
Assume two classes sharing the same index name:
Code:
@Indexed(index="common")
class a { ...}
@Indexed(index="common")
class b {...}
If RAM based directory is used, these to classes will get different two different Lucene RAMDirectories. So a search in the one will not find entries of the other and vice versa. The same applies for FS based: two FSDirectory instances access the same path concurrently causing index file being overwritten.
Regards,
Stefan