I'm not sure I completely follow you. I looked at the NH source and
only found one example of freetext search. I didn't find anything
related to the contains function. In a unit test, they register a
function similar to: RegisterFunction("freetext", new
SQLFunctionTemplate(null, "freetext($1,$2)")); and then use
freetext(...) in their hql. I tried that and it didn't change the
behavior I'm seeing.
I went back to my code and simplified the expression as much as
possible. I found that checking a related object value is what is
breaking things.
This works (even without specifying the custom function in the
dialect):
return Session.CreateQuery("from MyObject p where p.IsDeleted = false
and CONTAINS(p.Name, :query)")
.SetFirstResult((page - 1) * itemsPerPage)
.SetMaxResults(itemsPerPage)
.SetParameter("query", query)
.Future<MyObject>();
This does not:
return Session.CreateQuery("from MyObject p where p.IsDeleted = false
and CONTAINS(p.Name, :query) and p.Category = :category")
.SetFirstResult((page - 1) * itemsPerPage)
.SetMaxResults(itemsPerPage)
.SetParameter("query", query)
.SetParameter("category", category)
.Future<MyObject>();
Jim
On Apr 12, 5:33 pm, Fabio Maulo <[email protected]> wrote:
> This post represent my feeling when I saw the
> problemhttp://fabiomaulo.blogspot.com/2009/07/art-to-invent-mssqls-artists.html
>
> 2010/4/12 Fabio Maulo <[email protected]>
>
>
>
>
>
> > We should have an example in our tests.
> > Neither CONTAINS nor FREETEXT does return a boolean and we have implemented
> > something else to support it.
>
> > 2010/4/12 Jim Geurts <[email protected]>
>
> > Hi all,
>
> >> I have a custom function, that I'm adding to the Sql2008 dialect, that
> >> allows me to do some fulltext searching across my objects:
>
> >> public class FreeTextDialect:MsSql2008Dialect
> >> {
> >> public FreeTextDialect()
> >> {
> >> RegisterFunction("contains", new
> >> SQLFunctionTemplate(NHibernateUtil.Boolean, "CONTAINS(?1,?2)"));
> >> }
> >> }
>
> >> When I use that function as part of hql, the results are not populated
> >> even though the query brings back objects. NHProf shows that the
> >> correct sql query is being generated and there are results from that
> >> query. Example usage is:
>
> >> return Session.CreateQuery("from MyObject p where p.IsDeleted = false
> >> and contains(p.Name, :query)")
> >> .SetFirstResult((page - 1) * itemsPerPage)
> >> .SetMaxResults(itemsPerPage)
> >> .SetParameter("query", query)
> >> .List<MyObject>();
>
> >> However, if I do not use the contains function, then things work as
> >> expected:
>
> >> return Session.CreateQuery("from MyObject p where p.IsDeleted = false
> >> and p.Name like :query")
> >> .SetFirstResult((page - 1) * itemsPerPage)
> >> .SetMaxResults(itemsPerPage)
> >> .SetParameter("query", "%" + query + "%")
> >> .List<MyObject>();
>
> >> Is my syntax incorrect for using the contains function? How can I
> >> help track down why the list is not being populated? This is using NH
> >> 3.0 Alpha 1.
>
> >> Thanks for your help,
>
> >> Jim
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "nhusers" group.
> >> To post to this group, send email to [email protected].
> >> To unsubscribe from this group, send email to
> >> [email protected]<nhusers%[email protected]
> >> >
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/nhusers?hl=en.
>
> > --
> > Fabio Maulo
>
> --
> Fabio Maulo
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.