-->
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.  [ 4 posts ] 
Author Message
 Post subject: MySQL FullText How to get MATCH AGAINST working. HELP PLEASE
PostPosted: Wed Jan 17, 2007 1:30 pm 
Beginner
Beginner

Joined: Thu Aug 04, 2005 5:06 am
Posts: 31
Location: Bedford, UK
Hibernate version: 3.1.3

I want to use this MySQL SQL statement passing in the search string:

select product_id, categoryid, offerid, productid, productname, productdesc from product where status = 'L' and match(productname) against('+ ":searchStr" ' in boolean mode)


If I leave the + sign out of the statement Hibernate works but I need the + to give me the exact results I require.

I've tried a Named Query, and then createSQLQuery and tried to build the statement I want but I either get "invalid token" (for match/against) or "cannot find named parameter" ... gotta be the + sign creating this problem!

How can I do this please?

Here's what I have tried (unsuccessfully):
...................................................................
<sql-query name="com.xxx.xxxx.models.productSearchB">
<return class="com.xxx.xxxxx.models.Product"/>
<![CDATA[
select product_id, categoryid, offerid, productid, productname, productdesc
from product
where status = 'L'
and match(productname) against('+ :searchStr ' in boolean mode)
]]>
</sql-query>
...................................................................
public List getProductList(String search, int pageno)
throws HibernateException
{

String queryString;
List products;

queryString = "select * from com.xxx.xxxx.models.Product "
+ "where status = 'L' "
+ "and match(productname) against('+ :searchStr ' in boolean mode) ";

products = session.createSQLQuery(queryString)
.setString("searchStr", search)
.setFirstResult((pageno-1)*30)
.setMaxResults(30)
.list();

return products;

}


Last edited by mark.dathorne on Fri Jan 19, 2007 7:41 am, edited 4 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 18, 2007 6:08 am 
Beginner
Beginner

Joined: Thu Aug 04, 2005 5:06 am
Posts: 31
Location: Bedford, UK
Historically searching in the MySQL forums I found this link suggesting "Add your own SQLFunction to a custom subclass of MySQLDialect".
This was back in mid-2005 ... so is this the only solution currently?

http://forums.mysql.com/read.php?39,411 ... #msg-41195

Any suggestions appreciated.

(As yet, I haven't tried this.)

Cheers,

Mark D


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 19, 2007 7:28 am 
Beginner
Beginner

Joined: Thu Aug 04, 2005 5:06 am
Posts: 31
Location: Bedford, UK
BUMP!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 22, 2007 7:30 am 
Beginner
Beginner

Joined: Thu Aug 04, 2005 5:06 am
Posts: 31
Location: Bedford, UK
Right, I finally got it working.

1) Extended MySQLDialect to register new function match_against

2) Created MatchAgainstFunction class (extends SQLFunction) with render to return MATCH AGAINST syntax
e.g. MATCH(fieldname) AGAINST (\'+ \" :searchStr \"\' IN BOOLEAN MODE)

3) Used extended MySQLDialect class (in hibernate.cfg.xml) instead.


Loads of viewers, No suggestions. but we got there.


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