Just thought I should conclude this discussion before it´s way too old.
First as mentioned by Ricardo the LingExtensionMethodAttribute is a nice
attribute, tho not applicable in this scenario, it´s still really good to
know about.
When it´s comes to the initial question the conclusion will be not possible
in a good way with the current version of NHibernate. You can try a few
workarounds, the custom MySQL function as suggested may be possible but I
didn´t got mine to work. Another solution is to intercept the final query
before sent to the database and do the minor replacements that was needed.
The problem with both these is that they are quite limited, soon you wanna
order by relevance etc. and you have to do everything all over again. So my
final solution and recommendation to others is to just do a separate pure
sql call to get the ids you need and then pass them to NHibernate and you
will get the best of two worlds in a simple way. It´s more or less the same
way you would use a "real searchengine" like lucene together with
NHibernate which seems to be the more common solution for fulltext search.
Thanks to everybody who participated in the discussion.
Den torsdagen den 5:e juni 2014 kl. 09:41:49 UTC+2 skrev Joel Hervén:
>
> I´ve tried to write a LINQ extension that executes the MySQL function
> MATCH(...,...) AGAINST(...). But I have not been able to translate it into
> appropriate HQL because of the "two functions" syntax.
>
> To have something to look at I wrote this method
>
> public override HqlTreeNode BuildHql(MethodInfo method, Expression
> targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder
> treeBuilder, IHqlExpressionVisitor visitor)
> {
> var e1 = treeBuilder.MethodCall("MATCH", new[]
> {
> visitor.Visit(arguments[0]).AsExpression(),
> });
>
> var e2 = treeBuilder.MethodCall("AGAINST", new[]
> {
> visitor.Visit(arguments[1]).AsExpression(),
> });
>
> return
> treeBuilder.Equality(e1, e2);
> }
>
> The Equality method is obviously not the correct thing here but it will
> generate the SQL "MATCH(....)+AGAINST(....)" which is very close to correct
> except the + sign that shouldn´t be there. I have looked at the
> HqlTreeBuilder many times but I can´t find a working method to just add up
> the methods like needed here.
>
> So next thing was to look at the HqlTreeBuilder and try to extend with an
> alternative
>
> public class HqlDoubleMethod : HqlBooleanExpression
> {
> public HqlDoubleMethod(IASTFactory factory, HqlExpression lhs,
> HqlExpression rhs)
> : base(0, "", factory, lhs, rhs)
> {
> }
> }
>
> Calling this method instead of Equality results in a
> RewriteEmptyStreamException rule b
>
>
> Is it possible to implement this kind of function without modifying the
> Nhibernate-core?
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.