The following is one way to implement a working solution:
Just register the a new function name (e.g.
Code:
registerFunction("match_against", new MatchAgainstFunction() );
)
and provide a rendering method for the new function (e.g.
Code:
public String render(List args, SessionFactoryImplementor factory) throws QueryException {
StringBuffer buf = new StringBuffer();
buf.append("MATCH(");
for ( int i=0; i<args.size()-1; i++) {
buf.append(args.get(i));
if (i<args.size()-2) buf.append(",");
}
buf.append(")");
buf.append(" AGAINST(");
buf.append(args.get(args.size()-1));
buf.append(")");
return buf.toString();
}
)
With the above example you can use a HQL-Query like
Code:
FROM searchObject WHERE match_against(field1,field2,'searchtext') > 0
The trick is to use the fact that MATCH(...) AGAINST (..) returns a double that shows the relevance of the hit. With this, match_against() just works like any other aggregation-function and you don't need to tweak the grammar.
HTH,
greets, Stephan