NH Prof New FeatureNHibernate Search Integration
Well, I was demoing how easy it is to add new features to NH Prof in a user group in JAOO today, and tomorrow I am doing my OR/M += 2 talk. Part of the things that I want to show is NHibernate Search, but the demo doesn’t really work unless I can point to NH Prof and show what is going on there.
I now consider output results to the console to be so 2005.
Here is the code that I am using for this post:
using (var s = factory.OpenSession()) { var posts = NHibernate.Search.Search.CreateFullTextSession(s) .CreateFullTextQuery<Post>("Title:NHibernate User.Name:ayende") .List<Post>(); NHibernate.Search.Search.CreateFullTextSession(s) .CreateFullTextQuery<Post>("Title:NHibernate User.Name:ayende") .SetMaxResults(10) .List<Post>(); foreach (var post in posts) { Console.WriteLine(post.Title); } }
I had to make a small modification to NHibernate Search, to output the right information (which means that you can make this work with r1044 or up), but here is the result:
Notice that you can get not only the actual Lucene query text, but you also get the query duration and the number of returned results. The next query is NHibernate Search actually hitting the database to load the managed entities, after hitting the Lucene index to perform the actual search.
We can also generate some warnings on top of Lucene! As you can see here, we detect unbounded queries:
If you do specify a maximum number of entities to return, we are going to reflect that in the query directly:
We can also tell you if your Lucene index is out of date with respect to the database:
Sweet, and is currently warming up in the oven, build 488 should have it.
More posts in "NH Prof New Feature" series:
- (09 Dec 2010) Alert on bad ‘like’ query
- (10 Dec 2009) Filter static files
- (16 Nov 2009) Exporting Reports
- (08 Oct 2009) NHibernate Search Integration
- (19 Aug 2009) Multiple Session Factory Support
- (07 Aug 2009) Diffing Sessions
- (06 Aug 2009) Capturing DDL
- (05 Aug 2009) Detect Cross Thread Session Usage
- (22 May 2009) Detecting 2nd cache collection loads
- (15 May 2009) Error Detection
- (12 May 2009) Queries by Url
- (04 Feb 2009) View Query Results
- (18 Jan 2009) Superfluous <many-to-one> update
- (18 Jan 2009) URL tracking
- (10 Jan 2009) Detecting distributed transactions (System.Transactions)
- (06 Jan 2009) The Query Cache
- (05 Jan 2009) Query Duration
- (24 Dec 2008) Unbounded result sets
- (24 Dec 2008) Row Counts
Comments
Good news.
Sorry for spamming in your blog, but where should i look for answer to this question: stackoverflow.com/.../how-to-integrate-nhiberna... ?
Looks like you got an answer
And you can use my recent demo, it shows how to do this
Yeah. Count of 'viewed' skyrocketed thanks to your blog.
Our current app uses homemade search solution. It just bakes up sql, uses sql fulltext search underneath and returns list of objects with specified columns.
Thing i'm trying to accomplish - to mitigate nhibernate session state problems (our search mechanism won't find anything until session isn't flushed),to make lazy loading possible for searched entities (still haven't found if that's possible with our current search solution elegantly without turning to database once more) and make it more reliable/maintainable.
I know this isn't a support line but have you any advice? :)
What you want is to use NH Search, it is what it is meant for.
BTW, due to transaction isolation, you aren't supposed to see stuff in the index until the transaction is committed.
Oh, and are you aware that you can purchase support?
Nice! Ayende, once again helping me to justify software purchases with added value. Thanks for the new feature.
awesome! can't wait to try it out
Damn, that's good!
Nhibernate + Lucene + NHProf = Crazy Delicious! Thanks Ayende for making this stack better and better. It makes my job so much fun!
Now how about a log4net appender? Great stuff
Thanks a lot.
I do know about purchasing support. But it's just me alone - checking out how our project could be upgraded and that would be too expensive. No one is going to drop our search mechanism yet until robust solution is found. Maybe later. :)
Comment preview