【问题标题】:Best efficient way to make a fulltext search in MySQL在 MySQL 中进行全文搜索的最佳有效方法
【发布时间】:2009-08-24 20:59:20
【问题描述】:

我有 3 个表,我想查询一个搜索词文本框。我的查询目前看起来像这样:

SELECT Artist.* FROM Artist, Band, Instrument WHERE MATCH (Artist.name) AGAINST ('mysearchterm') OR MATCH (Band.name) AGAINST ('mysearchterm') OR MATCH (Instrument.name, Instrument.description) AGAINST ('mysearchterm');

此查询的执行时间过长。有什么办法可以改善这一点吗?我做错了吗?

谢谢

【问题讨论】:

    标签: mysql full-text-search


    【解决方案1】:

    我会转向全文搜索引擎,而不是尝试对此进行优化。

    http://www.sphinxsearch.com/about.html

    【讨论】:

    • +1 用于使用外部引擎,无论是 Sphinx 还是其他任何东西(Lucene?也有商业工具,顺便说一句)
    【解决方案2】:

    MYSQL 具有全文搜索支持,这将提供更好的性能。

    http://dev.mysql.com/doc/refman/5.0/en/fulltext-restrictions.html

    但是,如果您打算对应用程序施加任何重大负载,我建议您使用专为全文搜索而设计的系统。

    【讨论】:

    • 谢谢你的回答,我希望我能选择一个以上的正确答案。
    【解决方案3】:

    抱歉,后续跟进晚了,但您不是对这三个表进行笛卡尔连接吗?

    SELECT Artist.* FROM Artist, Band, Instrument WHERE MATCH (Artist.name) AGAINST ('mysearchterm') OR MATCH (Band.name) AGAINST ('mysearchterm') OR MATCH (Instrument.name, Instrument.description) AGAINST ('mysearchterm');
    

    假设您在 500,000 行中搜索包含 100 个乐队、10 种乐器和 500 位艺术家的数据库。

    我希望看到类似假设您有一个数据库,其中艺术家属于一个乐队并演奏一种乐器:

    SELECT Artist.* FROM Artist, Band, Instrument WHERE Artist.band_id = Band.id and Artist.instrument_id = Instrument.id and (MATCH (Artist.name) AGAINST ('mysearchterm') OR MATCH (Band.name) AGAINST ('mysearchterm') OR MATCH (Instrument.name, Instrument.description) AGAINST ('mysearchterm'));
    

    【讨论】:

      【解决方案4】:

      你能做如下的事情,这不是全文搜索吗?

      SELECT Artist.* FROM Artist, Band, Instrument WHERE Artist.name LIKE '%mysearchterm%'...
      

      或者(我的偏好):

      SELECT Artist.* FROM Artist, Band, Instrument WHERE Artist.name REGEXP '<regexp here>'...
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-30
        • 1970-01-01
        • 2011-11-04
        • 2021-12-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多