views:

20

answers:

2

Hi all..

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

A: 
// 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>();
Rafael Belliard
Sorry, not really the answer I was looking for. I might have worded my question poorly though. I'm using the IFullTextQuery from NHibernate to use a Lucene query. I only want the query to return objects where IsDeleted == false, though.
cwap
A: 

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 :)

cwap