Michal Ciechan
Michal Ciechan

Reputation: 13898

NHibernate Full Text Search

What is the best way trying to get a text search function using nhibernate? I have read about NHibernate.Search, but cannot find the library anywhere.

I downloaded the latest NHibernate source code(2.1.2) and compiled it, but i still cannot find NHibernate.Search.

Does anyone have any suggestions? Or any other methods to do text search?

EDIT: Using MySQL database, incase it makes any difference.

Upvotes: 2

Views: 987

Answers (2)

hassan
hassan

Reputation: 21

You can use Expression.Sql but i think it's good idea using mysql stored procedure

Your MySql Stored Procedure :

CREATE PROCEDURE `GetProductsByText`(IN `queryText` VARCHAR(100) CHARSET utf8)
SELECT *
FROM Products
WHERE MATCH(Title, Description) AGAINST (queryText)

Your nhibernate mapping xml file :

<sql-query name="GetProductsByText">
<return class="Product"/>
   call `GetProductsByText`( :queryText )
</sql-query>

your c# nhibernate query:

public IList<Product> FindByText (string text)
{   
    var session = SessionFactory.GetCurrentSession ();
    IQuery query = session.GetNamedQuery ("GetProductsByText");

    return query.SetString ("queryText", text).List<Product> ();        
}

Upvotes: 1

Paco
Paco

Reputation: 8381

NHiberante.Search a separate dll to make Nhiberante and Lucene work together. You have to download and reference it if you want to use it. You might like to read some introduction about Lucene to understand how Nhiberante.Search works.

One of the places where you can get the dll is hornget

If you want to the MySql specific full text search options, there won't be any help from Nhibernate for you to use them.

Upvotes: 2

Related Questions