如何根据 NHibernate 搜索中的一些属性禁用某些实体?

发布于 2024-09-09 03:39:12 字数 197 浏览 1 评论 0原文

我对 NHibernate.Search 还很陌生,所以如果这是一个愚蠢的问题,请耐心等待:)

比如说,我已经索引了一些 BlogPost 类型的实体,它有一个名为 IsDeleted 的属性。如果 IsDeleted 设置为 true,我不希望我的查询显示此特定博客文章。

这可能吗?如果是的话——如何? :P

提前致谢 - 华普

Im still pretty new to NHibernate.Search so please bear with me if this is stupid question :)

Say, I have indexed some entities of type BlogPost, which has a property called IsDeleted. If IsDeleted is set to true, I don't want my queries to show this particular blogpost.

Is this possible? And if it is - How? :P

Thanks in advance
- cwap

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

庆幸我还是我 2024-09-16 03:39:12
// Using NHibernate.Linq:
var result = Session.Linq<BlogPost>().Where(post => !post.IsDeleted).ToList();

// Using HQL:
var hql = "from BlogPost bp where bp.IsDeleted == false";
var result = Session.CreateQuery(hql).List<BlogPost>();

// Using Criteria API:    
var result = s.CreateCriteria(typeof(BlogPost))
              .Add(Restrictions.Eq("IsDeleted", false));
              .List<BlogPost>();
// Using NHibernate.Linq:
var result = Session.Linq<BlogPost>().Where(post => !post.IsDeleted).ToList();

// Using HQL:
var hql = "from BlogPost bp where bp.IsDeleted == false";
var result = Session.CreateQuery(hql).List<BlogPost>();

// Using Criteria API:    
var result = s.CreateCriteria(typeof(BlogPost))
              .Add(Restrictions.Eq("IsDeleted", false));
              .List<BlogPost>();
不奢求什么 2024-09-16 03:39:12

我自己找到了解决方案。我将 [Field(Index.Tokenized, Store = Store.Yes)] 属性添加到 IsDeleted 属性,并将此子句添加到任何入站查询:

string q = "(" + userQuery + ") AND IsDeleted:False";

我知道这很简单:)

Found the solution myself. I added the [Field(Index.Tokenized, Store = Store.Yes)]-attribute to the IsDeleted property, and added this clause to any query inbound:

string q = "(" + userQuery + ") AND IsDeleted:False";

I knew it was something simple :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文