Using several database setups with Lucene.Net

牧云@^-^@ 提交于 2019-12-25 09:35:36

问题


Hi I am developing a search function for an web application with Lucene.Net and NHibernate.Search. The application is used by a lots of companies but is runned as a single service, using different databases for different companies. Therefore I would need an index directory for each database rather than one directory for the entire application. Is there a way of achieve this in Lucene.Net?

I have also considering storing the indexes for each company in there respecitive database but havent found any satisfying compontents for this. I have read about Compass and JdbcDirectory for Java but I need something for C# or NHibernate. Does anyone know if there is a port of JdbcDirectory or something simular for C#?


回答1:


Hmm, it looks like you can't change anything at the session factory level using normal nhibernate.search. You may need separate instances of a configuration, or maybe try something along the lines of Fluent NHibernate Search to ease the pain.

Piecing it together from the project's wiki it appears you could do something like this to spin up separate session factories pointing to different databases / index directories:

Fluently.Configure()
    .Database(SQLiteConfiguration.Standard.InMemory())
    .Search(s => s.DefaultAnalyzer().Standard()
                             .DirectoryProvider().FSDirectory()
                             .IndexBase("~/Index")
                             .IndexingStrategy().Event()
                             .MappingClass<LibrarySearchMapping>())
    .BuildConfiguration()
    .BuildSessionFactory();

The "IndexBase" property and the connection are the parts you'll need to define per customer. Once you get the session factories set up you could resolve them using whatever strategy you use currently.

Hope it helps



来源:https://stackoverflow.com/questions/5604336/using-several-database-setups-with-lucene-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!