Search code examples
.netnhibernatelucene.netnhibernate-search

How to use nhibernate search? Can't get it to successfully build


I am trying to hookup nhibernate search but ran into a couple problems.

  1. I downloaded the nuget package and I am getting errors

    The type 'Lucene.Net.Search.Query' is defined in an assembly that is not referenced. You must add a reference to assembly 'Lucene.Net, Version=2.9.2.2, Culture=neutral, PublicKeyToken=null'

It seems like it does not have the right version. Is there a more up to date version that I can get? I can't seem to find one.

2 the next error I get is

 string query = "Name: Test";
                using (var nhibernateSearch = Search.CreateFullTextSession(unitOfWork.Session))
                {
                    base.unitOfWork.BeginTransaction();


                    var carSearchResults = nhibernateSearch.CreateFullTextQuery(query)
                        .SetMaxResults(5)
                        .List();

                    //var results = nhibernateSearch.CreateFullTextQuery(query).List();


                    base.unitOfWork.Commit();
                }

I get

The best overloaded method match for 'NHibernate.Search.IFullTextSession.CreateFullTextQuery(Lucene.Net.Search.Query, params System.Type[])' has some invalid arguments

3 Next error I get is

Error   13  Argument 1: cannot convert from 'string' to 'Lucene.Net.Search.Query'   

I been trying to follow this tutorial and so far it seems like alot has changed.


Solution

  • I'm unable to reproduce your first problem.

    You're calling CreateFulltextQuery(Query, params Type[]), but it sounds like you want to call CreateFulltextQuery<MyEntityType>(String) instead.

    Based on your variable name I'm guessing ...

    var carSearchResults = nhibernateSearch.CreateFullTextQuery<Car>(query)
                                           .SetMaxResults(5)
                                           .List();