SolrNet + NHibernate集成
我目前在我的应用程序中使用 NHibernate.Search ,效果很好,但是我现在需要迁移到 Solr,因为我需要负载平衡我的应用程序。
我已经完成了基础设置并正在工作,但结果没有按预期输出...这是我到目前为止所做的:
1)在命令提示符中运行 java solr 服务。 (我可以访问 http://localhost:8983/solr/admin/) 2) 使用我的 Nhibernate Cfg 初始化 Solr,如 SolrNet wiki 上所述 3)我已向我的实体之一添加了一些属性(ID、标题、描述) 4)我的 schema.xml 已被修改以匹配我的索引字段(id、标题、描述) 5)我在索引中添加了几个实体(我可以在管理控制台中看到它们) 6)我使用以下代码返回一些搜索结果(根据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();
当我运行它时,它会找到正确的结果,但是它不会水合完整的实体,只有已索引的字段......我错过了这里有一些东西... NHibernate.Search 是否让这件事神奇地发生在我身上?
保罗
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 solr 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前,NHibernate.SolrNet 集成在查询 Solr 时不会从数据库中获取实体。您可以分叉 SolrNet 并实现它(这是在查询 Solr 后通过 id 从数据库获取的问题),或者您可以为 SolrNet 和 NHibernate 保留单独的实体(并从项目中删除 NHibernate.SolrNet 集成),这可能需要更多工作,但应该更加灵活。
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.