|
NHibernateIntegration
Explains SolrNet-NHibernate integration
NHibernate integrationA NHibernate-SolrNet module is included in SolrNet, with these features:
This is intended to be used on entities that are similarly mapped on both NHibernate and SolrNet. SetupConfigure SolrNet and NHibernate as usual. Then apply SolrNet's integration to NHibernate's configuration like this: NHibernate.Cfg.Configuration cfg = SetupNHibernate(); var cfgHelper = new NHibernate.SolrNet.CfgHelper(); cfgHelper.Configure(cfg, true); // true -> autocommit Solr after every operation (not really recommended) If you're not using the default built-in container, you have to tell CfgHelper to use it, e.g.: IWindsorContainer container = new WindsorContainer(); ... var cfgHelper = new NHibernate.SolrNet.CfgHelper(container); ... UsageWhenever a NHibernate entity that is also mapped in SolrNet is created, updated, or deleted, it will be automatically updated on Solr. NHibernate transactions are honored: entities are updated on Solr only when the NHibernate transaction is committed. This synchronization goes only in the direction NHibernate -> SolrNet, not the other way around, i.e. operations issued directly through ISolrOperations will not be reflected on NHibernate. In order to issue Solr queries through NHibernate, the ISession needs to be wrapped. Sample: ISessionFactory sessionFactory = ...
using (var session = cfgHelper.OpenSession(sessionFactory)) {
ICollection<Entity> entities = session.CreateSolrQuery("this is a full-text query").SetMaxResults(10).List<Entity>();
}
|