The same problem which i also got
NHibernate + SqlServer full text search
and i didn't got any solution so i went for interceptor concept where
1)I created detached criteria for main table and joined the full text table
2)Also created a custom interceptor for nhibernate which will replace full text table name with (select [key] as foreignkey,[rank] as rank FROM CONTAINSTABLE(full_text,full_text_col , 'Foo*'))
Code
Generated query
SELECT c.id,
c.name,
ft.id,
ft.rank
FROM candidates c
INNER JOIN full_text ft ON ft.id = c.fulltext_id
ORDER BY rank
Query after interception
SELECT c.id,
c.name,
ft.id,
ft.rank
FROM candidates c
INNER JOIN (
SELECT [KEY] AS id ,[rank] AS rank
FROM CONTAINSTABLE(full_text, full_text_col, 'Foo*')
) AS ft ON ft.id = c.fulltext_id
ORDER BY rank
****DetachedCriteria ****
DetachedCriteria candidateCriteria = DetachedCriteria.For<Candidate>();
DetachedCriteria fullTextCriteria = candidateCriteria.CreateCriteria("FullText");
Interceptor code
public interface CustomInterceptor : IInterceptor, EmptyInterceptor
{
private string fulltextString;
public string FulltextString
{
get { return fulltextString; }
set { fulltextString = value; }
}
SqlString IInterceptor.OnPrepareStatement(SqlString sql)
{
string query = sql.ToString();
if (query.Contains("full_text"))
{
sql = sql.Replace("full_text", "(select [key] as foreignkey,[rank] as Rank FROM CONTAINSTABLE(full_text, full_text_col, '"+FulltextString+"')) AS ft'");
}
return sql;
}
}
Entity
candidtes table
id int
name string
fulltext_id
full_text table contains full text index
id int
full_text_col text
rank int //always null
Relation
Candidate - FullText (1-1)
OpenSession
CustomInterceptor custonInterceptor=new CustomInterceptor();
custonInterceptor.FulltextString="YourString";
sessionFactory.OpenSession(custonInterceptor);