mysql innodb 使用中,在MySQL中使用InnoDB进行全文搜索

I have a MySQL database (version 5.5.28) with a table like this:

products (InnoDB)

-------------------------------------------------

search_id title description

1 Levi Blue Jeans Some cool jeans

2 Gucci Handbag Great accessory

3 Prada Dress Beautiful dress

I want to do something like this in MySQL:

SELECT MATCH(title) AGAINST ('Jeans') AS score, search_id, FROM search WHERE MATCH(title) AGAINST ('Jeans' IN BOOLEAN MODE)

As far as I know you can only do that in MyISAM. Is it possible to do a similar search with InnoDB without resorting to things like:

For my application (around 1000 - 2000 records) Sphinx etc. seems like overkill. But getting every record into an array and search through it with PHP also seems too much. But maybe you disagree.

PS.

LIKE doesn't seem to work well for me. The results are usually less accurate and you cannot get a score as you can with MATCH.

解决方案

Duplicate the text column from products to a new MyISAM table.

Establish a 1-1 relationship beween the two, and, in order to ensure of the ACID'ity provided by InnoDB, make sure that you always access the MyISAM table together with products.

You may want to add triggers on products to maintain the bijection. You could also create a view so that the rework is minimal in your application when you upgrade to MySQL v5.6 (and drop this convoluted workaround).

Instead of copying the text column, you could move it altogether (delete it from products, that is). This would be more efficient, but it would also make it a bit more complicated to switch to a InnoDB-only solution when you feel like upgrading.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值