<tfoot id='zZd4d'></tfoot>
        <bdo id='zZd4d'></bdo><ul id='zZd4d'></ul>

      <small id='zZd4d'></small><noframes id='zZd4d'>

        <i id='zZd4d'><tr id='zZd4d'><dt id='zZd4d'><q id='zZd4d'><span id='zZd4d'><b id='zZd4d'><form id='zZd4d'><ins id='zZd4d'></ins><ul id='zZd4d'></ul><sub id='zZd4d'></sub></form><legend id='zZd4d'></legend><bdo id='zZd4d'><pre id='zZd4d'><center id='zZd4d'></center></pre></bdo></b><th id='zZd4d'></th></span></q></dt></tr></i><div id='zZd4d'><tfoot id='zZd4d'></tfoot><dl id='zZd4d'><fieldset id='zZd4d'></fieldset></dl></div>
      1. <legend id='zZd4d'><style id='zZd4d'><dir id='zZd4d'><q id='zZd4d'></q></dir></style></legend>

        任何在 InnoDB 上实现类全文搜索的方法

        Any way to achieve fulltext-like search on InnoDB(任何在 InnoDB 上实现类全文搜索的方法)

          <small id='zlQkA'></small><noframes id='zlQkA'>

            <tbody id='zlQkA'></tbody>

            • <bdo id='zlQkA'></bdo><ul id='zlQkA'></ul>
              • <legend id='zlQkA'><style id='zlQkA'><dir id='zlQkA'><q id='zlQkA'></q></dir></style></legend>

                <i id='zlQkA'><tr id='zlQkA'><dt id='zlQkA'><q id='zlQkA'><span id='zlQkA'><b id='zlQkA'><form id='zlQkA'><ins id='zlQkA'></ins><ul id='zlQkA'></ul><sub id='zlQkA'></sub></form><legend id='zlQkA'></legend><bdo id='zlQkA'><pre id='zlQkA'><center id='zlQkA'></center></pre></bdo></b><th id='zlQkA'></th></span></q></dt></tr></i><div id='zlQkA'><tfoot id='zlQkA'></tfoot><dl id='zlQkA'><fieldset id='zlQkA'></fieldset></dl></div>

                • <tfoot id='zlQkA'></tfoot>
                • 本文介绍了任何在 InnoDB 上实现类全文搜索的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个非常简单的查询:

                  I have a very simple query:

                  SELECT ... WHERE row LIKE '%some%' OR row LIKE '%search%' OR  row LIKE '%string%'
                  

                  搜索一些搜索字符串,但是如你所见,它单独搜索每个字符串,这对性能也不利.

                  to search for some search string, but as you can see, it searches for each string individually and it's also not good for performance.

                  有没有办法在 InnoDB 表上使用 LIKE 重新创建类似全文的搜索.当然,我知道我可以使用 Sphinx 之类的东西来实现这一点,但我正在寻找纯 MySQL 解决方案.

                  Is there a way to recreate a fulltext-like search using LIKE on an InnoDB table. Of course, I know I can use something like Sphinx to achieve this but I'm looking for a pure MySQL solution.

                  推荐答案

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

                  use a myisam fulltext table to index back into your innodb tables for example:

                  使用 innodb 构建您的系统:

                  Build your system using 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 表.您可以使用触发器或每晚批量更新等方式维护该表中的行.

                  Now the fulltext search table which we will use just to index back into our innodb tables. You can maintain rows in this table either by using a trigger or nightly batch updates etc.

                  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 subject
                  primary key (forum_id, thread_id) -- composite non-clustered index 
                  )
                  engine=myisam;
                  

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

                  Finally the search stored procedure which you call from your php/application:

                  drop procedure if exists ft_search_threads;
                  delimiter #
                  
                  create procedure ft_search_threads
                  (
                  in p_search varchar(255)
                  )
                  begin
                  
                  select
                   t.*,
                   f.title as forum_title,
                   u.username,
                   match(tft.subject) against (p_search in boolean mode) as rank
                  from
                   threads_ft tft
                  inner join threads t on tft.forum_id = t.forum_id and tft.thread_id = t.thread_id
                  inner join forums f on t.forum_id = f.forum_id
                  inner join users u on t.user_id = u.user_id
                  where
                   match(tft.subject) against (p_search in boolean mode) 
                  order by 
                   rank desc
                  limit 100;
                  
                  end;
                  
                  call ft_search_threads('+innodb +clustered +index');
                  

                  希望这有帮助:)

                  这篇关于任何在 InnoDB 上实现类全文搜索的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Bogus foreign key constraint fail(虚假外键约束失败)
                  how to get last insert id after insert query in codeigniter active record(如何在codeigniter活动记录中插入查询后获取最后一个插入ID)
                  Force InnoDB to recheck foreign keys on a table/tables?(强制 InnoDB 重新检查表/表上的外键?)
                  How to auto generate migrations with Sequelize CLI from Sequelize models?(如何使用 Sequelize CLI 从 Sequelize 模型自动生成迁移?)
                  Clear MySQL query cache without restarting server(无需重启服务器即可清除 MySQL 查询缓存)
                  ALTER TABLE to add a composite primary key(ALTER TABLE 添加复合主键)

                    <bdo id='An07o'></bdo><ul id='An07o'></ul>
                      <tbody id='An07o'></tbody>

                        <tfoot id='An07o'></tfoot>

                        <small id='An07o'></small><noframes id='An07o'>

                        1. <i id='An07o'><tr id='An07o'><dt id='An07o'><q id='An07o'><span id='An07o'><b id='An07o'><form id='An07o'><ins id='An07o'></ins><ul id='An07o'></ul><sub id='An07o'></sub></form><legend id='An07o'></legend><bdo id='An07o'><pre id='An07o'><center id='An07o'></center></pre></bdo></b><th id='An07o'></th></span></q></dt></tr></i><div id='An07o'><tfoot id='An07o'></tfoot><dl id='An07o'><fieldset id='An07o'></fieldset></dl></div>

                          <legend id='An07o'><style id='An07o'><dir id='An07o'><q id='An07o'></q></dir></style></legend>