开发者

SolrNet + NHibernate integration

开发者 https://www.devze.com 2023-02-19 01:33 出处:网络
I currently use NHibernate.Search in my app which works fine, however i now need to move to Solr because I need to load-balance my application.

I currently use NHibernate.Search in my app which works fine, however i now need to move to Solr because I need to load-balance my application.

I have the basics setup and working but the results arn't coming out as expected...here is what i have done so far:

1) Running java sol开发者_如何转开发r service in a command prompt. (i can access http://localhost:8983/solr/admin/) 2) Initialised Solr with my Nhibernate Cfg as described on the SolrNet wiki 3) I have added some Attributes to one of my entities (Id, Title, Description) 4) My schema.xml has been modified to match my indexed fields (id, title, description) 5) I have added a couple of entities to the index (i can see them in the admin console) 6) I am using the following code to return some search results (as per wiki)

NHibernate.SolrNet.CfgHelper cfgHelper = new CfgHelper();

ICollection<T> entities;

ISessionFactory sessionFactory = Session.SessionFactory;
using (var session = cfgHelper.OpenSession(sessionFactory)) {
   entities = session.CreateSolrQuery(term).SetMaxResults(10).List<T>();
}
return entities.ToList();

When i run this it finds the correct results, however it does not hydrate the full entity, only the fields that have been indexed...have i missed something here...did NHibernate.Search make this magically happen for me?

Paul


Currently, the NHibernate.SolrNet integration doesn't fetch entities from the database when querying Solr. You can either fork SolrNet and implement this (it's a matter of fetching from database by id after querying Solr), or you can keep separate entities for SolrNet and NHibernate (and removing the NHibernate.SolrNet integration from your project), which may be more work but should be significantly more flexible.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号