mysql的搜索效率_MySQL / PHP搜索效率

没有办法使LIKE’%pattern%’查询有效.一旦获得大量数据,使用这些通配符查询的速度比使用全文索引解决方案慢几百或几千倍.

以下是如何使其工作:

>首先确保您的表使用MyISAM存储引擎. MySQL FULLTEXT索引仅支持MyISAM表. (编辑11/1/2012:MySQL 5.6为InnoDB表引入了一个FULLTEXT索引类型.)

ALTER TABLE Entries ENGINE=MyISAM;

>创建全文索引.

CREATE FULLTEXT INDEX searchindex ON Entries(title, tags, entry);

>搜索它!

$search = mysql_real_escape_string($search);

$titles = mysql_query("SELECT title FROM Entries

WHERE MATCH(title, tags, entry) AGAINST('$search')");

while($row = mysql_fetch_assoc($titles)) {

$result[] = $row['title'];

}

请注意,您在MATCH子句中命名的列必须与您在全文索引定义中声明的列的顺序相同.否则它将无法工作.

I’ve tried using full-text index search, but I could never get it to work… I’m just wondering if this could be made any more efficient.

这就像是在说:“我无法弄清楚如何使用这种电锯,所以我决定用小折刀砍下这棵红木树.我怎么能像电锯那样做这个工作呢?”

关于您搜索匹配超过50%的行的单词的评论.

MySQL手册说this:

Users who need to bypass the 50% limitation can use the boolean search mode; see 07002.

The 50% threshold for natural language

searches is determined by the

particular weighting scheme chosen. To

disable it, look for the following

line in storage/myisam/ftdefs.h:

#define GWS_IN_USE GWS_PROB

Change that line to this:

#define GWS_IN_USE GWS_FREQ

Then recompile MySQL. There is no need

to rebuild the indexes in this case.

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值