Hibernate + MSSQL +全文搜索通过包含 [英] Hibernate + MSSQL + Fulltext Search via Contains

查看:90
本文介绍了Hibernate + MSSQL +全文搜索通过包含的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是在HQL中使用MSSQL Fulltext功能。对于什么情况,我写了一个特定的SQLFunction,将我的fulltext函数映射到contains函数。然而,问题在于,在HQL中(看起来)我不得不明确使用返回类型,MSSQL Contains函数不使用或接受。



这是MSSQL中的工作原理:

 从内容c中选择不同的ID,其中CONTAINS(c.content,'p')

这是我在HQL中使用它的想法:

 从Content c中选择id where fulltext(c.content,'p')

这不起作用,因为HQL需要返回类型。例如,这将在HQL中解析:

 从内容c中选择id fulltext(c.content,'p')= true 

它会以SQL的形式生成:



<$ p

从内容c中选择不同的ID,其中CONTAINS(c.content,'p')= 1

在MS SQL中不起作用。



我的想法很到位,但在这种设置中似乎不可能:


  1. 使hibernate解析函数没有返回值(Hibernate在我使用的版本中不支持这个功能)
  2. 尝试混合使用HQL和SQL(也似乎不起作用)

任何人有另一个想法或帮助?

我使用的Hibernate版本是3.2.6ga和MSSQL Server 2008。

解决方案

为我工作。



而不是生成

  CONTAINS(a,b)

它会生成

  CONTAINS(a,b)AND 1 

结合HQL Query



 全文(a,b)= true 

它将导致:

pre $ CONTAINS(a,b)AND 1 = 1

它很有用。


My goal is to use the MSSQL Fulltext Function with HQL. For what case I wrote a specific SQLFunction mapping the my "fulltext" function to the contains function.

However, the problem is that in HQL (it seems) I have to explicity use a return type, which the MSSQL Contains functions does not use or accepts.

This is how it works in MSSQL:

select distinct id from content c where CONTAINS(c.content, 'p')

This is my idea of using it in HQL:

select id from Content c  where fulltext(c.content, 'p') 

This does not work, since HQL needs a return type. For example this will parse in HQL:

select id from Content c  where fulltext(c.content, 'p') = true

And it will generate as SQL:

select distinct id from content c where CONTAINS(c.content, 'p') = 1

which will not work in MS SQL.

My ideas are so far but what does not seem possible in this setup:

  1. Make hibernate parse functions with no return value (Hibernate does not support this in my version used)
  2. Trying to mix HQL and SQL (also does not seem to work)

Anyone got another idea or help?

My Hibernate Version used is 3.2.6ga and MSSQL Server 2008.

解决方案

I found a way what works for me.

Instead of generating

CONTAINS(a,b) 

it will generate

CONTAINS(a,b) AND 1

And in conjunction with the HQL Query

fulltext(a,b) = true

It will result in:

CONTAINS(a,b) AND 1 = 1 

And it works.

这篇关于Hibernate + MSSQL +全文搜索通过包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆