-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Using NHibernate with SQL Server Full Text Search (FTS)
PostPosted: Mon May 26, 2008 3:16 pm 
Newbie

Joined: Mon May 26, 2008 3:08 pm
Posts: 2
Does anyone have any familiarity with using Microsoft SQL Server 2005's Full Text search with NHibernate? Specifically, I want to be able to have my search results returned as the C# objects.

Right now I am solving the problem using CreateSQLQuery. Ideally I would solve this using HQL. The problem is further compounded my the fact that the class that I want to return is a subclass. This means particularly nasty queries of the form:

Code:
select {subclass.*} from subclass {subclass} join superclass as subclass_1_ on subclass_1_.guid = subclass.guid where (contains(content,:query)


As you can see I have had to hard code "subclass_1_" into the query. If you have any idea how to do this better, your help would be much appreciated.

Then I was trying to get it to work with HQL:
Code:
   public class SQLServerDialectWithFTS : MsSql2005Dialect
   {
      public SQLServerDialectWithFTS()
         : base()
      {
         
         RegisterFunction("CONTAINS", new StandardSQLFunction("CONTAINS", NHibernateUtil.Boolean));
         RegisterFunction("FREETEXT", new StandardSQLFunction("FREETEXT", NHibernateUtil.Boolean));
      }
   }



and used the following HQL:
Code:
FROM Subclass sn WHERE CONTAINS(sn.Content,'asdf')


but this throws an exception:
Quote:
[ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index]
System.Collections.ArrayList.get_Item(Int32 index) +7541816
NHibernate.Hql.Classic.WhereParser.CloseExpression(QueryTranslator q, String lcToken) +368
NHibernate.Hql.Classic.WhereParser.Token(String token, QueryTranslator q) +758
NHibernate.Hql.Classic.WhereParser.End(QueryTranslator q) +102
NHibernate.Hql.Classic.ClauseParser.EndChild(QueryTranslator q) +34
NHibernate.Hql.Classic.ClauseParser.End(QueryTranslator q) +50
NHibernate.Hql.Classic.PreprocessingParser.End(QueryTranslator q) +44
NHibernate.Hql.Classic.ParserHelper.Parse(IParser p, String text, String seperators, QueryTranslator q) +232
NHibernate.Hql.Classic.QueryTranslator.Compile() +95

[QueryException: Incorrect query syntax [FROM DataAccessManager.Core.Domain.Subclass sn WHERE CONTAINS(sn.Content,'asdf')]]
NHibernate.Hql.Classic.QueryTranslator.Compile() +224
NHibernate.Hql.Classic.QueryTranslator.Compile(IDictionary replacements, Boolean scalar) +54
NHibernate.Impl.SessionFactoryImpl.GetQuery(String queryString, Boolean shallow, IDictionary enabledFilters) +135
NHibernate.Impl.SessionImpl.GetQueries(String query, Boolean scalar) +34
NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters, IList results) +132
NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters) +69
NHibernate.Impl.QueryImpl.List() +151


Any help would be appreciated.

Using NHibernate 1.2.1


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 28, 2008 11:09 pm 
Newbie

Joined: Mon May 26, 2008 3:08 pm
Posts: 2
The problem seems to be in specifying the return type as "NHibernateUtil.Boolean"

The parser is expecting CONTAINS to be a function with return type boolean.
If I change
Code:
FROM Subclass sn WHERE CONTAINS(sn.Content,'asdf')
to be:

Code:
FROM Subclass sn WHERE CONTAINS(sn.Content,'asdf') = 'true'
then the parser does not throw the above mentioned exception. Unfortunately this is no longer valid SQL, so SQL server complains


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 11, 2009 12:44 am 
Regular
Regular

Joined: Tue Dec 25, 2007 3:41 pm
Posts: 57
Location: Argentina
Fixed in r4123, will be available on NH 2.1

_________________
Dario Quintana


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.