栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

以任何方式在InnoDB上实现类似全文的搜索

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

以任何方式在InnoDB上实现类似全文的搜索

使用myisam全文表来索引回innodb表,例如:

使用innodb构建系统:

create table users (...) engine=innodb;create table forums (...) engine=innodb;create table threads(forum_id smallint unsigned not null,thread_id int unsigned not null default 0,user_id int unsigned not null,subject varchar(255) not null, -- gonna want to search this... !!created_date datetime not null,next_reply_id int unsigned not null default 0,view_count int unsigned not null default 0,primary key (forum_id, thread_id) -- composite clustered PK index)engine=innodb;

现在是全文搜索表,我们将使用它来索引回innodb表。您可以使用触发器或每晚进行批更新等来维护此表中的行。

create table threads_ft(forum_id smallint unsigned not null,thread_id int unsigned not null default 0,subject varchar(255) not null,fulltext (subject), -- fulltext index on subjectprimary key (forum_id, thread_id) -- composite non-clustered index )engine=myisam;

最后,您从php /应用程序调用的搜索存储过程:

drop procedure if exists ft_search_threads;delimiter #create procedure ft_search_threads(in p_search varchar(255))beginselect t.*, f.title as forum_title, u.username, match(tft.subject) against (p_search in boolean mode) as rankfrom threads_ft tftinner join threads t on tft.forum_id = t.forum_id and tft.thread_id = t.thread_idinner join forums f on t.forum_id = f.forum_idinner join users u on t.user_id = u.user_idwhere match(tft.subject) against (p_search in boolean mode) order by  rank desclimit 100;end;call ft_search_threads('+innodb +clustered +index');

希望这可以帮助 :)



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/416486.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号