-->
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.  [ 7 posts ] 
Author Message
 Post subject: MySQL FULLTEXT and Hibernate?
PostPosted: Tue Oct 28, 2003 3:01 pm 
Newbie

Joined: Tue Oct 28, 2003 2:57 pm
Posts: 3
Hi all:

Is there any support for MySQL "FULLTEXT" queries in Hibernate? Searching this forum I see this question was asked back in September, but there were no answers, so perhaps the answer is "no"?....

If that's the case - how do people handle querying large-text databases in Hibernate? Or is this not done?


Thanks

- bill


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 3:20 pm 
Regular
Regular

Joined: Tue Sep 16, 2003 11:35 am
Posts: 93
Location: San Francisco, CA
I think this is the type of performance bottleneck that people usually hand code in JDBC.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 6:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It SHOULD be that the HQL parser will just pass through the MySQL full text search syntax. So try it.

But recently there was a report that it does not, in fact, let you do this. let me know.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 7:28 pm 
Newbie

Joined: Tue Oct 28, 2003 2:57 pm
Posts: 3
gavin wrote:
It SHOULD be that the HQL parser will just pass through the MySQL full text search syntax. So try it.

But recently there was a report that it does not, in fact, let you do this. let me know.


Well, I may be doing something wrong, but it doesn't seem to be working for me. Here's what I did:

Code:
Query q = session.createQuery("FROM items WHERE MATCH (title) AGAINST (:query)");
q.setParameter("query", searchField.getText(), Hibernate.STRING);


This produces:
net.sf.hibernate.QueryException: Incorrect query syntax [FROM items WHERE MATCH (title) AGAINST (:query)]

So, passing the MySQL FULLTEXT query through doesnt seem to work.

I also downloaded the latest 2.1b4, and tried using createSQLQuery, ie:

Code:
Query q = session.createSQLQuery("SELECT {items.*} FROM items WHERE MATCH (title) AGAINST (:query)","items",Item.class);
q.setParameter("query", searchField.getText(), Hibernate.STRING);


This produces:

net.sf.hibernate.QueryException: Named parameter does not appear in Query: query [SELECT {items.*} FROM items WHERE MATCH (title) AGAINST (:query)]

Is this a parsing bug? I'm not sure about the rules re Hibernate parsing out named parameters - for example, this works fine:

Code:
Query q = session.createSQLQuery("SELECT {items.*} FROM items WHERE title LIKE :query","items",Item.class);
q.setParameter("query", searchField.getText(), Hibernate.STRING);


While this does not: (note the addition of the MySQL '%' wildcard to the ':query' parameter:

Code:
Query q = session.createSQLQuery("SELECT {items.*} FROM items WHERE title LIKE :query%","items",Item.class);
q.setParameter("query", searchField.getText(), Hibernate.STRING);


Above produces:

java.lang.IllegalArgumentException: Parameter query does not exist as a named parameter in [SELECT {items.*} FROM items WHERE title LIKE :query%]


So, there you go. It seems not to be working, but it could just be my relative newbiness.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 7:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
EH??? This is completely broken HQL!

But this:

Code:
FROM Item item WHERE MATCH (item.title) AGAINST (:query)


might be what you are looking for.



And also a broken SQLQuery, I think. Try:

Code:
session.createSQLQuery("SELECT {item.*} FROM ITEMS {item} WHERE MATCH ({item}.TITLE) AGAINST (:query)","item",Item.class);



Quote:
While this does not: (note the addition of the MySQL '%' wildcard to the ':query' parameter:


Of course not! Append the % to the parameter value, not the name of the parameter!.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 10:00 pm 
Newbie

Joined: Tue Oct 28, 2003 2:57 pm
Posts: 3
gavin wrote:
EH??? This is completely broken HQL!

[snip]

And also a broken SQLQuery, I think. Try:


Code:
session.createSQLQuery("SELECT {item.*} FROM ITEMS {item} WHERE MATCH ({item}.TITLE) AGAINST (:query)","item",Item.class);



Quote:
While this does not: (note the addition of the MySQL '%' wildcard to the ':query' parameter:

Of course not! Append the % to the parameter value, not the name of the parameter!.



Well, thanks for the replies... I'll try these changes and see what happens. I'll not post another question re this......


- bill


Top
 Profile  
 
 Post subject: Full text queries and native SQL
PostPosted: Tue Jan 13, 2004 7:53 am 
Newbie

Joined: Fri Sep 19, 2003 7:41 am
Posts: 4
Using createSQLQuery() for creating native full text queries makes it less attractive to use Hibernate, since we need to write the dialects for each used datase (in our case, Oracle, MySQL and PostgreSQL). Why not use the plain old JDBC instead, if we loose the database-independency anyway?

It should be possible to write a simple full text query with HQL. Hibernate would then compile the HQL expression into native SQL dialect of the used database. The Hibernate would return an error message for unsupported full text query operators (if the underlying database would not support the used operator (if the HQL cannot be successfully compiled into current SQL dialect)). Most databases support basic operators (and, or, not). These could be the initially supported HQL full text search operators.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.